cauri jaye
← All writing

Making sure agents can share context properly

24 January 2026

Originally published on Substack, 24 January 2026.

The context problem nobody warned you about in multi-agent systems

Confused robots, generated by chatGPT

Most tutorials on building multi-agent systems gloss over a fundamental architectural question: how does Agent C know what Agent A already knew?

The demos look impressive. User sends a message, orchestrator routes to the right specialist agent, specialist calls tools, results flow back up the chain. Clean diagrams, happy arrows, everybody understanding their role.

Then you build the thing for real.

Where the diagrams lie

Picture a conversation happening within some bounded context, a tenant scope, a customer session, a document collaboration. The first agent in your chain knows which context spawned it. That agent calls a second agent. The second agent calls a third. Somewhere along the way, a tool gets invoked.

Now: which tenant does that tool operate in?

The tool has no idea. Neither does the third agent, unless you explicitly told it. And you probably forgot to tell it, because you didn’t realise you needed to until something broke.

Prompt bloat: You start injecting contextual IDs and metadata into every prompt. “Remember, you’re operating in tenant X for user Y in session Z.” This consumes tokens, clutters the agent’s attention, and sometimes degrades performance because you’ve buried the actual task under administrative preamble.

Brittle workarounds: Each new context type demands its own passing mechanism. Session IDs get threaded one way, user preferences another, document references a third. The codebase accumulates special cases like sediment.

Tools flying blind: Your agents call tools, and those tools need context too. Without explicit threading through every function signature, they operate in a vacuum. A database query tool returns results from the wrong tenant. A file operation touches the wrong directory scope. These bugs hide until production.

No trace-scoped state: Some information should exist only for the lifetime of a single agent chain, intermediate results, accumulated permissions checks, partial aggregations, then vanish. You have nowhere clean to put it. So you stuff it in Redis with a TTL and hope the key naming convention holds.

I’ve hit every one of these building enterprise systems. The pattern recurs so reliably that I stopped treating it as a series of individual bugs and started recognising it as an architectural gap.

Why “just pass it through” doesn’t scale

The intuitive fix, threading context through function parameters, works until it doesn’t.

You add a tenant ID parameter. Then a user ID. Then a session type. Then feature flags, then permission scopes, then audit correlation IDs. Each new requirement touches every function signature in the chain. Your type definitions balloon. Refactoring becomes treacherous because changing the context shape means updating every intermediate layer, even those that only pass the context through without reading it.

Worse, this approach assumes you know at design time what context will matter. You don’t. The business will invent new scoping concepts. Regulatory requirements will demand new audit trails. A client will need multi-tenant isolation you hadn’t anticipated. Your clean function signatures will bloat into archaeological records of every context type anyone ever needed.

The fundamental mismatch: you’re treating context as data to push through a pipeline, when it should function as ambient state that any participant can query.

Event sourcing as context infrastructure

Event sourcing records every state change as an immutable event in a log. For context propagation, this means:

When a trace begins, you emit an event establishing context, `TraceInitialised { tenant_id, user_id, session_type, permission_scope }`, whatever scoping matters for this chain. Every agent and tool in the chain reads from this log to understand its operating environment. As agents act, they emit events that downstream participants can consume: `ToolInvoked { tool_name, parameters }`, `IntermediateResultCached { key, ttl }`, `PermissionChecked { resource, granted }`.

The trace has a natural boundary. Events scoped to that trace remain available for its duration, queryable by any participant. When the trace completes, you archive or discard them. No orphaned Redis keys, no leaked state between requests.

This transforms the problem. Instead of “push data through every function call,” you get “read from a shared, authoritative source.” An agent three layers deep doesn’t need context passed to it, it queries `getCurrentTenant()` and the event log provides the answer.

What this actually solves

Single source of truth: An immutable log ensures all agents and tools operate with identical context. The “did we pass the tenant ID correctly?” debugging sessions disappear, you query the log directly and see what was established at trace initialisation.

Context becomes queryable: Rather than threading IDs through function parameters, context becomes something agents and tools actively request. This also means you can add new context types without modifying intermediate layers. Emit a new event type, update the consumers that care, leave everything else untouched.

Unified access for agents and tools: Both read from the same event context using the same API. A database query tool that needs tenant scope doesn’t require special parameter passing, it queries the trace context like any other participant. This eliminates the divergent access patterns that make tool development tedious.

Traceability as a side effect: Every action gets recorded. When a tool returns wrong-scope data in production, you pull the event log and see exactly which tenant ID was active, which agent invoked the tool, and what parameters it passed. This pays dividends not just in debugging but in explaining agent behaviour to compliance teams and stakeholders who don’t trust black boxes.

Decoupling through events: Agents and tools communicate through the event log rather than direct parameter passing. They don’t need knowledge of each other’s internal implementations. Extending the system means adding new event producers or consumers, not threading new parameters through existing call chains.

Replay and recovery: If an agent fails mid-chain, you reconstruct state from the event log and retry without losing context. You can also replay entire traces for debugging, testing, or auditing purposes, something impossible when context exists only in ephemeral function parameters.

The honest trade-offs

Event sourcing brings real costs. You need infrastructure to store and query event logs efficiently, an append-only store with fast reads by trace ID. You need conventions for event schemas that won’t become their own versioning nightmare. If events propagate asynchronously, you introduce eventual consistency concerns that can bite you when an agent queries context before the initialisation event has landed.

The complexity budget increases. For simple, linear agent chains where you control every layer, explicit parameter passing might genuinely suffice. Not every system needs this machinery.

But the alternative, continuing to build ad-hoc context threading, has compounding costs that only become visible over time. The refactoring friction accumulates. The debugging sessions grow longer as you reconstruct state that was never recorded. The onboarding burden increases as new developers navigate the implicit conventions holding the system together.

I’ve watched teams spend more effort maintaining their ad-hoc context passing than they would have spent building proper event infrastructure from the start. The break-even point arrives sooner than most architects expect.

When this matters most

The context propagation problem scales with system complexity. If your agent chains stay short and your tools stay simple, you might never feel it. But the pain accelerates once you have chains longer than two agents, or multiple bounded contexts that can nest or overlap. Tools that perform scoped operations, database queries, file access, API calls with tenant headers, will expose the gap quickly. Audit requirements make it worse, since regulators tend to ask exactly what each agent knew and when it knew it. And if you expect to add new context types as the product evolves (which in my experience means every production system eventually), the ad-hoc approach starts creaking under its own weight.

The complexity doesn’t disappear, it just moves from scattered workarounds into a centralised, queryable, debuggable system. That relocation usually proves worth the investment once your agent architecture outgrows the demo stage.