Tool use patterns

From grandamenium/cortextos · View interactive version

Tool use patterns is an AI agent skill from the GitHub repository grandamenium/cortextos. Patterns for Claude tool use including sequential tools, parallel execution, error handling, and agentic loops.

How to use this skill

Skill file

Tool Use Patterns

Advanced patterns for Claude's tool use capability.

Agentic Loop

while True:
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        tools=tools,
        messages=messages
    )

    if response.stop_reason == "end_turn":
        break

    for block in response.content:
        if block.type == "tool_use":
            result = execute_tool(block.name, block.input)
            messages.append({"role": "assistant", "content": response.content})
            messages.append({"role": "user", "content": [
                {"type": "tool_result", "tool_use_id": block.id, "content": str(result)}
            ]})

Error Handling

{"type": "tool_result", "tool_use_id": id, "is_error": true, "content": "File not found"}

Parallel Tool Calls

Claude can request multiple tools in one response. Execute them concurrently and return all results.

Best Practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.