### Define Tool Use Examples for 'create_ticket' Source: https://www.anthropic.com/engineering/advanced-tool-use Provide concrete usage patterns for the 'create_ticket' tool. This helps Claude understand format conventions, nested structures, and optional parameter correlations, improving accuracy in complex parameter handling. ```json { "name": "create_ticket", "input_schema": { /* same schema as above */ }, "input_examples": [ { "title": "Login page returns 500 error", "priority": "critical", "labels": ["bug", "authentication", "production"], "reporter": { "id": "USR-12345", "name": "Jane Smith", "contact": { "email": "jane@acme.com", "phone": "+1-555-0123" } }, "due_date": "2024-11-06", "escalation": { "level": 2, "notify_manager": true, "sla_hours": 4 } }, { "title": "Add dark mode support", "labels": ["feature-request", "ui"], "reporter": { "id": "USR-67890", "name": "Alex Chen" } }, { "title": "Update API documentation" } ] } ``` -------------------------------- ### Tool Request with Caller Field Source: https://www.anthropic.com/engineering/advanced-tool-use This is an example of a tool request received by Claude when a tool is invoked. It includes a 'caller' field indicating the execution environment. ```json { "type": "tool_use", "id": "toolu_xyz", "name": "get_expenses", "input": {"user_id": "emp_123", "quarter": "Q3"}, "caller": { "type": "code_execution_20250825", "tool_id": "srvtoolu_abc" } } ``` -------------------------------- ### Configure Tool Search Tool with Deferred Loading Source: https://www.anthropic.com/engineering/advanced-tool-use Use `defer_loading: true` to mark tools for on-demand discovery by the Tool Search Tool. This is beneficial when you have a large number of tools and want to reduce initial context token usage. ```json { "tools": [ // Include a tool search tool (regex, BM25, or custom) {"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}, // Mark tools for on-demand discovery { "name": "github.createPullRequest", "description": "Create a pull request", "input_schema": {...}, "defer_loading": true } // ... hundreds more deferred tools with defer_loading: true ] } ``` -------------------------------- ### System Prompt for Tool Discovery Source: https://www.anthropic.com/engineering/advanced-tool-use Provides guidance to Claude on available tools. This system prompt helps Claude know what capabilities exist and encourages the use of tool search for specific functions. ```text You have access to tools for Slack messaging, Google Drive file management, Jira ticket tracking, and GitHub repository operations. Use the tool search to find specific capabilities. ``` -------------------------------- ### Good vs. Bad Tool Description for Search Source: https://www.anthropic.com/engineering/advanced-tool-use Illustrates effective tool descriptions for discoverability. Clear, descriptive names and descriptions improve the accuracy of tool search matching. ```json // Good { "name": "search_customer_orders", "description": "Search for customer orders by date range, status, or total amount. Returns order details including items, shipping, and payment info." } ``` ```json // Bad { "name": "query_db_orders", "description": "Execute order query" } ``` -------------------------------- ### Document Return Formats for Programmatic Tool Calling Source: https://www.anthropic.com/engineering/advanced-tool-use Clearly document the return formats of tools to help Claude write correct parsing logic. This is especially useful for tools with complex or list-based return structures. ```json { "name": "get_orders", "description": "Retrieve orders for a customer. Returns: List of order objects, each containing: - id (str): Order identifier - total (float): Order total in USD - status (str): One of 'pending', 'shipped', 'delivered' - items (list): Array of {sku, quantity, price} - created_at (str): ISO 8601 timestamp" } ``` -------------------------------- ### Defer Loading Entire MCP Server with Specific Tools Loaded Source: https://www.anthropic.com/engineering/advanced-tool-use For MCP servers, you can defer loading the entire server while keeping specific high-use tools loaded by setting `default_config: {"defer_loading": true}` and then overriding `defer_loading` to `false` for individual tools. ```json { "type": "mcp_toolset", "mcp_server_name": "google-drive", "default_config": {"defer_loading": true}, # defer loading the entire server "configs": { "search_files": { "defer_loading": false } # Keep most used tool loaded } } ``` -------------------------------- ### Configure Tools for Programmatic Execution Source: https://www.anthropic.com/engineering/advanced-tool-use This JSON configuration shows how to enable programmatic tool calling by adding 'code_execution' to the tool types and specifying 'allowed_callers' for individual tools. ```json { "tools": [ { "type": "code_execution_20250825", "name": "code_execution" }, { "name": "get_team_members", "description": "Get all members of a department...", "input_schema": {...}, "allowed_callers": ["code_execution_20250825"] # opt-in to programmatic tool calling }, { "name": "get_expenses", ... }, { "name": "get_budget_by_level", ... } ] } ``` -------------------------------- ### Enable Advanced Tool Use Beta Source: https://www.anthropic.com/engineering/advanced-tool-use To enable advanced tool use features, include the specified beta header and list the desired tools in the API call. Ensure your tools are correctly defined with their types and names. ```python client.beta.messages.create( betas=["advanced-tool-use-2025-11-20"], model="claude-sonnet-4-5-20250929", max_tokens=4096, tools=[ {"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}, {"type": "code_execution_20250825", "name": "code_execution"}, # Your tools with defer_loading, allowed_callers, and input_examples ] ) ``` -------------------------------- ### Orchestrate Budget Compliance Check with Python Source: https://www.anthropic.com/engineering/advanced-tool-use This Python script orchestrates fetching team members, their budgets, and expenses to identify individuals who exceeded their Q3 travel budget. It runs within the Code Execution tool, processing tool results programmatically. ```python team = await get_team_members("engineering") # Fetch budgets for each unique level levels = list(set(m["level"] for m in team)) budget_results = await asyncio.gather(*[ get_budget_by_level(level) for level in levels ]) # Create a lookup dictionary: {"junior": budget1, "senior": budget2, ...} budgets = {level: budget for level, budget in zip(levels, budget_results)} # Fetch all expenses in parallel expenses = await asyncio.gather(*[ get_expenses(m["id"], "Q3") for m in team ]) # Find employees who exceeded their travel budget exceeded = [] for member, exp in zip(team, expenses): budget = budgets[member["level"]] total = sum(e["amount"] for e in exp) if total > budget["travel_limit"]: exceeded.append({ "name": member["name"], "spent": total, "limit": budget["travel_limit"] }) print(json.dumps(exceeded)) ``` -------------------------------- ### Claude's Server Tool Use for Code Execution Source: https://www.anthropic.com/engineering/advanced-tool-use This JSON represents a server tool use message where Claude invokes the 'code_execution' tool, passing the Python orchestration code as input. ```json { "type": "server_tool_use", "id": "srvtoolu_abc", "name": "code_execution", "input": { "code": "team = get_team_members('engineering')\n..." # the code example above } } ``` -------------------------------- ### Support Ticket API Schema Source: https://www.anthropic.com/engineering/advanced-tool-use This JSON schema defines the structure for creating a support ticket. It illustrates the limitations of JSON Schema in expressing usage patterns and conventions. ```json { "name": "create_ticket", "input_schema": { "properties": { "title": {"type": "string"}, "priority": {"enum": ["low", "medium", "high", "critical"]}, "labels": {"type": "array", "items": {"type": "string"}}, "reporter": { "type": "object", "properties": { "id": {"type": "string"}, "name": {"type": "string"}, "contact": { "type": "object", "properties": { "email": {"type": "string"}, "phone": {"type": "string"} } } } }, "due_date": {"type": "string"}, "escalation": { "type": "object", "properties": { "level": {"type": "integer"}, "notify_manager": {"type": "boolean"}, "sla_hours": {"type": "integer"} } } }, "required": ["title"] } } ``` -------------------------------- ### Code Execution Tool Result Source: https://www.anthropic.com/engineering/advanced-tool-use This JSON represents the result of a code execution tool. It is sent back to Claude, containing the processed output such as stdout. ```json { "type": "code_execution_tool_result", "tool_use_id": "srvtoolu_abc", "content": { "stdout": "[{\"name\": \"Alice\", \"spent\": 12500, \"limit\": 10000}... Play]" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.