> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# XML Agent

> XML data processing tools for AI agents.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents import read_xml, write_xml, validate_xml

agent = Agent(
    name="XMLAgent",
    tools=[read_xml, write_xml, validate_xml],
)
agent.start("Validate config.xml against our schema")
```

The user describes an XML task; the agent reads, validates, or transforms documents with XML tools.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    U[Input] --> A[Agent]
    A --> T[Tool]
    T --> O[Output]

    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

    class A agent
    class U,O tool
    class T tool
```

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Feature as XML Agent

    User->>Agent: Request
    Agent->>Feature: Process request
    Feature-->>Agent: Result
    Agent-->>User: Response
```

<Note>
  **Prerequisites**

  * Python 3.10 or higher
  * PraisonAI Agents package installed
  * PraisonAI Tools package installed
  * `lxml` package installed
</Note>

## XML Tools

Use XML Tools to read, write, and manipulate XML data with AI agents.

<Steps>
  <Step title="Install Dependencies">
    First, install the required packages:

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    pip install praisonaiagents praisonai-tools lxml
    ```
  </Step>

  <Step title="Import Components">
    Import the necessary components:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, Task, AgentTeam
    from praisonai_tools import read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml
    ```
  </Step>

  <Step title="Create Agent">
    Create an XML processing agent:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    xml_agent = Agent(
        name="XMLProcessor",
        role="XML Processing Specialist",
        goal="Process XML files efficiently and accurately.",
        backstory="Expert in XML file manipulation and validation.",
        tools=[read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml],
        reflection=False
    )
    ```
  </Step>

  <Step title="Define Task">
    Define the XML processing task:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    xml_task = Task(
        description="Parse and validate XML configuration files.",
        expected_output="Validated and processed XML data.",
        agent=xml_agent,
        name="xml_processing"
    )
    ```
  </Step>

  <Step title="Run Agent">
    Initialize and run the agent:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    agents = AgentTeam(
        agents=[xml_agent],
        tasks=[xml_task],
        process="sequential"
    )
    agents.start()
    ```
  </Step>
</Steps>

## Understanding XML Tools

<Card title="What are XML Tools?" icon="question">
  XML Tools provide XML processing capabilities for AI agents:

  * XML parsing and reading
  * File writing and validation
  * Data transformation
  * Dictionary conversion
  * Structure manipulation
</Card>

## Key Components

<CardGroup cols={2}>
  <Card title="XML Agent" icon="user-robot">
    Create specialized XML agents:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    Agent(tools=[read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml])
    ```
  </Card>

  <Card title="XML Task" icon="list-check">
    Define XML tasks:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    Task(description="xml_operation")
    ```
  </Card>

  <Card title="Process Types" icon="arrows-split-up-and-left">
    Sequential or parallel processing:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    process="sequential"
    ```
  </Card>

  <Card title="XML Options" icon="sliders">
    Customize XML parameters:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    encoding="utf-8", pretty_print=True
    ```
  </Card>
</CardGroup>

## Available Functions

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai_tools import read_xml
from praisonai_tools import write_xml
from praisonai_tools import transform_xml
from praisonai_tools import validate_xml
from praisonai_tools import xml_to_dict
from praisonai_tools import dict_to_xml
```

## Examples

### Basic XML Processing Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml

# Create XML agent
xml_agent = Agent(
    name="XMLExpert",
    role="XML Processing Specialist",
    goal="Process XML files efficiently and accurately.",
    backstory="Expert in XML file handling and validation.",
    tools=[read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml],
    reflection=False
)

# Define XML task
xml_task = Task(
    description="Parse and validate XML configurations.",
    expected_output="Processed and validated XML data.",
    agent=xml_agent,
    name="config_processing"
)

# Run agent
agents = AgentTeam(
    agents=[xml_agent],
    tasks=[xml_task],
    process="sequential"
)
agents.start()
```

### Advanced XML Processing with Multiple Agents

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml

# Create XML processing agent
processor_agent = Agent(
    name="Processor",
    role="XML Processor",
    goal="Process XML files systematically.",
    tools=[read_xml, write_xml, transform_xml],
    reflection=False
)

# Create validation agent
validator_agent = Agent(
    name="Validator",
    role="Data Validator",
    goal="Validate XML structure and content.",
    backstory="Expert in data validation and verification.",
    tools=[validate_xml, xml_to_dict, dict_to_xml],
    reflection=False
)

# Define tasks
processing_task = Task(
    description="Process and transform XML configurations.",
    agent=processor_agent,
    name="xml_processing"
)

validation_task = Task(
    description="Validate processed XML data.",
    agent=validator_agent,
    name="data_validation"
)

# Run agents
agents = AgentTeam(
    agents=[processor_agent, validator_agent],
    tasks=[processing_task, validation_task],
    process="sequential"
)
agents.start()
```

## Best Practices

<AccordionGroup>
  <Accordion title="Agent Configuration">
    Configure agents with clear XML focus:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_tools import read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml

    Agent(
        name="XMLProcessor",
        role="XML Processing Specialist",
        goal="Process XML files accurately and safely",
        tools=[read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml]
    )
    ```
  </Accordion>

  <Accordion title="Task Definition">
    Define specific XML operations:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    Task(
        description="Parse and validate XML configurations",
        expected_output="Validated data structure"
    )
    ```
  </Accordion>
</AccordionGroup>

## Common Patterns

### XML Processing Pipeline

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import read_xml, write_xml, transform_xml, validate_xml, xml_to_dict, dict_to_xml

# Processing agent
processor = Agent(
    name="Processor",
    role="XML Processor",
    tools=[read_xml, write_xml, transform_xml]
)

# Validation agent
validator = Agent(
    name="Validator",
    role="Data Validator",
    tools=[validate_xml, xml_to_dict, dict_to_xml]
)

# Define tasks
process_task = Task(
    description="Process XML files",
    agent=processor
)

validate_task = Task(
    description="Validate processed data",
    agent=validator
)

# Run workflow
agents = AgentTeam(
    agents=[processor, validator],
    tasks=[process_task, validate_task]
)
```

## Related

<CardGroup cols={2}>
  <Card title="Custom Tools" icon="wrench" href="/docs/tools/custom">
    Build your own agent tools
  </Card>

  <Card title="Tools Overview" icon="toolbox" href="/docs/tools/tools">
    Browse PraisonAI tool documentation
  </Card>
</CardGroup>
