Managing State Across Interactions › Practical Example: A Day in the Life

Michael BrenndoerferJuly 11, 20252 min read
AI Agent HandbookAll chapters
Part 7 of 15Agent State and Architecture - Putting It All Together
Chapter 20Managing State Across Interactions › Practical Example: A Day in the Life
Reading section 8 of 13 · Practical Example: A Day in the Life · 2 minSection 8 of 13 · 2 min

Book contents

Section 8 of 13 · 2 min read

Managing State Across Interactions › Practical Example: A Day in the LifeOne section · Sections in this chapter8 / 13 ↓

Let's trace how state evolves through a realistic day of interactions:

In[14]:
Code
## Morning: First session
agent = StatefulAgent(user_id="alice")

## User sets a preference
agent.run("Remember, I prefer morning flights and window seats.")
## Persistent state updated: preferences stored

agent.run("What's the weather in Paris?")
## Session state: conversation history grows
## Ephemeral state: none (simple question)

agent.run("Book me a flight there next Tuesday.")
## Ephemeral state: flight booking task started
## Session state: conversation continues

agent.run("The 8:30 AM one.")
## Ephemeral state: selection stored
## Task completes, ephemeral state cleared
## Persistent state: booking added to history

agent.end_session()
## Session state cleared
## Persistent state saved

## Afternoon: New session, same user
agent = StatefulAgent(user_id="alice")
## Persistent state loaded (preferences intact)
## Session state: fresh start

agent.run("What time is my Paris flight?")
## Agent can answer using persistent state (booking history)
## No ephemeral state needed

agent.run("Book me a hotel near the Eiffel Tower.")
## Ephemeral state: hotel search task
## Session state: new conversation thread

agent.run("The one with breakfast included.")
## Ephemeral state: selection made
## Task completes, ephemeral state cleared

agent.end_session()
## Session state cleared
## Persistent state saved with updated history

Throughout the day, the agent maintained the right information at the right level. Preferences persisted across sessions. Conversation context stayed within sessions. Task-specific data lived only as long as needed.