Skip to main content

Module source

Module source 

Source
Expand description

Composable providers of per-request context.

A running job, an open checklist, a machine’s load: each reads some live state, renders it into the next request, and occasionally insists on something durable. A ContextSource is that contract, so the loop knows only the trait and the embedder registers whatever it needs with AgentBuilder::context_source.

A source returns ContextBlocks, each with a Placement:

  • Placement::Tail renders into the tail of one request, never into the middle of it, so content that changes on every single request is the last thing the model reads and the cached prefix never moves;
  • Placement::Stable appends to the conversation once and stays there, part of the cached prefix from then on. State changes, events and one-shot corrections are stable blocks, consumed when injected.

A LiveSource is live content: it renders into the cacheable prefix, after the system prompt and before the handoff, for large content that rarely changes and would cost full input price on every request in the tail. The agent keeps the version the model has seen. A change to it never rewrites a prefix the provider may hold: it is staged, announced once as the diff alert the source writes for it, and folded in at the next reassembly or compaction, which drops the diffs, exactly like a staged system block (see Context::update_live).

Structs§

AnyContextSource
A type-erased ContextSource, so an agent can hold a heterogeneous set.
AnyLiveSource
A type-erased LiveSource, so an agent can hold a heterogeneous set.
Block
A single piece of rendered context, identified by its tag.
ContextBlock
A piece of context and where it goes.
LiveChange
A change to a LiveSource’s block, as the model is to be told it: from the content it knows — the prefix’s block with every change announced since applied — to the content just rendered.

Enums§

Moment
The point in the loop at which a ContextSource is asked for blocks.
Placement
Where a ContextBlock goes in the conversation.

Traits§

ContextSource
Supplies context to the requests the agent sends.
LiveSource
Supplies live content: context that lives in the cacheable prefix of every request, after the system prompt and before the handoff, and changes while the session runs.