kaboo_workflows.converters¶
Stream converters that reshape agent events for external consumers.
kaboo_workflows.converters ¶
Stream converters for transforming StreamEvents into response formats.
StreamConverter ¶
Bases: ABC
Converts StreamEvent objects into protocol-specific output chunks.
Each converter is stateful across one completion stream (tracks message id, created timestamp, tool call index, etc.). Create a new instance per request — do not share across concurrent requests.
convert
abstractmethod
¶
convert(event)
Convert one StreamEvent into zero or more output chunks.
Returns a list (possibly empty) of serializable dicts. The transport layer is responsible for serializing and framing (e.g. 'data: {json}\n\n' for SSE). This method returns data shapes only — never pre-serialized strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
StreamEvent
|
The StreamEvent to convert. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A list of serializable dicts representing output chunks. |
Source code in src/kaboo_workflows/converters/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
done_marker
abstractmethod
¶
done_marker()
Terminal sentinel to emit after the stream ends.
E.g. 'data: [DONE]\n\n' for OpenAI SSE. Return empty string if the protocol needs no terminator.
Returns:
| Type | Description |
|---|---|
str
|
The terminal string to emit, or empty string if none. |
Source code in src/kaboo_workflows/converters/base.py
36 37 38 39 40 41 42 43 44 45 46 | |
content_type ¶
content_type()
MIME type for the HTTP streaming response.
Returns:
| Type | Description |
|---|---|
str
|
The MIME type string. |
Source code in src/kaboo_workflows/converters/base.py
48 49 50 51 52 53 54 | |
OpenAIStreamConverter ¶
OpenAIStreamConverter(
*,
entry_agent_name,
model_label=None,
completion_id=None,
reasoning_field_mode="both",
tool_result_render="details_block",
emit_usage_chunk=False,
verbosity="compact",
)
Bases: StreamConverter
Stateful converter from :class:~kaboo_workflows.wire.StreamEvent to OpenAI chat.completion.chunk dicts.
Targets Open WebUI and LibreChat. Translates strands events into the
OpenAI Chat Completions streaming protocol (v1) with reasoning extensions
from DeepSeek (reasoning_content) and OpenRouter (reasoning).
Single-use per stream. Call :meth:reset to reuse across requests.
Initialize the OpenAIStreamConverter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_agent_name
|
str
|
Name of the agent that owns the user-visible turn.
TOKEN and REASONING from all other agents are suppressed.
NODE_START/NODE_STOP from this agent surface sub-agents as
|
required |
model_label
|
str | None
|
Value for every chunk's |
None
|
completion_id
|
str | None
|
Fixed id for the whole stream. Defaults to a fresh
|
None
|
reasoning_field_mode
|
Literal['both', 'deepseek', 'openrouter', 'none']
|
Which
|
'both'
|
tool_result_render
|
Literal['details_block', 'none']
|
How tool calls and results are surfaced.
|
'details_block'
|
emit_usage_chunk
|
bool
|
When |
False
|
verbosity
|
Literal['compact', 'narrate']
|
|
'compact'
|
Source code in src/kaboo_workflows/converters/openai.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
convert ¶
convert(event)
Convert one :class:~kaboo_workflows.wire.StreamEvent into OpenAI chunk(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
StreamEvent
|
The event to convert. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A list of |
list[dict[str, Any]]
|
The transport layer is responsible for |
Source code in src/kaboo_workflows/converters/openai.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
done_marker ¶
done_marker()
Return the OpenAI SSE stream terminator.
Returns:
| Type | Description |
|---|---|
str
|
The |
Source code in src/kaboo_workflows/converters/openai.py
133 134 135 136 137 138 139 | |
reset ¶
reset()
Reset all mutable stream state for reuse across requests.
Preserves constructor configuration and regenerates completion_id
and created for the new stream.
Source code in src/kaboo_workflows/converters/openai.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
RawStreamConverter ¶
Bases: StreamConverter
Converts StreamEvents to raw JSON dicts (newline-delimited).
convert ¶
convert(event)
Pass through as dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
StreamEvent
|
The StreamEvent to convert. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A single-element list containing the event's dict representation. |
Source code in src/kaboo_workflows/converters/raw.py
14 15 16 17 18 19 20 21 22 23 | |
done_marker ¶
done_marker()
No terminator needed for raw streams.
Returns:
| Type | Description |
|---|---|
str
|
An empty string. |
Source code in src/kaboo_workflows/converters/raw.py
25 26 27 28 29 30 31 | |