← ClaudeAtlas

function-callinglisted

LLM function calling and tool use patterns. Covers JSON tool schemas (strict mode), execution loops, structured output with Pydantic, parallel tool calls, and LangChain tool binding. OpenAI and Anthropic patterns. Use when: enabling LLMs to call external tools, defining tool schemas, building tool execution loops, or returning structured JSON. Triggers on: function calling, tool use, tool schema, structured output, Pydantic validation, tool execution, parallel tool calls, bind tools
ArieGoldkin/claude-forge · ★ 6 · AI & Automation · score 77
Install: claude install-skill ArieGoldkin/claude-forge
# Function Calling Enable LLMs to use external tools and return structured data. ## Basic Tool Definition (2026 Best Practice) ```python # OpenAI format with strict mode (2026 recommended) tools = [{ "type": "function", "function": { "name": "search_documents", "description": "Search the document database for relevant content", "strict": True, # ← 2026: Enables structured output validation "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The search query" }, "limit": { "type": "integer", "description": "Max results to return" } }, "required": ["query", "limit"], # All props required when strict "additionalProperties": False # ← 2026: Required for strict mode } } }] # Note: With strict=True: # - All properties must be listed in "required" # - additionalProperties must be False # - No "default" values (provide via code instead) ``` ## Tool Execution Loop ```python async def run_with_tools(messages: list, tools: list) -> str: """Execute tool calls until LLM returns final answer.""" while True: response = await llm.chat(messages=messages, tools=tools) # Check if LLM wants to call tools if not response.tool_calls: return respons