symfonic.agent.context.protocol¶
protocol ¶
ContextManager protocol + AssembledContext dataclass (Roadmap Item 8).
Per-turn context-assembly seam introduced in 7.2 (PR-6). Two concrete strategies ship internal to symfonic-core:
- :class:
~symfonic.agent.context.jit.JITContextManager-- minimal ~210-token prompt, no inline hydration. Memory loaded reactively by the LLM via thehydrate_contexttool. - :class:
~symfonic.agent.context.stratified.StratifiedHMSContextManager-- full HMS body with inline L1/L2 hydration on every turn. Maps to the pre-7.2jit_context=Falseproduction path.
The engine owns I/O around the call -- tool registration, conversation
history truncation, _thread_id derivation, tenant_id/
sub_tenant_id stamping. The strategy owns prompt-template choice,
the hydration cadence, and the L0/L1/L2 wrapping.
AssembledContext
dataclass
¶
AssembledContext(
system_prompt: str | None = None,
memory_context: HydratedMemory | None = None,
state_overrides: dict[str, Any] = dict(),
activation_log: dict[str, Any] | None = None,
metadata: dict[str, Any] = dict(),
)
Output of :meth:ContextManager.assemble.
All fields are optional so the engine can no-op cleanly when the
strategy returns nothing (e.g. the enable_hms_prompt=False path).
Attributes:
| Name | Type | Description |
|---|---|---|
system_prompt |
str | None
|
Rendered system prompt body. |
memory_context |
HydratedMemory | None
|
Frozen :class: |
state_overrides |
dict[str, Any]
|
Per-strategy state additions for LangGraph
invocation -- today carries |
activation_log |
dict[str, Any] | None
|
Spreading-activation log consumed by |
metadata |
dict[str, Any]
|
Strategy-private telemetry slot (latency_ms, entries_count, strategy_name). Not consumed by the engine today; reserved for downstream observability. |
ContextManager ¶
Bases: Protocol
Per-turn context-assembly strategy.
Implementations are selected once at agent construction (via
:func:~symfonic.agent.context.make_context_manager) and are
invoked exactly once per turn from each of the three entry points
(run / stream / stream_typed).
Two concrete strategies ship with the framework:
- :class:
~symfonic.agent.context.jit.JITContextManager - :class:
~symfonic.agent.context.stratified.StratifiedHMSContextManager
The protocol is intentionally single-method. The JIT case returning
memory_context=None is the type-level signal that no hydration
happened; the engine branches on truthiness, not on the strategy
class.
assemble
async
¶
assemble(
*,
query: str,
scope: FrameworkTenantScope | None,
intent_verdict: Any | None,
auto_hydrate: bool = True,
) -> AssembledContext
Assemble the per-turn context for one agent invocation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query text. The canonical semantic anchor used for retrieval, embeddings, and tool-manifest gating. |
required |
scope
|
FrameworkTenantScope | None
|
Tenant scope for memory isolation. Carries
|
required |
intent_verdict
|
Any | None
|
Optional :class: |
required |
auto_hydrate
|
bool
|
v7.7.8 (Jarvio 9th-recurrence): explicit
hydration-on-this-turn flag. Pre-7.7.8 the engine
misused |
True
|
Returns:
| Type | Description |
|---|---|
AssembledContext
|
class: |
AssembledContext
|
memory-context bundle. |