Sharing data and state across tools and agents using agency context.
Agency Context
is a centralized data store accessible by all tools and agents within an agency. It allows you to share data between agents, control execution flow, and maintain state across tool calls without passing large data structures in messages.
Tool A
collects data that Tool B
needs. The agent must explicitly pass this data as a parameter to Tool B
, consuming tokens and potentially hitting message limits.Tool A
can store the required data in the agency context, and Tool B
can retrieve it without needing direct parameter passing. This approach reduces complexity, saves tokens, and enables additional workflows.MasterContext
object in function tools. The two basic operations are:
ctx.context.set('key', value)
ctx.context.get('key', default_value)
ctx.context.set
. For example, you can store retrieved database context: