Lesson 3 of 4 Advanced Prompt Engineering for Agents

Making Multi-Agent Systems Context-Aware

This lesson explains how agents become context-aware, so that users experience a multi-agent system as one assistant that remembers what was said, behaves appropriately for the user and the stage of the task, and never makes the user repeat information after a hand-off.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the sources of context an agent should adapt to.
  • Pass context between agents as a structured state object.
  • Keep shared context correct with single field owners, systems of record and lifetimes.

Sources of context

An agent's behaviour should adapt to several kinds of context. The workflow stage determines whether the agent should gather information, decide, confirm or report. The user's identity and role determine what the agent may reveal and do. The conversation state records facts already established, commitments made and open questions. The upstream output is what earlier agents concluded. Environmental context, such as the date, the channel and the user's locale, affects wording and validity.

Match the pairs

Kinds of context

Exam skills 2.1.2

Match each source of context with what it determines.

Log in to try this activity Interactive activities are free with an account.

Passing context between agents

Context is passed as a structured state object rather than as a transcript. The state contains typed fields such as intent, entities with stable IDs, verified identity, collected data, decisions with their source agent and open questions. Each agent receives the fields it needs, injected into its prompt, and writes back its results in a defined schema.

class CaseState(BaseModel):
    intent: Literal["refund", "repair", "question", "unknown"]
    customer_id: str | None
    verified: bool = False
    order_ids: list[str] = []
    facts: dict[str, str] = {}          # e.g. {"damage": "cracked screen", "purchase_date": "2026-08-14"}
    open_questions: list[str] = []
    decisions: list[dict] = []          # {"agent": "triage", "decision": "route_to_repairs", "reason": "..."}

Adapting behaviour

With the state available, behaviour adapts in predictable ways: a specialist greets the user with a confirmation of what it already knows instead of asking again; an agent skips identity verification when verified is true; an agent addressing a staff member shows internal details hidden from customers; and an agent reports its status in a structured field (complete, needs_input, escalate) so the orchestrator can choose the next step without parsing prose.

Scenario questions

Behaviour driven by state

Exam skills 2.1.2

Choose how agents should behave given the shared case state.

Log in to try this activity Interactive activities are free with an account.

Keeping shared context correct

Shared context is only useful if it is correct, and errors in it spread to every agent that reads it. Three practices protect it. First, each field has a single owner: only the identity agent sets verified, and only the agent that made a decision records it, so agents cannot overwrite each other's conclusions by accident. Second, facts that matter for security or money, such as the verified identity or an approved amount, come from systems of record or tools, not from what a model inferred from the conversation.

Third, context has a lifetime. Facts that can change, such as an order status, carry the time they were retrieved and are refreshed when they become stale, and context from one task is cleared or summarized before the next task begins, so that an agent does not act on information that no longer applies.

True or false

Correct shared context

Exam skills 2.1.2

Check the practices that keep shared context trustworthy.

Log in to try this activity Interactive activities are free with an account.
Worked example

Repeated questions

Customers complain that after the triage agent hands them to the returns agent, they are asked again for their order number and reason for return. Both agents run in one Agent Framework workflow.

The triage agent should write the order number and reason to the shared case state, and the returns agent's prompt should inject that state with an instruction to confirm rather than ask. Giving the returns agent the full transcript would also work but costs more tokens and exposes unrelated content; a larger model would not fix missing context.

Check yourself

Why should agents pass stable entity IDs in their shared state?

Show answer

Names and descriptions can be ambiguous or change. Stable IDs let every agent refer to the same customer, order or case.

Exam Tips

Remember for the exam

  • Pass structured state with stable entity IDs between agents.
  • Inject only the fields each agent needs.
  • Structured status outputs let orchestrators route without parsing prose.