Temporary State
Temporary state exists only for the duration of a single task run. When the task ends, it is discarded. This is the most common type of state for single-session agents.
Temporary State Characteristics
Temporary state is:
- Created when a task starts
- Held in memory (RAM) during the task
- Discarded when the task completes, fails, or times out
- Not shared between different task runs
When to use temporary state:
- For single-task workflows that complete in one session
- When the results do not need to be recalled in future sessions
- When privacy is important — data that should not be stored long-term
- For intermediate calculations, search results, and scratchpad data
Limitations:
- Lost if the agent crashes mid-task
- Cannot be recalled in a new session
- Limited to the memory available on the server running the agent
In-Memory State Example
# Simple in-memory state manager for a single task
class TaskState:
def __init__(self, goal: str, max_steps: int = 15):
self._state = {
"goal": goal,
"step": 0,
"max_steps": max_steps,
"status": "running",
"history": [],
"data": {},
"errors": [],
}
def record_action(self, action: str, args: dict, observation: dict):
"""Record a completed action and its result."""
self._state["history"].append({
"step": self._state["step"],
"action": action,
"args": args,
"observation": observation
})
self._state["step"] += 1
if observation.get("status") == "error":
self._state["errors"].append({
"step": self._state["step"],
"action": action,
"error": observation.get("error")
})
def store(self, key: str, value):
"""Store intermediate data."""
self._state["data"][key] = value
def get(self, key: str, default=None):
"""Retrieve stored data."""
return self._state["data"].get(key, default)
def complete(self, result):
self._state["status"] = "complete"
self._state["result"] = result
@property
def steps_remaining(self):
return self._state["max_steps"] - self._state["step"]
@property
def is_running(self):
return self._state["status"] == "running"
# Usage
state = TaskState("Find Python frameworks", max_steps=10)
state.record_action("web_search", {"query": "Python frameworks"},
{"status": "success", "results": ["Django", "Flask"]})
state.store("frameworks", ["Django", "Flask"])
print("Frameworks:", state.get("frameworks"))
print("Steps remaining:", state.steps_remaining)