Skip to content

OSSS.ai.context

OSSS.ai.context

AgentOutputEnvelope

Bases: BaseModel

Canonical representation of a single agent's output.

This is the "one true" internal format. Everything else (agent_outputs dict, execution_state mirrors, API payloads) is derived from this.

preview property

Short preview of content for logging / UIs.

as_public_dict()

Dict form safe for API export (no internal-only fields).

AgentContext

Lightweight shared context object passed between agents and orchestrator.

Responsibilities
  • Hold execution_state (shared mutable dict)
  • Hold a simple agent_outputs mapping (logical_name -> last content)
  • Hold a canonical list of AgentOutputEnvelope objects
  • Provide helper accessors used by agents (e.g. data_query) and orchestrator

output_envelopes property

Public, serialization-friendly view of envelopes.

Orchestration code treats each item either as Mapping (dict) or as an object with .agent_name / .logical_name / .content / .meta attributes. Returning dicts here keeps things simple.

agent_output_envelopes property

Backwards-compatible access used by some internals.

Orchestrator code is defensive and can handle actual objects as well.

add_agent_output(agent_name, content=None, *, logical_name=None, role=None, meta=None, action=None, intent=None)

Primary way agents should record output.

Supports both
  • add_agent_output("data_query", payload)
  • add_agent_output("data_query", payload, logical_name="data_query")

add_agent_output_envelope(envelope)

Backwards-compatible helper if some code still constructs envelopes directly.

add_agent_token_usage(agent_name, *, input_tokens=0, output_tokens=0, total_tokens=None)

Lightweight token accounting helper used by agents.

Aggregates per-agent token usage into execution_state["token_usage"]. Compatible with existing agents that call context.add_agent_token_usage.

get_last_output(key)

Return the content of the most recent envelope whose logical_name matches key OR whose agent_name starts with f"{key}:".

get_classifier_result()

Canonical place to read classifier output. ClassificationService should stash into execution_state['classifier_result'].

get_user_question()

Best-effort way to retrieve the original user question.

as_debug_dict()

Safe debug view of this context for logging or inspection.