Agentic tool use with Claude XML
Combine XML scaffolding with the API's tool-use feature for reliable agent loops.
The Claude API has a first-class tool-use feature — that's the right primitive for agents. XML still helps as scaffolding for the model's internal planning and for shaping observations.
How to apply the pattern
- Use real tools via the API, not XML-defined ones.
tools=[...]in the API call is stronger than asking Claude to output<tool_call>tags. - Wrap tool observations in
<observation>tags. When you re-inject tool results, give them clear boundaries. The model treats them as evidence, not instructions. - Have Claude plan in
<plan>before acting. On the first turn, ask for a numbered plan. Subsequent turns can re-plan with<updated_plan>. - Use
<final_answer>as the stop signal. Your agent loop terminates when this tag appears.
Worked example
<instructions>
You are an agent that helps users plan trips. You have tools available.
On each turn:
1. Reason in <thinking> tags about what to do next.
2. Either call a tool, or produce a <final_answer>.
3. When you call a tool, the result will appear in <observation> tags on
the next turn.
Do not include <observation> tags yourself — those come from the system.
</instructions>
<task>Find me a flight from SFO to NYC next Tuesday under $400.</task>
Tips
- Keep tool descriptions short and example-driven — Claude calls tools more reliably when their JSON schema includes an example argument.
- Bound the agent loop. Hard cap on turns prevents runaway costs.
Cite this page
Agentic tool use with Claude XML. claudexml.com. https://claudexml.com/patterns/agentic-tool-use/