Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(docs): add generated API reference to version-0.6 snapshot

xf gongee1056df0a2c
diff --git a/website/versioned_docs/version-0.6/api/cubepi-agent.mdx b/website/versioned_docs/version-0.6/api/cubepi-agent.mdx
new file mode 100644
index 0000000..2896c92
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-agent.mdx
@@ -0,0 +1,588 @@
+---
+id: cubepi-agent
+title: cubepi.agent
+sidebar_position: 1
+hide_table_of_contents: false
+---
+
+# `cubepi.agent`
+
+### Agent {#agent}
+
+_class_
+
+```python
+Agent(self, *, provider: Provider, model: Model, system_prompt: str = '', tools: list[AgentTool] | None = None, thinking: ThinkingLevel = 'off', convert_to_llm: Callable[[list[Message]], list[Message]] | None = None, transform_context: Callable | None = None, transform_system_prompt: Callable | None = None, after_model_response: Callable | None = None, before_tool_call: Callable | None = None, after_tool_call: Callable | None = None, should_stop_after_turn: Callable | None = None, on_payload: OnPayloadCallback | None = None, on_response: OnResponseCallback | None = None, steering_mode: str = 'one-at-a-time', follow_up_mode: str = 'one-at-a-time', tool_execution: str = 'parallel', checkpointer: Any = None, thread_id: str | None = None, middleware: list[Middleware] | None = None, channel: HitlChannel | None = None)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L124)
+
+
+**Attributes**
+
+- `convert_to_llm`
+- `transform_context`
+- `transform_system_prompt`
+- `after_model_response`
+- `before_tool_call`
+- `after_tool_call`
+- `should_stop_after_turn`
+- `on_payload`
+- `on_response`
+- `tool_execution`
+- `checkpointer`
+- `thread_id`
+- `state`: `AgentState`
+- `channel`: `HitlChannel | None`
+- `in_flight_hitl_request`: `HitlRequest | None`
+
+
+**Methods**
+
+#### `subscribe` {#agent-subscribe}
+
+```python
+subscribe(listener: Callable) -> Callable[[], None]
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L210)
+
+
+#### `steer` {#agent-steer}
+
+```python
+steer(message: Message) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L216)
+
+
+#### `cancel_steer` {#agent-cancel-steer}
+
+```python
+cancel_steer(steer_id: str) -> bool
+```
+
+Remove a not-yet-drained steering message by its steer_id.
+
+Returns True if a queued message was removed; False if it was already
+drained or never queued (best-effort cancel).
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L219)
+
+
+#### `follow_up` {#agent-follow-up}
+
+```python
+follow_up(message: Message) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L227)
+
+
+#### `abort` {#agent-abort}
+
+```python
+abort() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L230)
+
+
+#### `wait_for_idle` {#agent-wait-for-idle}
+
+```python
+wait_for_idle() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L234)
+
+
+#### `reset` {#agent-reset}
+
+```python
+reset() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L238)
+
+
+#### `prompt` {#agent-prompt}
+
+```python
+prompt(message: str | Message | list[Message]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L247)
+
+
+#### `resume` {#agent-resume}
+
+```python
+resume() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L287)
+
+
+#### `detach` {#agent-detach}
+
+```python
+detach() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L385)
+
+
+#### `load_pending_hitl_request` {#agent-load-pending-hitl-request}
+
+```python
+load_pending_hitl_request() -> HitlRequest | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L403)
+
+
+#### `respond` {#agent-respond}
+
+```python
+respond(*, question_id: str | None = None, answer: Any) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L411)
+
+
+#### `abort_pending` {#agent-abort-pending}
+
+```python
+abort_pending(reason: str = 'aborted by host') -> None
+```
+
+Abort a pending HITL request and CLOSE the conversation.
+
+Per spec §5.2 "abort closes the conversation" — no new model call.
+Two-phase: Phase 1 (no lock) interrupts any in-flight HITL await via
+the agent signal; Phase 2 (with lock) appends synthetic deny
+tool_results + a terminal stop_reason="aborted" assistant message
+and emits AgentAbortedEvent.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L451)
+
+
+
+### AgentState {#agentstate}
+
+_class_
+
+```python
+AgentState(self, system_prompt: str = '', model: Model = (lambda: Model(id='unknown', provider='unknown'))(), thinking: ThinkingLevel = 'off', is_streaming: bool = False, streaming_message: Message | None = None, error_message: str | None = None, _tools: list[AgentTool] = list(), _messages: list[Message] = list(), _pending_tool_calls: set[str] = set())
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/agent.py#L85)
+
+
+**Attributes**
+
+- `system_prompt`: `str`
+- `model`: `Model`
+- `thinking`: `ThinkingLevel`
+- `is_streaming`: `bool`
+- `streaming_message`: `Message | None`
+- `error_message`: `str | None`
+- `tools`: `list[AgentTool]`
+- `messages`: `list[Message]`
+- `pending_tool_calls`: `set[str]`
+
+
+### run_agent_loop {#run-agent-loop}
+
+_function_
+
+```python
+run_agent_loop(*, prompts: list[Message], context: AgentContext, provider: Provider, model: Model, convert_to_llm: Callable, emit: Callable, transform_context: Callable | None = None, transform_system_prompt: Callable | None = None, after_model_response: Callable | None = None, before_tool_call: Callable | None = None, after_tool_call: Callable | None = None, should_stop_after_turn: Callable | None = None, get_steering_messages: Callable | None = None, get_follow_up_messages: Callable | None = None, stream_options: StreamOptions | None = None, tool_execution: str = 'parallel', system_prompt: str | None = None) -> list[Message]
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/loop.py#L31)
+
+
+### run_agent_loop_continue {#run-agent-loop-continue}
+
+_function_
+
+```python
+run_agent_loop_continue(*, context: AgentContext, provider: Provider, model: Model, convert_to_llm: Callable, emit: Callable, transform_context: Callable | None = None, transform_system_prompt: Callable | None = None, after_model_response: Callable | None = None, before_tool_call: Callable | None = None, after_tool_call: Callable | None = None, should_stop_after_turn: Callable | None = None, get_steering_messages: Callable | None = None, get_follow_up_messages: Callable | None = None, stream_options: StreamOptions | None = None, tool_execution: str = 'parallel', system_prompt: str | None = None) -> list[Message]
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/loop.py#L88)
+
+
+### execute_tool_calls {#execute-tool-calls}
+
+_function_
+
+```python
+execute_tool_calls(context: AgentContext, assistant_message: AssistantMessage, *, tool_execution: str = 'parallel', before_tool_call: Callable | None = None, after_tool_call: Callable | None = None, signal: asyncio.Event | None = None, emit: Callable) -> ToolCallBatch
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/tools.py#L260)
+
+
+### AfterToolCallContext {#aftertoolcallcontext}
+
+_class_
+
+```python
+AfterToolCallContext(self, assistant_message: AssistantMessage, tool_call: ToolCall, args: Any, result: AgentToolResult, is_error: bool, context: AgentContext)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L82)
+
+
+**Attributes**
+
+- `assistant_message`: `AssistantMessage`
+- `tool_call`: `ToolCall`
+- `args`: `Any`
+- `result`: `AgentToolResult`
+- `is_error`: `bool`
+- `context`: `AgentContext`
+
+
+### AfterToolCallResult {#aftertoolcallresult}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L67)
+
+
+**Attributes**
+
+- `content`: `list[Content] | None`
+- `details`: `Any`
+- `is_error`: `bool | None`
+- `terminate`: `bool | None`
+
+
+### AgentContext {#agentcontext}
+
+_class_
+
+```python
+AgentContext(self, system_prompt: str, messages: list[Message], tools: list[AgentTool] | None = None, extra: dict[str, Any] = dict())
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L48)
+
+
+**Attributes**
+
+- `system_prompt`: `str`
+- `messages`: `list[Message]`
+- `tools`: `list[AgentTool] | None`
+- `extra`: `dict[str, Any]`
+
+
+### AgentEndEvent {#agentendevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L107)
+
+
+**Attributes**
+
+- `type`: `Literal['agent_end']`
+- `messages`: `list[Message]`
+
+
+### AgentEvent {#agentevent}
+
+_attribute_
+
+```python
+AgentEvent = AgentStartEvent | AgentEndEvent | TurnStartEvent | TurnEndEvent | MessageStartEvent | MessageUpdateEvent | MessageEndEvent | ToolExecutionStartEvent | ToolExecutionUpdateEvent | ToolExecutionEndEve...
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L196)
+
+
+### AgentListener {#agentlistener}
+
+_attribute_
+
+```python
+AgentListener = Callable[[AgentEvent, asyncio.Event | None], Awaitable[None] | None]
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L215)
+
+
+### AgentStartEvent {#agentstartevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L103)
+
+
+**Attributes**
+
+- `type`: `Literal['agent_start']`
+
+
+### AgentTool {#agenttool}
+
+_class_
+
+```python
+AgentTool(self, name: str, description: str, parameters: type[TParams], execute: Callable[..., Awaitable[AgentToolResult]], label: str = '', execution_mode: Literal['sequential', 'parallel'] | None = None)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L30)
+
+
+**Attributes**
+
+- `name`: `str`
+- `description`: `str`
+- `parameters`: `type[TParams]`
+- `execute`: `Callable[..., Awaitable[AgentToolResult]]`
+- `label`: `str`
+- `execution_mode`: `Literal['sequential', 'parallel'] | None`
+
+
+**Methods**
+
+#### `to_definition` {#agenttool-to-definition}
+
+```python
+to_definition() -> ToolDefinition
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L39)
+
+
+
+### AgentToolResult {#agenttoolresult}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L23)
+
+
+**Attributes**
+
+- `content`: `list[Content]`
+- `details`: `Any`
+- `is_error`: `bool | None`
+- `terminate`: `bool | None`
+
+
+### BeforeToolCallContext {#beforetoolcallcontext}
+
+_class_
+
+```python
+BeforeToolCallContext(self, assistant_message: AssistantMessage, tool_call: ToolCall, args: Any, context: AgentContext)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L74)
+
+
+**Attributes**
+
+- `assistant_message`: `AssistantMessage`
+- `tool_call`: `ToolCall`
+- `args`: `Any`
+- `context`: `AgentContext`
+
+
+### BeforeToolCallResult {#beforetoolcallresult}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L59)
+
+
+**Attributes**
+
+- `block`: `bool`
+- `reason`: `str | None`
+- `edited_args`: `dict | None`
+- `deny_reason`: `str | None`
+- `hitl_trace`: `dict | None`
+
+
+### MessageEndEvent {#messageendevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L133)
+
+
+**Attributes**
+
+- `type`: `Literal['message_end']`
+- `message`: `Message`
+
+
+### MessageStartEvent {#messagestartevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L122)
+
+
+**Attributes**
+
+- `type`: `Literal['message_start']`
+- `message`: `Message`
+
+
+### MessageUpdateEvent {#messageupdateevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L127)
+
+
+**Attributes**
+
+- `type`: `Literal['message_update']`
+- `message`: `AssistantMessage`
+- `stream_event`: `StreamEvent`
+
+
+### ShouldStopAfterTurnContext {#shouldstopafterturncontext}
+
+_class_
+
+```python
+ShouldStopAfterTurnContext(self, message: AssistantMessage, tool_results: list[ToolResultMessage], context: AgentContext, new_messages: list[Message])
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L92)
+
+
+**Attributes**
+
+- `message`: `AssistantMessage`
+- `tool_results`: `list[ToolResultMessage]`
+- `context`: `AgentContext`
+- `new_messages`: `list[Message]`
+
+
+### ToolExecutionEndEvent {#toolexecutionendevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L153)
+
+
+**Attributes**
+
+- `type`: `Literal['tool_execution_end']`
+- `tool_call_id`: `str`
+- `tool_name`: `str`
+- `result`: `Any`
+- `is_error`: `bool`
+- `terminate`: `bool` — True iff the tool's AgentToolResult.terminate was True (or the after_tool_call hook set terminate=True). Recorders use this to mark the turn as terminated-by-tool without unwrapping `result`.
+- `blocked_by_hook`: `bool` — True iff the tool call was blocked by a `before_tool_call` hook returning `block=True`. Distinguishes hook-blocks from other immediate errors (tool-not-found, arg-validation failure).
+- `block_reason`: `str | None` — When `blocked_by_hook` is True, the reason string from `BeforeToolCallResult.reason` (or `None` if the hook supplied no reason).
+
+
+### ToolExecutionStartEvent {#toolexecutionstartevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L138)
+
+
+**Attributes**
+
+- `type`: `Literal['tool_execution_start']`
+- `tool_call_id`: `str`
+- `tool_name`: `str`
+- `args`: `Any`
+
+
+### ToolExecutionUpdateEvent {#toolexecutionupdateevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L145)
+
+
+**Attributes**
+
+- `type`: `Literal['tool_execution_update']`
+- `tool_call_id`: `str`
+- `tool_name`: `str`
+- `args`: `Any`
+- `partial_result`: `Any`
+
+
+### TurnEndEvent {#turnendevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L116)
+
+
+**Attributes**
+
+- `type`: `Literal['turn_end']`
+- `message`: `AssistantMessage`
+- `tool_results`: `list[ToolResultMessage]`
+
+
+### TurnStartEvent {#turnstartevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/agent/types.py#L112)
+
+
+**Attributes**
+
+- `type`: `Literal['turn_start']`
+
+
+### emit_event {#emit-event}
+
+_function_
+
+```python
+emit_event(emit_fn: Callable, event: object) -> None
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/utils/emit.py#L7)
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-checkpointer.mdx b/website/versioned_docs/version-0.6/api/cubepi-checkpointer.mdx
new file mode 100644
index 0000000..1775bd8
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-checkpointer.mdx
@@ -0,0 +1,365 @@
+---
+id: cubepi-checkpointer
+title: cubepi.checkpointer
+sidebar_position: 3
+hide_table_of_contents: false
+---
+
+# `cubepi.checkpointer`
+
+### Checkpointer {#checkpointer}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L13)
+
+
+**Methods**
+
+#### `load` {#checkpointer-load}
+
+```python
+load(thread_id: str) -> CheckpointData | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L15)
+
+
+#### `append` {#checkpointer-append}
+
+```python
+append(thread_id: str, messages: list[Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L16)
+
+
+#### `save_extra` {#checkpointer-save-extra}
+
+```python
+save_extra(thread_id: str, extra: dict[str, Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L17)
+
+
+#### `save_pending_request` {#checkpointer-save-pending-request}
+
+```python
+save_pending_request(thread_id: str, request: Any) -> None
+```
+
+Persist (or clear, if request is None) the pending HITL request for a thread.
+
+First-party implementations (Memory, SQLite, Postgres, MySQL) all implement this.
+HITL-requiring features (Agent.respond, CheckpointedChannel) use
+`getattr(checkpointer, "save_pending_request", None)` for graceful degradation.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L19)
+
+
+#### `load_pending_request` {#checkpointer-load-pending-request}
+
+```python
+load_pending_request(thread_id: str) -> Any
+```
+
+Load the persisted pending HITL request for a thread, or None.
+
+Returns a `HitlRequest` instance or `None`.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L28)
+
+
+
+### CheckpointData {#checkpointdata}
+
+_class_
+
+```python
+CheckpointData(self, messages: list[Any] = list(), extra: dict[str, Any] = dict())
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/base.py#L7)
+
+
+**Attributes**
+
+- `messages`: `list[Any]`
+- `extra`: `dict[str, Any]`
+
+
+### MemoryCheckpointer {#memorycheckpointer}
+
+_class_
+
+```python
+MemoryCheckpointer(self)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L9)
+
+
+**Methods**
+
+#### `load` {#memorycheckpointer-load}
+
+```python
+load(thread_id: str) -> CheckpointData | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L14)
+
+
+#### `append` {#memorycheckpointer-append}
+
+```python
+append(thread_id: str, messages: list[Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L17)
+
+
+#### `save_extra` {#memorycheckpointer-save-extra}
+
+```python
+save_extra(thread_id: str, extra: dict[str, Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L22)
+
+
+#### `save_pending_request` {#memorycheckpointer-save-pending-request}
+
+```python
+save_pending_request(thread_id: str, request: Any) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L27)
+
+
+#### `load_pending_request` {#memorycheckpointer-load-pending-request}
+
+```python
+load_pending_request(thread_id: str) -> Any
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/memory.py#L33)
+
+
+
+### PostgresCheckpointer {#postgrescheckpointer}
+
+_class_
+
+```python
+PostgresCheckpointer(self, dsn: str, *, min_pool_size: int = 1, max_pool_size: int = 10)
+```
+
+Checkpointer backed by PostgreSQL.
+
+
+**Usage**
+
+```python
+cp = PostgresCheckpointer(dsn="postgresql://...")
+async with cp:
+ await cp.append(thread_id, [msg1, msg2])
+ data = await cp.load(thread_id)
+ await cp.save_extra(thread_id, {"k": "v"})
+```
+
+Raises CubepiSchemaUninitialized / CubepiSchemaMismatch at __aenter__
+if the DB schema isn't compatible with this cubepi version.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L46)
+
+
+**Methods**
+
+#### `load` {#postgrescheckpointer-load}
+
+```python
+load(thread_id: str) -> CheckpointData | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L110)
+
+
+#### `append` {#postgrescheckpointer-append}
+
+```python
+append(thread_id: str, messages: list[Message]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L152)
+
+
+#### `save_extra` {#postgrescheckpointer-save-extra}
+
+```python
+save_extra(thread_id: str, extra: dict[str, Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L200)
+
+
+#### `save_pending_request` {#postgrescheckpointer-save-pending-request}
+
+```python
+save_pending_request(thread_id: str, request) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L213)
+
+
+#### `load_pending_request` {#postgrescheckpointer-load-pending-request}
+
+```python
+load_pending_request(thread_id: str)
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/postgres/checkpointer.py#L238)
+
+
+
+### SQLiteCheckpointer {#sqlitecheckpointer}
+
+_class_
+
+```python
+SQLiteCheckpointer(self, db_path: str)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L12)
+
+
+**Methods**
+
+#### `load` {#sqlitecheckpointer-load}
+
+```python
+load(thread_id: str) -> CheckpointData | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L49)
+
+
+#### `append` {#sqlitecheckpointer-append}
+
+```python
+append(thread_id: str, messages: list[Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L75)
+
+
+#### `save_extra` {#sqlitecheckpointer-save-extra}
+
+```python
+save_extra(thread_id: str, extra: dict[str, Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L86)
+
+
+#### `save_pending_request` {#sqlitecheckpointer-save-pending-request}
+
+```python
+save_pending_request(thread_id: str, request: Any) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L108)
+
+
+#### `load_pending_request` {#sqlitecheckpointer-load-pending-request}
+
+```python
+load_pending_request(thread_id: str) -> Any
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/sqlite.py#L125)
+
+
+
+### MySQLCheckpointer {#mysqlcheckpointer}
+
+_class_
+
+```python
+MySQLCheckpointer(self, dsn: str, *, min_pool_size: int = 1, max_pool_size: int = 10)
+```
+
+Checkpointer backed by MySQL (8.0.13+, InnoDB).
+
+
+**Usage**
+
+```python
+cp = MySQLCheckpointer("mysql://user:pw@host:3306/db")
+async with cp:
+ await cp.append(thread_id, [msg1, msg2])
+ data = await cp.load(thread_id)
+ await cp.save_extra(thread_id, {"k": "v"})
+```
+
+Raises CubepiSchemaUninitialized / CubepiSchemaMismatch at __aenter__ if the
+DB schema isn't compatible with this cubepi version.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L75)
+
+
+**Methods**
+
+#### `load` {#mysqlcheckpointer-load}
+
+```python
+load(thread_id: str) -> CheckpointData | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L159)
+
+
+#### `append` {#mysqlcheckpointer-append}
+
+```python
+append(thread_id: str, messages: list[Message]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L190)
+
+
+#### `save_extra` {#mysqlcheckpointer-save-extra}
+
+```python
+save_extra(thread_id: str, extra: dict[str, Any]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L244)
+
+
+#### `save_pending_request` {#mysqlcheckpointer-save-pending-request}
+
+```python
+save_pending_request(thread_id, request)
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L278)
+
+
+#### `load_pending_request` {#mysqlcheckpointer-load-pending-request}
+
+```python
+load_pending_request(thread_id)
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/checkpointer/mysql/checkpointer.py#L309)
+
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-mcp.mdx b/website/versioned_docs/version-0.6/api/cubepi-mcp.mdx
new file mode 100644
index 0000000..ee3fe88
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-mcp.mdx
@@ -0,0 +1,182 @@
+---
+id: cubepi-mcp
+title: cubepi.mcp
+sidebar_position: 5
+hide_table_of_contents: false
+---
+
+# `cubepi.mcp`
+
+### load_mcp_tools_http {#load-mcp-tools-http}
+
+_function_
+
+```python
+load_mcp_tools_http(server_url: str, *, headers: dict[str, str] | None = None, timeout: float = 30.0, transport: Transport = 'sse') -> MCPDiscoveryResult
+```
+
+Connect to an HTTP MCP server and discover its tools + metadata.
+
+Returns a [`MCPDiscoveryResult`](./cubepi-mcp#mcpdiscoveryresult) carrying:
+
+- `tools` — executable `AgentTool` per `tools/list` entry.
+- `server` — `MCPServerInfo` (name, version, websiteUrl, icons)
+ captured from the `initialize` handshake's `serverInfo`. Sourced
+ from MCP spec rev 2025-11-25's `Implementation` shape.
+- `tool_infos` — per-tool display metadata (currently `icons`)
+ captured from each `tools/list` entry, separated from
+ `AgentTool` so callers can render visuals without coupling
+ core types to display concerns.
+
+`transport` picks the wire format:
+
+- `"sse"` (default) — legacy SSE-over-GET transport (`sse_client`).
+- `"streamable_http"` — newer SSE-over-POST transport
+ (`streamablehttp_client`).
+
+Each returned tool's execute method invokes `tools/call` against a
+fresh session — v1 simplicity, no pooling. The session is opened over
+the same transport that was used for discovery, so the call path
+cannot accidentally regress to the wrong wire format.
+
+The transport's own timeout bounds the connection; we additionally
+wrap initialize/list/call awaits in `asyncio.wait_for` so a server
+that accepts the connection but stalls on protocol messages still
+aborts.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/http_loader.py#L112)
+
+
+### load_mcp_tools_stdio {#load-mcp-tools-stdio}
+
+_function_
+
+```python
+load_mcp_tools_stdio(command: str, args: list[str], *, env: dict[str, str] | None = None, cwd: str | None = None, timeout: float = 30.0) -> MCPDiscoveryResult
+```
+
+Spawn a stdio MCP server subprocess and discover its tools + metadata.
+
+Returns a [`MCPDiscoveryResult`](./cubepi-mcp#mcpdiscoveryresult) with the same shape as
+[`load_mcp_tools_http`](./cubepi-mcp#load-mcp-tools-http): `tools` (executable AgentTools),
+`server` (Implementation info from `initialize`), and `tool_infos`
+(per-tool display metadata such as icons).
+
+Each returned tool's execute opens a fresh subprocess per call (v1
+simplicity, no process pooling).
+
+
+**Args**
+
+- `command` — executable to run (e.g. "npx" or sys.executable)
+- `args` — argv for the server process
+- `env` — environment variables (passed to subprocess)
+- `cwd` — working directory for the subprocess
+- `timeout` — per-call wall-clock timeout for initialize/list/call awaits.
+ A hung server raises asyncio.TimeoutError instead of blocking forever.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/stdio_loader.py#L16)
+
+
+### MCPDiscoveryResult {#mcpdiscoveryresult}
+
+_class_
+
+```python
+MCPDiscoveryResult(self, tools: list[AgentTool], server: MCPServerInfo | None = None, tool_infos: list[MCPToolInfo] = list())
+```
+
+Outcome of an MCP discovery handshake.
+
+`tools` is the executable surface (one `AgentTool` per tool the
+server exposes). `server` and `tool_infos` are display metadata
+captured from the same handshake; both follow MCP spec rev 2025-11-25.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/types.py#L56)
+
+
+**Attributes**
+
+- `tools`: `list[AgentTool]`
+- `server`: `MCPServerInfo | None`
+- `tool_infos`: `list[MCPToolInfo]`
+
+
+### MCPIcon {#mcpicon}
+
+_class_
+
+```python
+MCPIcon(self, src: str, mime_type: str | None = None, sizes: tuple[str, ...] | None = None, theme: str | None = None)
+```
+
+One icon entry from an MCP `Icon` block.
+
+Mirrors `mcp.types.Icon` with snake_case fields. `src` is either an
+HTTP/HTTPS URL or a `data:` URI; `sizes` is a tuple of strings such
+as `("48x48", "96x96")`. `theme` is `"light"` or `"dark"` when
+the server supplies separate variants — the spec lets clients pick the
+variant matching the current UI theme and fall back to the first entry
+otherwise.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/types.py#L10)
+
+
+**Attributes**
+
+- `src`: `str`
+- `mime_type`: `str | None`
+- `sizes`: `tuple[str, ...] | None`
+- `theme`: `str | None`
+
+
+### MCPServerInfo {#mcpserverinfo}
+
+_class_
+
+```python
+MCPServerInfo(self, name: str, version: str, website_url: str | None = None, icons: tuple[MCPIcon, ...] = ())
+```
+
+Server-level metadata captured from the `initialize` handshake.
+
+Sourced from `InitializeResult.serverInfo` (an `Implementation`):
+the server's display name + version, an optional website URL, and an
+optional list of icons that clients can render as the server's logo.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/types.py#L28)
+
+
+**Attributes**
+
+- `name`: `str`
+- `version`: `str`
+- `website_url`: `str | None`
+- `icons`: `tuple[MCPIcon, ...]`
+
+
+### MCPToolInfo {#mcptoolinfo}
+
+_class_
+
+```python
+MCPToolInfo(self, name: str, icons: tuple[MCPIcon, ...] = ())
+```
+
+Per-tool display metadata captured from `tools/list`.
+
+Carries `Tool.icons` separately from the executable `AgentTool` so
+consumers can render tool-specific icons without coupling cubepi's
+core `AgentTool` type to MCP display concerns.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/mcp/types.py#L43)
+
+
+**Attributes**
+
+- `name`: `str`
+- `icons`: `tuple[MCPIcon, ...]`
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-middleware.mdx b/website/versioned_docs/version-0.6/api/cubepi-middleware.mdx
new file mode 100644
index 0000000..f442a1e
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-middleware.mdx
@@ -0,0 +1,121 @@
+---
+id: cubepi-middleware
+title: cubepi.middleware
+sidebar_position: 4
+hide_table_of_contents: false
+---
+
+# `cubepi.middleware`
+
+### Middleware {#middleware}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L24)
+
+
+**Methods**
+
+#### `transform_context` {#middleware-transform-context}
+
+```python
+transform_context(messages: list, *, signal = None) -> list
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L25)
+
+
+#### `convert_to_llm` {#middleware-convert-to-llm}
+
+```python
+convert_to_llm(messages: list) -> list
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L28)
+
+
+#### `before_tool_call` {#middleware-before-tool-call}
+
+```python
+before_tool_call(ctx: Any, *, signal = None) -> Any
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L31)
+
+
+#### `after_tool_call` {#middleware-after-tool-call}
+
+```python
+after_tool_call(ctx: Any, *, signal = None) -> Any
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L34)
+
+
+#### `transform_system_prompt` {#middleware-transform-system-prompt}
+
+```python
+transform_system_prompt(system_prompt: str, *, signal = None) -> str
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L37)
+
+
+#### `should_stop_after_turn` {#middleware-should-stop-after-turn}
+
+```python
+should_stop_after_turn(ctx: Any) -> bool
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L45)
+
+
+#### `after_model_response` {#middleware-after-model-response}
+
+```python
+after_model_response(response: AssistantMessage, ctx: Any, *, signal: Any = None) -> TurnAction | None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L48)
+
+
+
+### TurnAction {#turnaction}
+
+_class_
+
+```python
+TurnAction(self, response: AssistantMessage | None = None, inject_messages: list[Message] = list(), decision: Literal['natural', 'stop', 'loop_to_model'] = 'natural')
+```
+
+Directs the agent loop's next step after a model response.
+
+Composition (chain): each middleware sees previous middleware's
+TurnAction. Last middleware's value wins for response and decision.
+inject_messages concatenates across the chain.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L10)
+
+
+**Attributes**
+
+- `response`: `AssistantMessage | None`
+- `inject_messages`: `list[Message]`
+- `decision`: `Literal['natural', 'stop', 'loop_to_model']`
+
+
+### compose_middleware {#compose-middleware}
+
+_function_
+
+```python
+compose_middleware(middlewares: list[Middleware]) -> dict[str, Callable]
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/middleware/base.py#L64)
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-providers.mdx b/website/versioned_docs/version-0.6/api/cubepi-providers.mdx
new file mode 100644
index 0000000..0ab2f01
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-providers.mdx
@@ -0,0 +1,739 @@
+---
+id: cubepi-providers
+title: cubepi.providers
+sidebar_position: 2
+hide_table_of_contents: false
+---
+
+# `cubepi.providers`
+
+### AssistantMessage {#assistantmessage}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L124)
+
+
+**Attributes**
+
+- `role`: `Literal['assistant']`
+- `content`: `list[Content | ThinkingContent | ToolCall]`
+- `stop_reason`: `str`
+- `error_message`: `str | None`
+- `usage`: `Usage | None`
+- `timestamp`: `float | None`
+- `provider_id`: `str`
+- `model_id`: `str`
+- `response_id`: `str | None`
+- `metadata`: `dict[str, Any]`
+
+
+### BaseProvider {#baseprovider}
+
+_class_
+
+```python
+BaseProvider(self)
+```
+
+Concrete base class for built-in cubepi providers.
+
+Built-in providers (Anthropic, OpenAI, OpenAI Responses, Faux) inherit
+from this class to gain the persistent listener registry used by
+`cubepi.tracing` and other observers. User-defined providers may also
+inherit from `BaseProvider` to opt in, or remain duck-typed against
+the `Provider` Protocol (which only requires `stream()`).
+
+Concrete subclasses must implement `stream()` and call
+`_fire_listeners` at three points: after the request payload is
+finalized, for each `StreamEvent` pushed onto the stream, and exactly
+once in a `finally` block after the stream terminates.
+
+Per-call mutators (`StreamOptions.on_payload`,
+`StreamOptions.on_response`) retain their existing single-slot
+semantics and fire independently of the persistent listener registry
+below.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L581)
+
+
+**Methods**
+
+#### `stream` {#baseprovider-stream}
+
+```python
+stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, options: StreamOptions | None = None) -> MessageStream
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L606)
+
+
+#### `subscribe_request` {#baseprovider-subscribe-request}
+
+```python
+subscribe_request(cb: OnRequestCallback) -> Callable[[], None]
+```
+
+Register a persistent observer for request payloads.
+
+Returns a detach callable that removes this specific subscription.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L625)
+
+
+#### `subscribe_chunk` {#baseprovider-subscribe-chunk}
+
+```python
+subscribe_chunk(cb: OnChunkCallback) -> Callable[[], None]
+```
+
+Register a persistent observer for stream chunks.
+
+Returns a detach callable.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L633)
+
+
+#### `subscribe_response` {#baseprovider-subscribe-response}
+
+```python
+subscribe_response(cb: OnResponseBodyCallback) -> Callable[[], None]
+```
+
+Register a persistent observer for assembled responses.
+
+Returns a detach callable.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L641)
+
+
+
+### Content {#content}
+
+_attribute_
+
+```python
+Content = TextContent | ImageContent
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L107)
+
+
+### ImageContent {#imagecontent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L96)
+
+
+**Attributes**
+
+- `type`: `Literal['image']`
+- `source`: `str`
+- `media_type`: `str`
+
+
+### Message {#message}
+
+_attribute_
+
+```python
+Message = UserMessage | AssistantMessage | ToolResultMessage
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L148)
+
+
+### MessageStream {#messagestream}
+
+_class_
+
+```python
+MessageStream(self)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L209)
+
+
+**Methods**
+
+#### `attach_task` {#messagestream-attach-task}
+
+```python
+attach_task(task: asyncio.Task) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L217)
+
+
+#### `push` {#messagestream-push}
+
+```python
+push(event: StreamEvent) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L229)
+
+
+#### `set_result` {#messagestream-set-result}
+
+```python
+set_result(message: AssistantMessage) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L234)
+
+
+#### `result` {#messagestream-result}
+
+```python
+result() -> AssistantMessage
+```
+
+Return the final assistant message.
+
+Blocks not just on the result future, but also on the producer
+task's completion — the producer's `finally` block runs
+`_fire_response_listeners` (after `set_result`), so
+without waiting for the task, callers under `asyncio.run`
+teardown could exit before async response listeners have run.
+Producer exceptions are NOT re-raised here; they were already
+surfaced via the result future or the stream's error events.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L247)
+
+
+
+### Model {#model}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L79)
+
+
+**Attributes**
+
+- `id`: `str`
+- `provider`: `str`
+- `api`: `str`
+- `reasoning`: `bool`
+- `context_window`: `int`
+- `max_tokens`: `int`
+- `temperature`: `float`
+- `cost`: `ModelCost | None`
+- `thinking_level_map`: `dict[str, str | None] | None`
+
+
+### ModelCost {#modelcost}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L65)
+
+
+**Attributes**
+
+- `input`: `float`
+- `output`: `float`
+- `cache_read`: `float`
+- `cache_write`: `float`
+
+
+### OnChunkCallback {#onchunkcallback}
+
+_attribute_
+
+```python
+OnChunkCallback = Callable[['StreamEvent', Model], Awaitable[None] | None]
+```
+
+Persistent observer. Fires for every StreamEvent pushed onto the stream
+(start, text_delta, thinking_delta, toolcall_delta, done, error, ...).
+Heavy listeners should early-return on irrelevant event types — this hook
+fires hot. Return value is ignored.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L301)
+
+
+### OnPayloadCallback {#onpayloadcallback}
+
+_attribute_
+
+```python
+OnPayloadCallback = Callable[[dict, Model], Awaitable[dict | None] | dict | None]
+```
+
+Optional callback for inspecting/replacing provider payloads before sending.
+Return a dict to replace the payload, or None to keep unchanged.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L288)
+
+
+### OnRequestCallback {#onrequestcallback}
+
+_attribute_
+
+```python
+OnRequestCallback = Callable[[dict, Model], Awaitable[None] | None]
+```
+
+Persistent observer. Fires just before HTTP send, after any per-call
+`StreamOptions.on_payload` mutation has been applied. Receives the final
+wire payload dict and the Model. Return value is ignored.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L296)
+
+
+### OnResponseBodyCallback {#onresponsebodycallback}
+
+_attribute_
+
+```python
+OnResponseBodyCallback = Callable[[dict | None, Model, BaseException | None], Awaitable[None] | None]
+```
+
+Persistent observer. Fires exactly once per `stream()` call, in a
+finally block, after the stream terminates.
+
+- body: assembled provider response as a dict (same shape a non-streaming
+ call to the provider would have returned), or None if the stream failed
+ before a response could be assembled.
+- exc: the exception that ended the stream (including
+ `asyncio.CancelledError`), or None on normal completion.
+Return value is ignored.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L307)
+
+
+### OnResponseCallback {#onresponsecallback}
+
+_attribute_
+
+```python
+OnResponseCallback = Callable[['ProviderResponse', Model], Awaitable[None] | None]
+```
+
+Optional callback invoked after an HTTP response is received.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L292)
+
+
+### Provider {#provider}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L568)
+
+
+**Methods**
+
+#### `stream` {#provider-stream}
+
+```python
+stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, options: StreamOptions | None = None) -> MessageStream
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L570)
+
+
+
+### ProviderResponse {#providerresponse}
+
+_class_
+
+```python
+ProviderResponse(self, status: int, headers: dict[str, str] = dict())
+```
+
+HTTP response metadata exposed to on_response callbacks.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L280)
+
+
+**Attributes**
+
+- `status`: `int`
+- `headers`: `dict[str, str]`
+
+
+### StreamEvent {#streamevent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L157)
+
+
+**Attributes**
+
+- `type`: `Literal['start', 'text_start', 'text_delta', 'text_end', 'thinking_start', 'thinking_delta', 'thinking_end', 'toolcall_start', 'toolcall_delta', 'toolcall_end', 'done', 'error']`
+- `content_index`: `int | None`
+- `delta`: `str | None`
+- `partial`: `AssistantMessage | None`
+- `error_message`: `str | None`
+
+
+### StreamOptions {#streamoptions}
+
+_class_
+
+Options bag for Provider.stream(), transparent to the agent loop.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L529)
+
+
+**Attributes**
+
+- `model_config`
+- `thinking`: `ThinkingLevel`
+- `thinking_budgets`: `ThinkingBudgets | None`
+- `signal`: `asyncio.Event | None`
+- `on_payload`: `OnPayloadCallback | None`
+- `on_response`: `OnResponseCallback | None`
+
+
+### TextContent {#textcontent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L91)
+
+
+**Attributes**
+
+- `type`: `Literal['text']`
+- `text`: `str`
+
+
+### ThinkingBudgets {#thinkingbudgets}
+
+_class_
+
+Token budgets for each thinking level.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L22)
+
+
+**Attributes**
+
+- `minimal`: `int`
+- `low`: `int`
+- `medium`: `int`
+- `high`: `int`
+
+
+### ThinkingContent {#thinkingcontent}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L102)
+
+
+**Attributes**
+
+- `type`: `Literal['thinking']`
+- `thinking`: `str`
+
+
+### ThinkingLevel {#thinkinglevel}
+
+_attribute_
+
+```python
+ThinkingLevel = Literal['off', 'minimal', 'low', 'medium', 'high', 'xhigh']
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L19)
+
+
+### ToolCall {#toolcall}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L110)
+
+
+**Attributes**
+
+- `type`: `Literal['tool_call']`
+- `id`: `str`
+- `name`: `str`
+- `arguments`: `dict[str, Any]`
+
+
+### ToolDefinition {#tooldefinition}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L151)
+
+
+**Attributes**
+
+- `name`: `str`
+- `description`: `str`
+- `parameters`: `dict[str, Any]`
+
+
+### ToolResultMessage {#toolresultmessage}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L137)
+
+
+**Attributes**
+
+- `role`: `Literal['tool_result']`
+- `tool_call_id`: `str`
+- `tool_name`: `str`
+- `content`: `list[Content]`
+- `details`: `Any`
+- `is_error`: `bool`
+- `timestamp`: `float | None`
+- `metadata`: `dict[str, Any]`
+
+
+### Usage {#usage}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L72)
+
+
+**Attributes**
+
+- `input_tokens`: `int`
+- `output_tokens`: `int`
+- `cache_read_tokens`: `int`
+- `cache_write_tokens`: `int`
+
+
+### UserMessage {#usermessage}
+
+_class_
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L117)
+
+
+**Attributes**
+
+- `role`: `Literal['user']`
+- `content`: `list[Content]`
+- `timestamp`: `float | None`
+- `metadata`: `dict[str, Any]`
+
+
+### adjust_max_tokens_for_thinking {#adjust-max-tokens-for-thinking}
+
+_function_
+
+```python
+adjust_max_tokens_for_thinking(base_max_tokens: int, model_max_tokens: int, reasoning_level: ThinkingLevel, custom_budgets: ThinkingBudgets | None = None) -> tuple[int, int]
+```
+
+Adjust max_tokens to reserve space for a thinking budget.
+
+Given a base max_tokens (the desired output capacity), increases it to
+accommodate the thinking budget while respecting the model's hard cap.
+If the model cap is too small to fit both, the thinking budget is reduced
+to leave at least `min_output_tokens` (1024) for output.
+
+
+**Returns**
+
+- A `(max_tokens, thinking_budget)` tuple.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/base.py#L31)
+
+
+### FauxProvider {#fauxprovider}
+
+_class_
+
+```python
+FauxProvider(self, *, tokens_per_second: float | None = None, token_size_min: int = 3, token_size_max: int = 5)
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L155)
+
+
+**Attributes**
+
+- `call_count`
+- `pending_response_count`: `int`
+- `prompt_cache`: `dict[str, str]` — Read-only access to the prompt cache for test assertions.
+
+
+**Methods**
+
+#### `set_responses` {#fauxprovider-set-responses}
+
+```python
+set_responses(responses: list[FauxResponseStep]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L213)
+
+
+#### `append_responses` {#fauxprovider-append-responses}
+
+```python
+append_responses(responses: list[FauxResponseStep]) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L216)
+
+
+#### `clear_prompt_cache` {#fauxprovider-clear-prompt-cache}
+
+```python
+clear_prompt_cache() -> None
+```
+
+Clear the prompt cache, useful between test scenarios.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L223)
+
+
+#### `stream` {#fauxprovider-stream}
+
+```python
+stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, options: StreamOptions | None = None) -> MessageStream
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L265)
+
+
+
+### faux_assistant_message {#faux-assistant-message}
+
+_function_
+
+```python
+faux_assistant_message(content: str | FauxContentBlock | list[FauxContentBlock], *, stop_reason: str = 'stop', error_message: str | None = None) -> AssistantMessage
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L63)
+
+
+### faux_text {#faux-text}
+
+_function_
+
+```python
+faux_text(text: str) -> TextContent
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L46)
+
+
+### faux_thinking {#faux-thinking}
+
+_function_
+
+```python
+faux_thinking(thinking: str) -> ThinkingContent
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L50)
+
+
+### faux_tool_call {#faux-tool-call}
+
+_function_
+
+```python
+faux_tool_call(name: str, arguments: dict[str, Any], *, id: str | None = None) -> ToolCall
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/faux.py#L54)
+
+
+### THINKING_LEVELS {#thinking-levels}
+
+_attribute_
+
+```python
+THINKING_LEVELS: list[ThinkingLevel] = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh']
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/models.py#L12)
+
+
+### clamp_thinking_level {#clamp-thinking-level}
+
+_function_
+
+```python
+clamp_thinking_level(model: Model, level: ThinkingLevel) -> ThinkingLevel
+```
+
+Clamp *level* to the nearest supported level for *model*.
+
+If *level* is already supported, return it unchanged. Otherwise search
+upward first (higher intensity), then downward, through the ordered level
+list to find the closest available level.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/models.py#L54)
+
+
+### get_supported_thinking_levels {#get-supported-thinking-levels}
+
+_function_
+
+```python
+get_supported_thinking_levels(model: Model) -> list[ThinkingLevel]
+```
+
+Return the thinking levels supported by *model*.
+
+* Non-reasoning models only support `["off"]`.
+* For reasoning models, levels are filtered through the model's
+ `thinking_level_map`. A level mapped to `None` is unsupported.
+ `"xhigh"` is only included when it has an explicit (non-None) mapping.
+ All other levels are included by default when the map omits them.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/models.py#L22)
+
+
+### models_are_equal {#models-are-equal}
+
+_function_
+
+```python
+models_are_equal(a: Model | None, b: Model | None) -> bool
+```
+
+Return `True` if *a* and *b* refer to the same model.
+
+Comparison is by `id` and `provider`. Returns `False` when either
+argument is `None`.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/providers/models.py#L87)
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-tracing.mdx b/website/versioned_docs/version-0.6/api/cubepi-tracing.mdx
new file mode 100644
index 0000000..fae2121
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-tracing.mdx
@@ -0,0 +1,395 @@
+---
+id: cubepi-tracing
+title: cubepi.tracing
+sidebar_position: 6
+hide_table_of_contents: false
+---
+
+# `cubepi.tracing`
+
+### tracing_context {#tracing-context}
+
+_function_
+
+```python
+tracing_context(*, tags: list[str] | tuple[str, ...] | None = None, metadata: dict[str, Any] | None = None) -> Iterator[None]
+```
+
+Scope tags / metadata onto agent runs started inside this block.
+
+The recorder reads these contextvars on `AgentStartEvent` and
+stamps them on the `invoke_agent` span as:
+
+- `cubepi.tags` — tuple of strings (OTel attribute type)
+- one attribute per metadata key, namespaced under
+ `cubepi.metadata.*` (e.g. `metadata=\{"user_id": "u-42"\}` →
+ `cubepi.metadata.user_id = "u-42"`). The dedicated
+ sub-namespace keeps recorder-owned schema keys
+ (`cubepi.run_id`, `cubepi.turn.index`, …) safe from
+ caller-supplied collisions.
+
+The contextvar nature means this works for concurrent agents:
+each asyncio task tree gets its own value. Nested blocks merge
+additively (tags concatenate; metadata is union with inner
+keys winning).
+
+
+**Args**
+
+- `tags` — Tags to apply to runs started in this scope. Stored as
+ a tuple on the span so it round-trips through OTel's
+ attribute serializer.
+- `metadata` — Per-run key/value pairs. Values must be types that
+ OTel attributes accept (str, bool, int, float, or a
+ tuple/list of those); other shapes will be silently
+ dropped by the recorder.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/context.py#L51)
+
+
+### JsonlSpanExporter {#jsonlspanexporter}
+
+_class_
+
+```python
+JsonlSpanExporter(self, directory: str | os.PathLike[str] = './cubepi-traces')
+```
+
+Write each ReadableSpan as one JSON line.
+
+Files: `<directory>/<YYYY-MM-DD>/<trace_id>.jsonl`, one file per trace
+so the parent run and any nested subagent runs (same trace_id, different
+`cubepi.run_id`) land together. The date used for the subdirectory is
+the span's start time (UTC). The `trace_id` is the span's 32-hex trace
+id; spans without a context fall back to `"unknown-trace"`.
+
+Permissions: files are created mode `0o600` (user-only).
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/exporters/jsonl.py#L23)
+
+
+**Methods**
+
+#### `export` {#jsonlspanexporter-export}
+
+```python
+export(spans: Sequence[ReadableSpan]) -> SpanExportResult
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/exporters/jsonl.py#L42)
+
+
+#### `shutdown` {#jsonlspanexporter-shutdown}
+
+```python
+shutdown() -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/exporters/jsonl.py#L69)
+
+
+#### `force_flush` {#jsonlspanexporter-force-flush}
+
+```python
+force_flush(timeout_millis: int = 30000) -> bool
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/exporters/jsonl.py#L72)
+
+
+
+### Meter {#meter}
+
+_class_
+
+```python
+Meter(self, *, resource: Resource | None = None, exporters: list[MetricExporter] | None = None, export_interval_millis: int = 60000)
+```
+
+Emit OTel GenAI histograms alongside the cubepi Tracer.
+
+Construct with a list of `MetricExporter` instances (e.g. the
+OTLP metric exporter); call `attach` to start emitting.
+
+Example:
+
+```python
+from cubepi.tracing import Tracer, Meter
+from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
+ OTLPMetricExporter,
+)
+
+tracer = Tracer(service_name="my-bot", exporters=[...])
+meter = Meter(
+ resource=tracer.resource,
+ exporters=[OTLPMetricExporter(endpoint="http://collector:4318/v1/metrics")],
+)
+tracer.attach(agent)
+meter.attach(agent)
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/meter.py#L71)
+
+
+**Attributes**
+
+- `otel_meter`: `Any` — The underlying `opentelemetry.metrics.Meter` — exposed so callers can register their own instruments.
+
+
+**Methods**
+
+#### `attach` {#meter-attach}
+
+```python
+attach(agent: 'Agent') -> Callable[[], None]
+```
+
+Subscribe to `agent` and start emitting metrics.
+
+Each `attach()` call gets its own `_MeterState` so
+multiple concurrent agents attached to the same Meter don't
+clobber each other's open-ns timestamps and attribute dicts
+(codex overall-review MAJOR — previously all state lived on
+the Meter instance, so a second agent's `provider_request`
+overwrote the first agent's `_chat_open_ns` / `_chat_attrs`
+before its response landed).
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/meter.py#L144)
+
+
+#### `force_flush` {#meter-force-flush}
+
+```python
+force_flush(timeout_seconds: float = 30.0) -> bool
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/meter.py#L194)
+
+
+#### `shutdown` {#meter-shutdown}
+
+```python
+shutdown(timeout_seconds: float = 30.0) -> None
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/meter.py#L197)
+
+
+#### `attached` {#meter-attached}
+
+```python
+attached(agent: 'Agent') -> AsyncIterator['Meter']
+```
+
+RAII wrapper around `attach`.
+
+`async with` enters by attaching the per-attach state, exits
+by calling the detach callable returned from `attach`.
+Mirrors [`Tracer.attached`](./cubepi-tracing#tracer-attached) — use both for the cleanest
+end-to-end shutdown:
+
+```python
+async with (
+ Tracer(...) as tracer,
+ Meter(resource=tracer.resource, ...) as meter,
+ tracer.attached(agent),
+ meter.attached(agent),
+):
+ await agent.prompt("...")
+# auto: detach both + shutdown both
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/meter.py#L204)
+
+
+
+### SCHEMA_URL {#schema-url}
+
+_attribute_
+
+```python
+SCHEMA_URL = 'https://opentelemetry.io/schemas/1.41.0'
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/schema.py#L13)
+
+
+### Tracer {#tracer}
+
+_class_
+
+```python
+Tracer(self, *, service_name: str | None = None, service_version: str | None = None, service_namespace: str | None = None, service_instance_id: str | None = None, deployment_environment: str | None = None, agent_name: str | None = None, agent_id: str | None = None, agent_description: str | None = None, agent_version: str | None = None, exporters: list[SpanExporter] | None = None, record_content: bool = False, record_stream: bool = False, stream_dir: 'str | Path | None' = None, redact: 'Callable[[str, Any], Any] | None' = None, resource: Resource | None = None, atexit_flush: bool = True, atexit_flush_timeout_seconds: float = 5.0)
+```
+
+Attaches OTel-compatible tracing to a cubepi [`Agent`](./cubepi-agent#agent).
+
+Construct once per process (or per service). Each `attach(agent)`
+call wires the cubepi recorder to the agent's event stream and
+provider listener registry; the returned callable detaches.
+
+**Example**
+
+```python
+from cubepi.tracing import Tracer
+from cubepi.tracing.exporters import JsonlSpanExporter
+
+tracer = Tracer(
+ service_name="my-bot",
+ agent_name="coding-agent",
+ exporters=[JsonlSpanExporter(directory="./cubepi-traces")],
+)
+detach = tracer.attach(agent)
+try:
+ ...
+finally:
+ detach()
+ await tracer.shutdown()
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L35)
+
+
+**Attributes**
+
+- `resource`: `Resource`
+- `otel_tracer`: `Any` — The underlying `opentelemetry.trace.Tracer` instance.
+- `redact`: `'Callable[[str, Any], Any] | None'` — Optional `(key, value) -> value` filter applied at every `set_attribute` site for content attributes.
+
+
+**Methods**
+
+#### `attach` {#tracer-attach}
+
+```python
+attach(agent: 'Agent') -> Callable[[], Any]
+```
+
+Wire the cubepi recorder to `agent`.
+
+Returns a `detach()` callable. When invoked:
+
+- Synchronously: unsubscribes every hook, closes any spans
+ still open from a cancelled run, sweeps MCP tool-span
+ registrations — observable on the next line.
+- Schedules a flush on the running event loop and returns the
+ resulting `asyncio.Task` so callers can `await detach()`
+ to block until buffered spans have been exported. Outside
+ an async context returns `None` — call
+ `await tracer.shutdown()` separately to flush.
+
+Either `await detach()` or `await tracer.shutdown()` (or
+both) must be used in the caller's `finally` block; the
+synchronous `detach()` alone does not guarantee that ended
+spans have left `BatchSpanProcessor` (codex overall-review
+MAJOR).
+
+Also registers this Tracer's private TracerProvider with
+`cubepi.mcp._tracing` so MCP CLIENT spans flow through
+the same exporters — without this step, the MCP module falls
+back to the OTel global default (a no-op provider when the
+caller didn't separately call `trace.set_tracer_provider`).
+The detach callable unregisters.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L155)
+
+
+#### `force_flush` {#tracer-force-flush}
+
+```python
+force_flush(timeout_seconds: float = 30.0) -> bool
+```
+
+Block until all currently buffered spans are exported.
+
+Returns `False` on timeout.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L235)
+
+
+#### `shutdown` {#tracer-shutdown}
+
+```python
+shutdown(timeout_seconds: float = 30.0) -> None
+```
+
+Flush and close all exporters. Tracer is unusable after this.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L243)
+
+
+#### `attached` {#tracer-attached}
+
+```python
+attached(agent: 'Agent') -> AsyncIterator['Tracer']
+```
+
+RAII wrapper around `attach`.
+
+`async with` enters by attaching the recorder, exits by
+running detach and (in an async context) awaiting its returned
+flush `Task`. Equivalent to:
+
+```python
+detach = tracer.attach(agent)
+try:
+ ...
+finally:
+ result = detach()
+ if result is not None: # async context: it's a Task
+ await result
+```
+
+Use this instead of the bare `attach` / `finally: detach()`
+pattern when you want the cleanup tied to a single ``async
+with`` block. Combines with [`Tracer`](./cubepi-tracing#tracer)'s own context
+manager:
+
+```python
+async with Tracer(...) as tracer, tracer.attached(agent):
+ await agent.prompt("...")
+# auto: detach (closes cancelled spans) + shutdown (flush + close)
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L284)
+
+
+
+### trace {#trace}
+
+_function_
+
+```python
+trace(tracer: 'Tracer | None', agent: 'Agent') -> AsyncIterator[None]
+```
+
+Best-effort tracing scope for one agent run.
+
+Attaches `tracer` to `agent` on enter and detaches + flushes its
+buffered spans on exit. Every tracing fault — a failed attach, detach, or
+flush — is logged and swallowed, so tracing can never break or fail the
+work inside the `async with` block. Passing `tracer=None` makes the
+block a no-op, which lets callers gate tracing on config without branching
+at the call site.
+
+This does **not** shut the tracer down: the tracer is reusable across runs,
+so build it once (e.g. per process) and call `await tracer.shutdown()`
+when the owning process stops.
+
+Unlike [`Tracer.attached`](./cubepi-tracing#tracer-attached), which surfaces flush failures to the caller,
+this helper swallows them — use it when tracing is auxiliary to the work and
+must never affect its outcome.
+
+**Example**
+
+```python
+async with trace(tracer, agent):
+ await agent.prompt("...")
+```
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/tracing/tracer.py#L398)
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file
diff --git a/website/versioned_docs/version-0.6/api/cubepi-utils.mdx b/website/versioned_docs/version-0.6/api/cubepi-utils.mdx
new file mode 100644
index 0000000..ab9a121
--- /dev/null
+++ b/website/versioned_docs/version-0.6/api/cubepi-utils.mdx
@@ -0,0 +1,67 @@
+---
+id: cubepi-utils
+title: cubepi.utils
+sidebar_position: 7
+hide_table_of_contents: false
+---
+
+# `cubepi.utils`
+
+### emit_event {#emit-event}
+
+_function_
+
+```python
+emit_event(emit_fn: Callable, event: object) -> None
+```
+
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/utils/emit.py#L7)
+
+
+### parse_streaming_json {#parse-streaming-json}
+
+_function_
+
+```python
+parse_streaming_json(text: str | None) -> dict
+```
+
+Parse potentially incomplete or malformed JSON from streaming.
+
+Uses a 3-tier fallback:
+ 1. `json.loads(text)`
+ 2. `json.loads(repair_json(text))`
+ 3. Partial-parse: repair + close open braces/brackets/strings
+ 4. `\{\}` as last resort
+
+Always returns a *dict* (or at minimum `\{\}`) so callers never need
+to handle parse failures.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/utils/json_parse.py#L169)
+
+
+### repair_json {#repair-json}
+
+_function_
+
+```python
+repair_json(text: str) -> str
+```
+
+Repair malformed JSON string literals.
+
+Operates character-by-character, tracking whether the cursor is inside a
+JSON string value. Inside strings it:
+
+* Escapes raw control characters (0x00-0x1F) that are not already
+ escaped (`\t`, `\n`, `\r` are kept when already escaped).
+* Doubles a backslash before an invalid escape character
+ (e.g. `\x` becomes `\\x`), making the output parseable.
+* Handles truncated backslash at end-of-string.
+
+[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/.worktrees/2026-05-31-release-0.6.0/cubepi/utils/json_parse.py#L39)
+
+
+
+<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->
\ No newline at end of file