Skip to content

XML Agent

⚠️ DEPRECATION WARNING

This component is deprecated and will be removed in a future version of Nappai. Please migrate to the recommended alternative components.

The XML Agent component lets you create an AI agent that can call tools using XML tags. It sends prompts to a language model and interprets the model’s XML output to execute tools and return results.

How it Works

The component uses LangChain’s create_xml_agent to build an agent that understands a simple XML-based instruction format.

  1. Prompt Template – A template tells the model how to format its output: <tool>name</tool><tool_input>…</tool_input> for tool calls and <final_answer>…</final_answer> for the final response.
  2. LLM Interaction – The chosen language model (e.g., GPT‑4) generates text that follows the XML format.
  3. XML Parsing – The agent parses the model’s output, extracts the tool name and input, calls the corresponding tool, and feeds the tool’s result back to the model as an <observation>.
  4. Iteration – This loop repeats until the model emits a <final_answer> or the maximum number of iterations is reached.
  5. Output – The final answer is returned as a message, and the fully built agent is exposed for reuse.

Inputs

  • Model – The language model that will generate the agent’s responses.
  • Tools – A list of tools that the agent can call (e.g., search, calculator).
  • Disable Streaming – If checked, the LLM will not stream responses; it will send the full answer at once.
  • Handle Parse Errors – Enables graceful handling of malformed XML from the model.
  • Input – The user’s question or prompt that the agent should answer.
  • Max Iterations – The maximum number of tool calls the agent can make before stopping.
  • Prompt – A custom prompt template that can override the default XML instructions.
  • Verbose – If enabled, the agent will log detailed debugging information.

Outputs

  • Agent – The built AgentExecutor object that can be run in other parts of the workflow.
  • Response – The final message returned by the agent, containing the answer to the user’s question.

Usage Example

  1. Add the XML Agent to your workflow.
  2. Connect a Tool (e.g., a “Search” tool) to the Tools input.
  3. Select a Model (e.g., OpenAI GPT‑4) for the Model input.
  4. Leave the Prompt as default or customize it if needed.
  5. Feed a User Question into the Input field (e.g., “What’s the weather in SF?”).
  6. Run the Agent and capture the Response output.
  7. Display the Result in a Text Output component or use it to trigger other actions.
  • Base Agent – The foundational agent component that XML Agent builds upon.
  • Tool – Individual tools that can be called by the agent.
  • LLM – Language model components that provide the AI engine.
  • Text Input – Component to capture user questions.
  • Text Output – Component to display the agent’s answer.

Tips and Best Practices

  • Keep the Max Iterations low (e.g., 5) to avoid endless loops.
  • Enable Verbose during development to see how the agent parses and calls tools.
  • Use a clear, concise Prompt to reduce parsing errors.
  • Restrict the Tools list to trusted actions to maintain security.
  • Test the agent with a variety of inputs to ensure robust XML handling.

Security Considerations

  • Only expose tools that are safe and have been vetted; the agent can execute any tool it receives.
  • Disable Streaming if you need to capture the entire response before processing.
  • Monitor the Verbose logs for unexpected tool calls or malformed XML.
  • Ensure that the LLM provider’s usage complies with your organization’s data‑handling policies.