liveBook · Manning

Tool result

As explained in Context Engineering

A tool output is information returned by a tool after it runs, such as a response, computed value, or command result.

A tool result is the information returned after an agent runs a tool, such as an API response, computed value, or command output. It differs from a tool call, which is the model’s structured request. Results usually enter the working context and can inform the model’s next response; only relevant outputs are later persisted as memory. section 1.5.3

Weather lookup

A function-calling loop executes a requested weather function and adds its returned weather value to the model’s context before it generates the final answer. section 4.6.1

Listing 4.1 Python script using an OpenAI model and a mock weather tool
from openai import OpenAI
import json

client = OpenAI()

TOOLS = [{ #1
    "type": "function",
    "name": "get_weather", #2
    "description": "Get the current weather in a location",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City or place name"
            }
        },
        "required": ["location"]
    }
}]

def query_model(prompt, model="gpt-4o-mini"):
    response = client.responses.create( #3
        model=model,
        input=prompt,
        tools=TOOLS,
        tool_choice="required",
    )
    input_items = list(response.output)
    for item in response.output: #4
        if item.type != "function_call":
            continue
        function_name = item.name
        function_args = json.loads(item.arguments)
        result = route_function_call(function_name, function_args) #5
        input_items.append({
            "type": "function_call_output",
            "call_id": item.call_id,
            "output": json.dumps(result),
        })
    final_response = client.responses.create( #6
        model=model,
        input=input_items,
        tools=TOOLS,
    )
    return final_response.output_text

Trace the function-calling loop that returns a mock weather result to the model. section 4.6.1

How Context Engineering covers it

How deep it goes
Defines results and traces their return to context, without detailing result validation or handling.
Examples
Uses a returned weather value and bug investigation involving an issue report, git diff, and project documentation.
What you can do after
Understand how a tool’s returned value becomes available to an agent during response generation.
How it connects
Connects tool results to tool calls, context windows, working context, and memory.

Also explained in

Compare how 4 books explain tool result →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Context Engineering. The section links point to the parts of the book it draws on.