Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Agentic AI Notes
Topic #204

Agent State

State is everything the agent needs to remember across iterations of a single task run — the accumulated history of decisions, tool results, and progress toward the goal.

What Typically Lives in State

State ElementExample
GoalThe original task, unchanged throughout the run
Action/observation historyEvery tool call made so far, and its result
Current iteration countUsed to enforce the loop's safety limit
Intermediate resultsPartial findings the agent has gathered so far
Status flagse.g. "awaiting human approval," "encountered an error"

Simplified Example

state = {
    "goal": "Find the total revenue for Q1 2026",
    "history": [
        {"action": "run_query", "args": {"month": "Jan"}, "result": 45000},
        {"action": "run_query", "args": {"month": "Feb"}, "result": 52000},
    ],
    "iteration": 2,
    "status": "in_progress"
}

Each iteration of the agent loop reads from and updates this structure.

State vs Memory — A Common Point of Confusion

State is scoped to the current task run — it typically doesn't need to persist once the task completes. Memory is about information that persists across separate runs or conversations — like remembering a user's preferences from a previous session. See Memory vs Context and Agent Memory for the fuller distinction. Some frameworks blur this line by persisting "state" across sessions, which effectively makes it function as memory — the important thing is being deliberate about which behavior you actually want.

Practical Use Case

If an agent's process crashes mid-task, well-designed state (persisted incrementally, not just held in memory) lets the system resume from the last completed step instead of restarting the entire task from scratch — see State Persistence and State Checkpoints.

Common Mistakes

  • Keeping state only in memory (a Python variable, for example) with no persistence — any crash loses all progress on a long-running task
  • Letting state grow unbounded across many iterations without any summarization/trimming, eventually exceeding the model's context window
  • Conflating state with memory and building a system that "remembers" things across unrelated tasks/users unintentionally

Interview Relevance

"What's the difference between an agent's state and its memory?" is a common conceptual-clarity question — state is per-run and typically transient, memory is what deliberately persists beyond a single run.

Practice Question

Design the state structure (in plain fields, not code) for an agent that processes a multi-page document one page at a time.

Related Notes

Want to go beyond the notes?

Join CodingNow's Agentic AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →