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 #205

Agent Context

Context is everything actually included in the prompt sent to the LLM at each decision point — the goal, relevant history, available tool definitions, and recent observations. It's the agent's entire "field of view" for that one decision.

What Typically Goes Into an Agent's Context

System instructions:
  "You are a data-analysis agent. Use the available tools to
   answer the user's question. Only call a tool when necessary."

Available tools (schema):
  - run_sql_query(query: string)
  - get_table_schema(table_name: string)

Goal: "What was our top-selling product last month?"

Recent history:
  - Called get_table_schema("sales") → returned columns: id, product, amount, date
  - (agent now deciding its next action based on the above)

All of this — instructions, tool schemas, goal, and history — competes for space in the same bounded context window.

Context Grows With Every Iteration

Each loop iteration typically adds more to the history (the new action and its observation), so context tends to grow as a task progresses. Left unmanaged, a long-running agent task can approach or exceed the context window, degrading decision quality or causing failures. This is why real agent systems often summarize or prune older history rather than keeping everything verbatim forever.

Context Design Is a Real Engineering Decision

ChoiceTradeoff
Include full tool result verbatimMore accurate, but consumes more context budget — problematic for large results
Summarize tool results before adding to contextSaves space, but risks losing detail the agent needs later
Keep full historyMaximum information, but grows unbounded
Keep only recent N stepsBounded size, but the agent can "forget" earlier relevant findings

See Context Design for the deeper engineering patterns.

Common Mistakes

  • Dumping entire raw tool outputs (e.g. a huge JSON API response) into context unfiltered, wasting context budget and increasing cost per call
  • Not monitoring context size as a task runs longer — a task that works fine in short demos can silently degrade once real-world tasks run for many more iterations

Interview Relevance

"An agent's answers get worse the longer a task runs. What would you investigate?" — context growth and window pressure is one of the first, most likely causes to check.

Practice Question

An agent's tool returns a 50,000-word document as a single observation. Propose a way to include it in context without overwhelming the context window.

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 →