Understanding the Agent's State › A Complete State Example

Michael BrenndoerferJuly 7, 20251 min read
AI Agent HandbookAll chapters
Part 7 of 15Agent State and Architecture - Putting It All Together
Chapter 18Understanding the Agent's State › A Complete State Example
Reading section 5 of 12 · A Complete State Example · 1 minSection 5 of 12 · 1 min

Book contents

Section 5 of 12 · 1 min read

Understanding the Agent's State › A Complete State ExampleOne section · Sections in this chapter5 / 12 ↓

Let's see what the agent's state might look like during our Paris trip booking:

In[9]:
Code
state = {
    "current_goal": "Book flight to Paris and find hotel near Eiffel Tower",
    "goal_status": "in_progress",
    "conversation_history": [
        {"role": "user", "content": "Book me a flight to Paris next week..."},
        {"role": "assistant", "content": "I'll help you with that..."},
        {"role": "assistant", "content": "I found three morning flights..."},
        {"role": "user", "content": "The United flight."},
    ],
    "knowledge": {
        "user_preferences": {
            "prefers_morning_flights": True,
            "budget_range": "mid-range",
        }
    },
    "working_memory": {
        "flight_search_results": [
            {"airline": "Air France", "time": "8:30 AM", "price": 450},
            {"airline": "United", "time": "10:00 AM", "price": 425},
            {"airline": "Delta", "time": "11:30 AM", "price": 440},
        ],
        "selected_flight": {
            "airline": "United",
            "time": "10:00 AM",
            "price": 425,
        },
    },
    "available_tools": ["flight_search", "flight_booking", "hotel_search"],
    "tools_used": ["flight_search"],
    "task_plan": [
        "Search for flights to Paris",
        "Book selected flight",
        "Search for hotels near Eiffel Tower",
        "Present hotel options",
    ],
    "current_step": 1,  # Booking the flight
}

This state tells the complete story of where the agent is. If something interrupts the process, the agent can look at its state and pick up where it left off. If the user asks a clarifying question, the agent has all the context it needs to answer appropriately.