base
code_context_agent.consumer.base ¶
Abstract base class for consuming agent streaming events.
This module defines the EventConsumer protocol that all consumers must implement. Consumers receive typed events from the AG-UI protocol and can render them in different ways (Rich terminal, JSON output, web UI, etc.).
EventConsumer ¶
Bases: ABC
Protocol for consuming agent streaming events.
Implement this interface to create custom event consumers for different output formats (Rich terminal, JSON, web UI, etc.).
The consumer receives typed AG-UI events and can render them appropriately. Events follow a lifecycle: run starts -> messages/tools -> run finishes.
Example
class LoggingConsumer(EventConsumer): ... async def on_run_started(self, thread_id: str, run_id: str) -> None: ... print(f"Run started: {run_id}")
on_run_started abstractmethod async ¶
Handle run started event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id | str | Unique identifier for the conversation thread. | required |
run_id | str | Unique identifier for this agent run. | required |
Source code in src/code_context_agent/consumer/base.py
on_text_start abstractmethod async ¶
Handle start of a text message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Unique identifier for the message. | required |
role | str | Message role (usually "assistant"). | required |
on_text_content abstractmethod async ¶
Handle streaming text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Identifier of the message being streamed. | required |
delta | str | New text chunk to append. | required |
on_text_end abstractmethod async ¶
Handle end of a text message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Identifier of the completed message. | required |
on_tool_start abstractmethod async ¶
Handle start of tool execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Unique identifier for this tool call. | required |
tool_name | str | Name of the tool being called. | required |
Source code in src/code_context_agent/consumer/base.py
on_tool_args abstractmethod async ¶
Handle streaming tool arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the tool call. | required |
args_delta | str | JSON string chunk of tool arguments. | required |
Source code in src/code_context_agent/consumer/base.py
on_tool_result abstractmethod async ¶
Handle tool execution result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the completed tool call. | required |
result | Any | Result returned by the tool. | required |
on_tool_end abstractmethod async ¶
Handle end of tool execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the completed tool call. | required |
on_state_snapshot abstractmethod async ¶
Handle state snapshot event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot | dict[str, Any] | Complete state snapshot dictionary. | required |
on_run_finished abstractmethod async ¶
Handle run finished event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id | str | Identifier of the conversation thread. | required |
run_id | str | Identifier of the completed run. | required |
Source code in src/code_context_agent/consumer/base.py
on_error abstractmethod async ¶
Handle error event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | Error message description. | required |
code | str | None | Optional error code. | None |
start async ¶
Initialize the consumer (optional).
Override to perform setup before events start streaming. Called before the first event is received.
stop async ¶
Cleanup the consumer (optional).
Override to perform cleanup after events stop streaming. Called after the last event is received or on error.