xml

An agent design that represents tool calls, intermediate results, and final answers with XML tags. XML is a text format that marks structured information with named opening and closing tags.

In plain words
What is it for?
Use it when building or studying an agent that plans actions, calls tools, and parses XML-formatted responses.
Why use it?
It gives the agent a consistent way to record its steps and separate tool inputs, observations, and answers.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/xt765/langchain-chinese-comment/xml
Clone the repo
git clone --depth 1 https://github.com/xt765/LangChain-Chinese-Comment
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 571 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00571
Opus 5 $0.00000 $0.00285
Sonnet 5 $0.00000 $0.00114
Haiku 4.5 $0.00000 $0.00057

Measured 2d ago against content hash b0852dcb4968, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

xml scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

code_comment/libs/langchain/langchain_classic/agents/xml.md · 57 lines

What it actually says

XML Agent

XMLAgent 是一种使用 XML 标签(如 <tool><tool_input>)来结构化其思考和行动过程的代理。这种格式特别适合那些对 XML 结构化数据处理较好的模型(如 Anthropic 的 Claude 系列)。

核心工作流

  1. Prompt: 指示模型使用 XML 标签来调用工具。
  2. Execution: 模型生成类似 <tool>search</tool><tool_input>weather</tool_input> 的内容。
  3. Parsing: XMLAgentOutputParser 提取标签内容并转换为 AgentAction
  4. Observation: 工具结果被包装在 <observation> 标签中反馈给模型。

核心实现 (Verbatim Snippet)

1. 计划逻辑 (plan)

XML Agent 手动拼接中间步骤的 XML 字符串,而不是依赖通用的 Scratchpad 格式化函数。

def plan(
    self,
    intermediate_steps: list[tuple[AgentAction, str]],
    callbacks: Callbacks = None,
    **kwargs: Any,
) -> AgentAction | AgentFinish:
    log = ""
    for action, observation in intermediate_steps:
        # 手动构建 XML 历史记录
        log += (
            f"<tool>{action.tool}</tool><tool_input>{action.tool_input}"
            f"</tool_input><observation>{observation}</observation>"
        )
    inputs = {
        "intermediate_steps": log,
        "tools": tools,
        "question": kwargs["input"],
        "stop": ["</tool_input>", "</final_answer>"],
    }
    response = self.llm_chain(inputs, callbacks=callbacks)
    return response[self.llm_chain.output_key]

迁移指南 (Migration)

现代 LangChain 推荐使用 create_xml_agent 工厂函数,或者直接使用原生支持 Tool Calling 的模型。

现代 XML Agent 创建

from langchain.agents import create_xml_agent
from langchain_anthropic import ChatAnthropic

model = ChatAnthropic(model="claude-3-opus-20240229")
agent = create_xml_agent(model, tools, prompt)

为什么迁移?

  1. LCEL 支持: create_xml_agent 返回的是一个 Runnable 对象,可以轻松与其他组件集成。
  2. 异步支持: 现代实现对异步 aplan 有更好的原生支持。
  3. 鲁棒性: 新的 XMLAgentOutputParser 在处理不完整的 XML 或格式微调方面更加健壮。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 57 lines · 0 tokens per session scan A b0852dcb4968

Subscribe to this mod's changes

xml is an agent published in the GitHub repository xt765/LangChain-Chinese-Comment (20 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 571 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other agents, from other repositories

observer

Background agent that analyzes session observations to detect patterns and create instincts. Uses Haiku for cost-efficiency.

sangrokjung/claude-forge · 23 tokens

mcp-server-architect

Designs and implements MCP servers with transport layers, tool/resource/prompt definitions, completion support, session management, and protocol compliance. Specializes in FastMCP 2.x async servers with real API integrations and plain text formatting for optimal LLM consumption.

utensils/mcp-nixos · 57 tokens

loop-monitor

Autonomous loop monitor — detects stalls, token runaway, and infinite loops in long-running unattended Claude sessions. Use alongside a watchdog process when running autonomous pipelines.

FlorianBruniaux/claude-code-ultimate-guide · 34 tokens

claude-code-guide

Expert on the Claude Code Ultimate Guide. Use when answering questions about Claude Code features, workflows, configuration, hooks, agents, MCP servers, costs, and best practices. Searches the guide before answering. Cites file + line sources.

FlorianBruniaux/claude-code-ultimate-guide · 52 tokens

tools

Give your Agents capabilities with built-in tools, MCP servers, and custom scripts.

MarlBurroW/hivekeep · 16 tokens

orchestrator

Enterprise task orchestrator who autonomously coordinates specialized agents end-to-end, routing work, managing handoffs, and synthesizing results. Classifies complexity, triages delegation, and sequences workflows. Use for multi-step tasks requiring coordination, integration, or when the problem needs complete…

rjmurillo/ai-agents · 63 tokens