Task 3 · 8 tasks
File sessions
Persist the conversation to disk so the agent still knows Alice after a restart.
The “Goldfish” problem
Alice introduced herself. One restart later the agent greeted her like a stranger. Give it short-term memory that survives the process.
Build it
Make the conversation survive a restart
Challenge
Give the Task 2 agent a session that is saved under
SESSIONS_DIRwith the idSESSION_ID(alice_session_starterin your starter,alice_sessionin the reference, so the reference never fills in your starter's memory).Work in
phase1/starter/t3_sessions.py(look forTODO; an unfinished one prints[starter] TODO …) and run it withuv run bootcamp.py phase1 t3 --starter. The reference solution isphase1/t3_sessions.py;uv run bootcamp.py phase1 t3runs it.Hint 1
Strands has session managers that plug into the agent lifecycle. Look at
strands.session.FileSessionManager. See Strands: session management.Hint 2
Create it once, before the agent, and pass it as
session_manager=.sketchread onlysession_manager = FileSessionManager(session_id=..., storage_dir=str(SESSIONS_DIR))Solution
Paste each block below into
phase1/starter/t3_sessions.pyin place of the definition with the same name (the TODO), including any import line that comes with it. Nothing else in the file changes.phase1/starter/t3_sessions.py · replace build_session_manager() (keep its import line)from strands.session import FileSessionManager def build_session_manager() -> FileSessionManager: """Session SESSION_ID, stored as JSON files under SESSIONS_DIR.""" return FileSessionManager(session_id=SESSION_ID, storage_dir=str(SESSIONS_DIR))Introduce yourself, then restart
terminal · your starter fileuv run bootcamp.py phase1 t3 --starter "My name is Alice Chen, CEO of DataStream Corp" uv run bootcamp.py phase1 t3 --starter "What's my name?"terminal · reference solutionuv run bootcamp.py phase1 t3 "My name is Alice Chen, CEO of DataStream Corp" uv run bootcamp.py phase1 t3 "What's my name?"Two separate processes, one memory. Look at what was stored:
terminalls phase1/sessions/session_alice_session_starter/agents/agent_default/messages/ # your starter ls phase1/sessions/session_alice_session/agents/agent_default/messages/ # referenceTo start over, pass a new session name:
--session alice2(any letters, digits,_or-) starts an empty session, and the run prints[session] ...so you always see which one you are in. Deleting a session's folder works too.Experiments
- Open a
message_*.jsonfile. What exactly is persisted? - Play two users: introduce yourself as Bob with
--session bob, then ask--session bob "What's my name?"and the same without--session. Now run both people on one shared session name: each sees the other's history. That's the isolation problem AgentCore Memory solves in Phase 2.
- Open a
Check your work
Phase 1 has no automated test: you check it by running the task and looking for the result below.
In the second process, “What's my name?” answers Alice Chen without a [tool] line: the name comes from the restored history, not the database. JSON message files appear under phase1/sessions/session_alice_session_starter/ (reference: session_alice_session/). If your starter remembers nothing, check that it saves to SESSION_ID.
Failed? Run the same prompt on the reference (drop --starter). If the reference fails too, it's the model: rerun or try another MODEL_ID (uv run bootcamp.py llm models).
Under the hood
FileSessionManager hooks into the agent lifecycle: it restores messages when the agent is created and appends every new message as a JSON file. It's ideal for local work and useless for a fleet of containers, which is why Phase 2 swaps it for AgentCoreMemorySessionManager with almost the same call site.