Chat API Reference¶
The chat subsystem provides interactive, multi-turn conversation capabilities for HoloDeck agents. It coordinates message validation, agent execution via the provider-agnostic backend layer, streaming responses, tool execution progress tracking, and session lifecycle management.
Module: holodeck.chat.executor¶
Orchestrates agent execution for chat sessions using the backend abstraction
layer (AgentBackend / AgentSession). Supports both synchronous turn-based
and streaming response modes, with lazy backend initialization and optional
task-bound session wrapping for HTTP server contexts.
AgentResponse¶
AgentResponse(content, tool_executions, tokens_used, execution_time)
dataclass
¶
Response from agent execution.
Contains the agent's text response, any tool executions performed, token usage tracking, and execution timing information.
AgentExecutor¶
AgentExecutor(agent_config, backend=None, on_execution_start=None, on_execution_complete=None, release_transport_after_turn=False)
¶
Coordinates agent execution for chat sessions.
Uses the provider-agnostic AgentBackend/AgentSession abstractions to execute user messages and manage conversation history.
Initialize executor with agent configuration.
No I/O is performed during construction — backend and session
are lazily created on the first execute_turn() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_config
|
Agent
|
Agent configuration with model and instructions. |
required |
backend
|
AgentBackend | None
|
Optional pre-initialized backend (bypasses BackendSelector). |
None
|
on_execution_start
|
Callable[[str], None] | None
|
Optional callback before agent execution. |
None
|
on_execution_complete
|
Callable[[AgentResponse], None] | None
|
Optional callback after agent execution. |
None
|
release_transport_after_turn
|
bool
|
If True, wrap the backend session
in a |
False
|
Source code in src/holodeck/chat/executor.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
tool_event_queue
property
¶
The tool event queue from the underlying session, if available.
clear_history()
async
¶
Clear conversation history and close the current session.
Resets the agent's chat history to start fresh conversation.
The next execute_turn() will create a new session.
Source code in src/holodeck/chat/executor.py
315 316 317 318 319 320 321 322 323 324 325 | |
execute_turn(message)
async
¶
Execute a single turn of agent conversation.
Sends a user message to the agent, captures the response, extracts tool calls, and tracks token usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message to send to the agent. |
required |
Returns:
| Type | Description |
|---|---|
AgentResponse
|
AgentResponse with content, tool executions, tokens, and timing. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If agent execution fails. |
Source code in src/holodeck/chat/executor.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
execute_turn_streaming(message)
async
¶
Stream agent response token by token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message to send to the agent. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
Successive string chunks of the agent response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If agent execution fails. |
Source code in src/holodeck/chat/executor.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
get_history()
¶
Get current conversation history.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Serialized conversation history as a list of dicts, or empty list. |
Source code in src/holodeck/chat/executor.py
307 308 309 310 311 312 313 | |
shutdown()
async
¶
Cleanup executor resources.
Called when ending a chat session to release any held resources. Closes the session and tears down the backend.
Source code in src/holodeck/chat/executor.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
Module: holodeck.chat.message¶
Validates user messages before they reach the agent, enforcing content standards such as empty-message detection, size limits, control-character filtering, and UTF-8 validation.
MessageValidator¶
MessageValidator(max_length=10000)
¶
Validates user messages before sending to the agent.
Uses ValidationPipeline to enforce content standards including empty message detection, size limits, control character filtering, and UTF-8 validation.
Initialize validator with length constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_length
|
int
|
Maximum message length in characters. Defaults to 10,000. |
10000
|
Source code in src/holodeck/chat/message.py
16 17 18 19 20 21 22 | |
validate(message)
¶
Validate a message and return validation status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str | None
|
User message to validate (None, empty, or any content). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Tuple of (is_valid: bool, error_message: str | None). |
str | None
|
If valid, error_message is None. |
tuple[bool, str | None]
|
If invalid, error_message describes the validation failure. |
Validation checks: - Message is not None or empty - Message does not exceed max_length - Message contains no control characters - Message is valid UTF-8
Source code in src/holodeck/chat/message.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Module: holodeck.chat.session¶
Manages chat session lifecycle and state, coordinating between message validation, agent execution, token tracking, and session statistics.
ChatSessionManager¶
ChatSessionManager(agent_config, config)
¶
Maintains chat session lifecycle and state management.
Coordinates between message validation, agent execution, and session state tracking.
Initialize session manager with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_config
|
Agent
|
Agent configuration to use for execution. |
required |
config
|
ChatConfig
|
Chat runtime configuration. |
required |
Source code in src/holodeck/chat/session.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
get_session()
¶
Get current chat session.
Returns:
| Type | Description |
|---|---|
ChatSession | None
|
ChatSession instance, or None if not started. |
Source code in src/holodeck/chat/session.py
154 155 156 157 158 159 160 | |
get_session_stats()
¶
Get current session statistics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with message_count, total_tokens, and session_duration. |
Source code in src/holodeck/chat/session.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
process_message(message)
async
¶
Process a user message through validation and execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message to process. |
required |
Returns:
| Type | Description |
|---|---|
AgentResponse
|
AgentResponse from the agent. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If session not started or execution fails. |
ValueError
|
If message validation fails. |
Source code in src/holodeck/chat/session.py
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
process_message_streaming(message)
async
¶
Stream a user message through validation and agent execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message to process. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
Successive string chunks of the agent response. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If session not started or execution fails. |
ValueError
|
If message validation fails. |
Source code in src/holodeck/chat/session.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
should_warn_context_limit()
¶
Check if conversation is approaching context limit.
Returns:
| Type | Description |
|---|---|
bool
|
True if message count >= 80% of max_messages, False otherwise. |
Source code in src/holodeck/chat/session.py
175 176 177 178 179 180 181 182 183 184 185 186 | |
start()
async
¶
Start a new chat session.
Initializes the agent executor, creates a chat session, and transitions state to ACTIVE.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If session initialization fails. |
Source code in src/holodeck/chat/session.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
terminate()
async
¶
Terminate the chat session.
Cleans up resources and transitions state to TERMINATED.
Source code in src/holodeck/chat/session.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
Module: holodeck.chat.streaming¶
Streams tool execution events to callers in real time, allowing UIs to display progress as tools start, run, and complete (or fail).
ToolExecutionStream¶
ToolExecutionStream(verbose=False)
¶
Streams tool execution events to the caller.
Emits ToolEvent instances as a tool executes, allowing callers to display real-time progress. Supports both standard and verbose modes.
Initialize the stream with verbosity preference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
If True, include detailed execution data (parameters, results). If False, emit minimal data (tool name, status, timing). |
False
|
Source code in src/holodeck/chat/streaming.py
22 23 24 25 26 27 28 29 | |
stream_execution(tool_call)
async
¶
Stream execution events for a tool call.
Simulates the execution lifecycle by emitting events: 1. STARTED - Tool execution begins 2. PROGRESS - (optional, for long operations) 3. COMPLETED or FAILED - Execution finished
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call
|
ToolExecution
|
Tool execution with status and result data. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[ToolEvent]
|
ToolEvent instances representing execution progression. |
Source code in src/holodeck/chat/streaming.py
31 32 33 34 35 36 37 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 | |
ToolEvent and ToolEventType¶
ToolEvent and ToolEventType are re-exported from holodeck.models.tool_event.
See the Models API Reference for full documentation.
Module: holodeck.chat.progress¶
Tracks and displays chat session progress with animated spinners and adaptive status output (inline for default mode, rich panel for verbose mode).
ChatProgressIndicator¶
ChatProgressIndicator(max_messages, quiet, verbose)
¶
Bases: SpinnerMixin
Track and display chat session progress with spinner and status information.
Provides animated spinner during agent execution and adaptive status display (minimal in default mode, rich in verbose mode). Tracks message count, tokens, session time, response timing, and tool executions.
Inherits spinner animation from SpinnerMixin.
Initialize progress indicator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_messages
|
int
|
Maximum messages for session before warning. |
required |
quiet
|
bool
|
Suppress status display (spinner still shows). |
required |
verbose
|
bool
|
Show rich status panel instead of inline status. |
required |
Source code in src/holodeck/chat/progress.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
get_spinner_char()
¶
Get current spinner character and advance rotation.
Returns:
| Type | Description |
|---|---|
str
|
Current spinner character from the braille sequence. |
Source code in src/holodeck/lib/ui/spinner.py
36 37 38 39 40 41 42 43 44 | |
get_spinner_line()
¶
Get current spinner animation frame.
Returns:
| Type | Description |
|---|---|
str
|
Animated spinner text, or empty string if not TTY. |
Source code in src/holodeck/chat/progress.py
46 47 48 49 50 51 52 53 54 55 56 | |
get_status_inline()
¶
Get minimal inline status for default mode.
Format: [messages_current/messages_max | execution_time]
Returns:
| Type | Description |
|---|---|
str
|
Inline status string. |
Source code in src/holodeck/chat/progress.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
get_status_panel()
¶
Get rich status panel for verbose mode.
Returns:
| Type | Description |
|---|---|
str
|
Multi-line status panel string. |
Source code in src/holodeck/chat/progress.py
103 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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
update(response)
¶
Update progress after agent response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Any
|
AgentResponse object with execution_time, tokens_used, and tool_executions. |
required |
Source code in src/holodeck/chat/progress.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |