xiaohongshu
xiaohongshu
Comprehensive guide for AI agents on proper Claude-style tool calling with correct syntax, patterns, and examples
Full skill instructions
This skill provides comprehensive guidance on proper Claude-style tool calling syntax for AI agents building systems that interact with Claude's API. Claude uses a unique XML-based tool calling format that differs from other LLM APIs.
Key Insight: Claude's tool calling uses XML-style function_calls blocks with nested invoke and parameter tags. Understanding this structure is critical for building reliable agent systems.
EDUCATIONAL - Study the patterns and examples, implement in your Claude API integration. The examples are reference implementations showing correct syntax.
Claude's tool calling format uses three layers - see examples directory for complete working examples.
| Aspect | OpenAI Function Calling | Claude Tool Use |
|---|---|---|
| Format | JSON in tool_calls array | XML-style function_calls block |
| Multiple calls | Array of tool call objects | Multiple invoke tags in same block |
| Parameters | JSON object | Individual parameter tags |
| Response | tool_call_id required | Implicit response matching |
| Syntax | Pure JSON | XML with JSON for complex parameters |
Every tool call MUST be wrapped in a function_calls block, even for single calls.
Each tool gets its own invoke tag with the tool name in the name attribute.
Each parameter gets its own tag - do NOT pass all parameters as JSON unless they are nested objects.
Use JSON format within parameter tags for:
Multiple invoke tags in the same function_calls block execute in parallel.
Use multiple separate function_calls blocks for sequential operations that depend on previous results.
See examples/tool-calling-examples.md for working code.
Multiple invoke tags within ONE function_calls block.
Complex parameters use JSON format within parameter tags.
Separate function_calls blocks when you need results from first call before making second call.
NEVER write invoke tags without the function_calls container.
Do NOT pass all parameters as single JSON blob - use individual parameter tags.
Always properly close all tags in correct order.
Don't mix calls that need sequential execution in parallel block.
When Claude calls your tools, your system must:
See examples directory for complete request-response cycles.
Always validate that tool names and parameters match your schema.
Gracefully handle cases where Claude requests non-existent tools.
Return clear error messages in tool results for debugging.
Validate parameter types match what your tools expect.
Use parallel calls when tools don't depend on each other for better performance.
Define your tools clearly in the API request with proper JSON Schema.
Format tool results consistently for Claude to parse.
Handle tool execution errors and return useful messages.
When integrating Claude tool calling:
Return results to Claude in this format:
<function_results>
<result>
<name>tool_name</name>
<output>Tool output or error message</output>
</result>
</function_results>
For errors, use <tool_use_error> tags within output.
Claude API returns stop_reason field:
"tool_use" → Execute tools and continue"end_turn" → Normal completion, no more tools needed"max_tokens" → Hit token limit"stop_sequence" → Custom stop sequence hitClaude may include <thinking> tags for internal reasoning - these are NOT tool calls. Parse and ignore them when extracting tool calls.
Claude can include explanatory text before/after tool calls. Preserve this text for user experience, but only execute the function_calls blocks.
Complete working examples are in the examples/ subdirectory:
tool-calling-examples.md - Full examples of all patterns + Claude Code-specific behaviorscommon-mistakes.md - Detailed mistake examples with fixesThese examples show the actual XML syntax that would be interpreted if included directly in this file.
When implementing Claude tool calling:
IMPORTANT: All concrete XML examples are in the examples/ subdirectory to prevent accidental tool execution when this skill file is read. Always refer to examples/ for actual syntax.
Created: 2026-01-22 Last Updated: 2026-01-22 v1.1 Changes in v1.1: Added Claude Code-specific behaviors, API integration patterns, thinking tags, stop_reason handling, conversation flow
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience