Claude On Google Cloud
← All lessons
Lesson 32Claude On Google Cloud

Sending tool results

Summary audio

Spoken summary — press play to read along: the line being spoken stays near the top.

Study notes

🤖 Tool Use and Function Calling Workflow

**I. Executing the Requested Tool (Step 4)**

  • Accessing Arguments: The arguments (input) for the tool function are found within the Claude response structure, specifically inside the tool use block (e. g. , response content[1]. input).
  • Function Invocation: Since the tool function often expects keyword arguments, the input dictionary received from Claude must be unpacked and passed to the function using the double asterisk operator (e. g. , function_name(**input_dictionary)).

**II. Sending Tool Results Back to Claude (Step 5)**

  • Purpose: After executing the tool, a follow-up request must be sent to Claude to provide the results, allowing Claude to generate a final, informed response.
  • Conversation History: This follow-up request must include the entire conversation history (original user message → Claude's tool request → new tool result).
  • The Tool Result Block: The tool output is delivered to Claude via a special tool result block, which is placed inside a user message.

**III. Key Components of the Tool Result Block**

  • tool_use_id: This is the most critical field. It is a unique identifier assigned to the original tool use request by Claude. The tool result block must use this exact ID to ensure the output is correctly matched to the corresponding tool call.
  • Example: If Claude requests two tools (Tool A and Tool B), the system must send two separate tool result blocks, each containing the correct ID (e. g. , ID_A and ID_B).
  • content: This field holds the actual output returned by the executed tool function. The output (whether a number, list, or dictionary) must be converted into a string (often plain JSON) before being sent.
  • is_error (Optional): Set to true if the tool function execution failed.

**IV. Complete Workflow Summary**

  • User Input: User sends a message.
  • Claude Response: Claude responds with a tool use block (request for a tool).
  • System Action: The system executes the requested tool function using the provided arguments.
  • Feedback Loop: The system sends a follow-up request to Claude, including the full history and a new user message containing the tool result block.
  • Final Output: Claude processes the tool result and generates a final response, typically containing a text block.

Takeaways

  • Tool arguments are extracted from the tool use block and must be unpacked (e. g. , using the double asterisk operator) to invoke the function.
  • After execution, the system must send the entire conversation history back to Claude, including the new tool result.
  • The tool output is delivered to Claude via a special tool result block which is placed inside a user message.
  • The tool_use_id is the most critical field, as it uniquely identifies and matches the tool result to the original tool request.
  • The complete workflow is a loop: User Input → Claude Tool Request → System Execution → Claude Final Response.
Flashcards 8 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 1 questions