Runtime¶
Runtime types, events, and registry for pluggable execution engines.
RuntimeEvent¶
RuntimeEvent dataclass ¶
Unified event stream from the runtime.
Types: - assistant_delta: data={"text": "..."} - status: data={"text": "..."} - tool_call_started: data={"name": "...", "correlation_id": "...", "args": {...}} - tool_call_finished: data={"name": "...", "correlation_id": "...", "ok": bool, "result_summary": "..."} - approval_required: data={"action_name": "...", "args": {...}, "allowed_decisions": [...], "interrupt_id": "..."} - user_input_requested: data={"prompt": "...", "interrupt_id": "..."} - native_notice: data={"text": "...", "metadata": {...}} - final: data={"text": "...", "new_messages": [...], "metrics": {...}, ...metadata} - error: data=RuntimeErrorData.to_dict()
approval_required staticmethod ¶
approval_required(action_name: str, args: dict[str, Any] | None = None, allowed_decisions: list[str] | None = None, interrupt_id: str | None = None, description: str = '') -> RuntimeEvent
Request human approval / tool review.
user_input_requested staticmethod ¶
The runtime expects user/human input.
native_notice staticmethod ¶
Explicit notice about native-specific semantics.
tool_call_started staticmethod ¶
tool_call_started(name: str, args: dict[str, Any] | None = None, correlation_id: str | None = None) -> RuntimeEvent
Start of a tool call.
tool_call_finished staticmethod ¶
tool_call_finished(name: str, correlation_id: str, ok: bool = True, result_summary: str = '') -> RuntimeEvent
End of a tool call.
final staticmethod ¶
final(text: str, new_messages: list[Message] | None = None, metrics: TurnMetrics | None = None, session_id: str | None = None, total_cost_usd: float | None = None, usage: dict[str, Any] | None = None, structured_output: Any = None, native_metadata: dict[str, Any] | None = None) -> RuntimeEvent
Final response.
RuntimeConfig¶
RuntimeConfig dataclass ¶
Configuration for runtime selection and parameters.
Priority: runtime_override > runtime_name > env COGNITIA_RUNTIME > default.
AgentRuntime¶
AgentRuntime ¶
Bases: Protocol
Agent Runtime protocol — canonical interface for all runtimes.
ISP: 4 methods (run, cleanup, cancel, context manager).
run ¶
run(*, messages: list[Message], system_prompt: str, active_tools: list[ToolSpec], config: RuntimeConfig | None = None, mode_hint: str | None = None) -> AsyncIterator[RuntimeEvent]
Run the agent loop, yielding streaming events.
RuntimeRegistry¶
RuntimeRegistry ¶
Thread-safe extensible registry for runtime factories.
Each entry maps a runtime name to: - factory_fn: Callable[[RuntimeConfig, ...], AgentRuntime] - capabilities: RuntimeCapabilities | None
CostBudget¶
CostBudget dataclass ¶
Budget limits for cost tracking.
Attributes: max_cost_usd: Maximum total cost in USD. None = no limit. max_total_tokens: Maximum total tokens (input + output). None = no limit. action_on_exceed: What to do when budget is exceeded. "error" = emit budget_exceeded error event. "warn" = report warning status but continue.
CostTracker¶
CostTracker ¶
Accumulates token usage and checks budget limits.
Thread-safe for single-threaded async usage (no locks needed).