๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Agentic AI Notes
Topic #15

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.

Want to go beyond the notes?

Join CodingNow 2.0's Agentic AI course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Agent Context โ€“ FAQs

Quick answers about learning Agent Context in Agentic AI.

This free note from CodingNow 2.0 explains Agent Context in Agentic AI โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Agentic AI topic on CodingNow 2.0, including Agent Context, is 100% free with no signup required.
With focused practice, most students grasp Agent Context in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now