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, thinking='')
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, llm_timeout=None)
¶
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
|
llm_timeout
|
int | float | None
|
Per-turn LLM invocation timeout in seconds. When
set, |
None
|
Source code in src/holodeck/chat/executor.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
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
514 515 516 517 518 519 520 521 522 523 524 | |
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
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
execute_turn_agui(input_data, message_override=None)
async
¶
Execute an AG-UI turn through a backend session that supports it.
Source code in src/holodeck/chat/executor.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
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
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
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
506 507 508 509 510 511 512 | |
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
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
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
157 158 159 160 161 162 163 | |
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
165 166 167 168 169 170 171 172 173 174 175 176 | |
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
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 122 123 124 | |
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
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 | |
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
178 179 180 181 182 183 184 185 186 187 188 189 | |
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 71 72 73 | |
terminate()
async
¶
Terminate the chat session.
Cleans up resources and transitions state to TERMINATED.
Source code in src/holodeck/chat/session.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
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 45 46 47 | |
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
49 50 51 52 53 54 55 56 57 58 59 | |
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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
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
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
set_active_snapshot(entries)
¶
Record the panel's view of tools that ran this turn.
Streaming responses don't surface tool_executions (they always
return []), so the verbose summary panel uses this snapshot
from :class:holodeck.chat.tools_panel.ToolsPanel instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Any
|
Iterable of objects exposing |
required |
Source code in src/holodeck/chat/progress.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |