Working Memory
Working memory is the most transient level of the memory hierarchy, existing only for the duration of a single agent run.
Purpose
Working memory stores:
- Current task context
- Intermediate results
- Accumulated observations
- Step-to-step state
Lifecycle
Run Starts → Working Memory Created
│
├── Step 1: Read/Write working memory
├── Step 2: Read/Write working memory
├── Step N: Read/Write working memory
│
Run Ends → Working Memory ClearedAutomatic Population
The execution engine automatically populates working memory:
{
"working_memory": {
"input": {
"original_request": "Offboard Sarah Chen",
"parsed": {
"employee": "sarah.chen@company.com",
"action": "offboard"
}
},
"observations": [
{
"step": 1,
"summary": "Retrieved employee profile and access list"
},
{
"step": 2,
"summary": "Risk score calculated: 85/100 (HIGH)"
}
],
"state": {
"risk_level": "high",
"approved_actions": ["revoke_aws"],
"pending_actions": ["revoke_github", "transfer_docs"]
}
}
}Agent Access
Agents can read and write working memory using the memory_read and memory_write tools:
Reading
{
"tool": "memory_read",
"input": {
"level": "working",
"key": "observations"
},
"output": [
{"step": 1, "summary": "Retrieved employee profile..."},
{"step": 2, "summary": "Risk score calculated..."}
]
}Writing
{
"tool": "memory_write",
"input": {
"level": "working",
"key": "state.current_focus",
"value": "knowledge_transfer"
}
}Use Cases
Tracking Progress
{
"completed_tasks": ["gather_info", "assess_risk", "revoke_aws"],
"remaining_tasks": ["revoke_github", "transfer_docs", "send_farewell"]
}Storing Intermediate Results
{
"employee_data": {
"id": "user_456",
"name": "Sarah Chen",
"apps": ["aws", "github", "slack"]
},
"risk_assessment": {
"score": 85,
"factors": ["competitor", "admin_access"]
}
}Accumulating Context
{
"conversation_history": [
{"role": "user", "content": "Offboard Sarah"},
{"role": "agent", "content": "I'll process that. Risk is high..."}
]
}Best Practices
Keep It Organized
Structure working memory logically:
{
"input": { ... },
"state": { ... },
"results": { ... },
"observations": [ ... ]
}Don’t Overload
Working memory is for the current run only. For persistent storage:
- Use short-term for temporary cross-run data
- Use episodic for lessons learned
- Use semantic for long-term facts
Clean Up
While working memory clears automatically, explicitly removing unneeded data can help with context limits:
{
"tool": "memory_write",
"input": {
"level": "working",
"key": "raw_api_response",
"value": null
}
}