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.
DiagramDiagram
XML Tools
Use XML Tools to read, write, and manipulate XML data with AI agents.
Install Dependencies
First, install the required packages:
bash
pip install praisonaiagents praisonai-tools lxml
Import Components
Import the necessary components:
python
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 Agent
Create an XML processing agent:
python
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
)
Define Task
Define the XML processing task:
python
xml_task = Task(
description="Parse and validate XML configuration files.",
expected_output="Validated and processed XML data.",
agent=xml_agent,
name="xml_processing"
)
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
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
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
Agent Configuration
Configure agents with clear XML focus:
python
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]
)
Task Definition
Define specific XML operations:
python
Task(
description="Parse and validate XML configurations",
expected_output="Validated data structure"
)