State propagation

Each tool result feeds into the next decision. When the agent calls get_weather and gets "25", that result is in the messages list. The next LLM call sees it and can use "25" as input for the multiply tool. This is state propagation: information flows through the loop.

State flowing through multiple tool calls

04-agent-loop.ipynb
python
# After running the multi-step task,
# inspect the full message trace:
for msg in agent.messages:
    role = msg.get("role", msg.role)
    if role == "tool":
        print(f"  [tool] {msg['name']}: {msg['content']}")
    elif role == "assistant":
        content = getattr(msg, "content", None)
        calls = getattr(msg, "tool_calls", None)
        if calls:
            for tc in calls:
                print(f"  [assistant] calls {tc.function.name}")
        else:
            print(f"  [assistant] {content[:60]}...")
    else:
        print(f"  [{role}] {msg['content'][:60]}...")

The messages list is the complete trace of the agent's execution, capturing every decision and result.

Matching exercise: Match agent loop concepts

Loading practice…

Quiz: Quiz

Loading practice…