Serve (Agent Local Server)¶
The holodeck.serve package provides HTTP server functionality for exposing
HoloDeck agents via AG-UI (default) or REST protocols. It includes session
management, middleware, multimodal file handling, and protocol adapters.
Server¶
The main entry point. AgentServer wraps a FastAPI application and manages
the full server lifecycle -- initialization, request routing, session cleanup,
and graceful shutdown.
AgentServer(agent_config, protocol=ProtocolType.AG_UI, host='127.0.0.1', port=8000, cors_origins=None, debug=False, execution_config=None, observability_enabled=False)
¶
HTTP server for exposing a single HoloDeck agent.
The AgentServer wraps a FastAPI application and manages the server lifecycle, including session management and protocol handling.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_config |
The agent configuration to serve. |
|
protocol |
The protocol to use (AG-UI or REST). |
|
host |
The hostname to bind to. |
|
port |
The port to listen on. |
|
sessions |
The session store for managing conversations. |
|
state |
The current server state. |
Initialize the agent server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_config
|
Agent
|
The agent configuration to serve. |
required |
protocol
|
ProtocolType
|
The protocol to use (default: AG-UI). |
AG_UI
|
host
|
str
|
The hostname to bind to (default: 127.0.0.1 for security). Use 0.0.0.0 to expose to all network interfaces. |
'127.0.0.1'
|
port
|
int
|
The port to listen on (default: 8000). |
8000
|
cors_origins
|
list[str] | None
|
List of allowed CORS origins (default: ["*"]). |
None
|
debug
|
bool
|
Enable debug logging (default: False). |
False
|
execution_config
|
ExecutionConfig | None
|
Resolved execution configuration for timeouts. |
None
|
observability_enabled
|
bool
|
Enable OpenTelemetry per-request tracing. |
False
|
Source code in src/holodeck/serve/server.py
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
is_ready
property
¶
Check if the server is ready to accept requests.
uptime_seconds
property
¶
Return server uptime in seconds.
create_app()
¶
Create and configure the FastAPI application.
Returns:
| Type | Description |
|---|---|
FastAPI
|
Configured FastAPI application instance. |
Source code in src/holodeck/serve/server.py
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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
start()
async
¶
Start the server and begin accepting requests.
This method should be called after create_app() to transition the server to the RUNNING state. Also starts the background session cleanup task.
Source code in src/holodeck/serve/server.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
stop()
async
¶
Stop the server gracefully.
Transitions through SHUTTING_DOWN to STOPPED state, stopping the cleanup task and clearing all sessions.
Source code in src/holodeck/serve/server.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
Models¶
Pydantic request/response models shared across both AG-UI and REST protocols, plus health-check and error-response schemas.
ProtocolType¶
ProtocolType
¶
Bases: str, Enum
Protocol types supported by the Agent Local Server.
ServerState¶
ServerState
¶
Bases: str, Enum
Server lifecycle states.
FileContent¶
FileContent
¶
Bases: BaseModel
Binary file content for multimodal inputs.
Files are base64-encoded for JSON transport. Supported file types include images, PDFs, Office documents, and text files.
validate_mime_type(v)
classmethod
¶
Validate MIME type is supported.
Source code in src/holodeck/serve/models.py
65 66 67 68 69 70 71 | |
validate_base64(v)
classmethod
¶
Validate content is valid base64.
Source code in src/holodeck/serve/models.py
73 74 75 76 77 78 79 80 81 | |
ChatRequest¶
ChatRequest
¶
Bases: BaseModel
Request payload for chat endpoints.
Used by both synchronous and streaming chat endpoints in the REST protocol.
message_not_blank(v)
classmethod
¶
Validate message is not just whitespace.
Source code in src/holodeck/serve/models.py
106 107 108 109 110 111 112 | |
valid_ulid(v)
classmethod
¶
Validate session_id is valid ULID format if provided.
Source code in src/holodeck/serve/models.py
114 115 116 117 118 119 120 121 122 123 | |
ChatResponse¶
ChatResponse
¶
Bases: BaseModel
Response payload for synchronous chat endpoint.
Contains the agent's response, tool calls, and execution metadata.
valid_message_id_ulid(v)
classmethod
¶
Validate message_id is valid ULID format.
Source code in src/holodeck/serve/models.py
163 164 165 166 167 168 169 170 171 | |
valid_session_id_ulid(v)
classmethod
¶
Validate session_id is valid ULID format.
Source code in src/holodeck/serve/models.py
173 174 175 176 177 178 179 180 181 | |
ToolCallInfo¶
ToolCallInfo
¶
Bases: BaseModel
Tool execution information in response.
Contains details about a tool call made by the agent during message processing.
HealthResponse¶
HealthResponse
¶
Bases: BaseModel
Response for health check endpoints.
Provides server and agent status information.
ProblemDetail¶
ProblemDetail
¶
Bases: BaseModel
RFC 7807 Problem Details error response.
Standard format for HTTP API error responses.
SUPPORTED_MIME_TYPES¶
SUPPORTED_MIME_TYPES = {'image/png', 'image/jpeg', 'image/gif', 'image/webp', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'text/plain', 'text/csv', 'text/markdown'}
module-attribute
¶
Middleware¶
Cross-cutting concerns for the FastAPI application: structured logging with optional OpenTelemetry tracing, and RFC 7807 error handling.
LoggingMiddleware¶
LoggingMiddleware(app, debug=False, observability_enabled=False)
¶
Bases: BaseHTTPMiddleware
Middleware for request/response logging and tracing.
Captures request metadata including timestamp, endpoint, session ID, and latency for each request. When observability is enabled, creates per-request trace spans with HTTP attributes.
Initialize logging middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Callable
|
The ASGI application. |
required |
debug
|
bool
|
Enable verbose logging of full request/response content. |
False
|
observability_enabled
|
bool
|
Enable OpenTelemetry per-request tracing. |
False
|
Source code in src/holodeck/serve/middleware.py
36 37 38 39 40 41 42 43 44 45 46 47 48 | |
dispatch(request, call_next)
async
¶
Process request, log metadata, and create trace span if enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming HTTP request. |
required |
call_next
|
RequestCallNext
|
The next middleware/handler in the chain. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The HTTP response. |
Source code in src/holodeck/serve/middleware.py
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 101 102 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 | |
ErrorHandlingMiddleware¶
ErrorHandlingMiddleware(app, debug=False)
¶
Bases: BaseHTTPMiddleware
Middleware for standardized error handling.
Catches unhandled exceptions and returns RFC 7807 Problem Details formatted error responses.
Initialize error handling middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Callable
|
The ASGI application. |
required |
debug
|
bool
|
Include stack traces in error responses. |
False
|
Source code in src/holodeck/serve/middleware.py
159 160 161 162 163 164 165 166 167 | |
dispatch(request, call_next)
async
¶
Process request and handle errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming HTTP request. |
required |
call_next
|
RequestCallNext
|
The next middleware/handler in the chain. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The HTTP response, or an error response on exception. |
Source code in src/holodeck/serve/middleware.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
Session Store¶
In-memory session storage with TTL-based expiration. Sessions maintain
conversation context (via AgentExecutor) across multiple HTTP requests.
ServerSession¶
ServerSession(agent_executor, session_id=(lambda: str(ULID()))(), created_at=(lambda: datetime.now(timezone.utc))(), last_activity=(lambda: datetime.now(timezone.utc))(), message_count=0)
dataclass
¶
Individual conversation session with an agent.
Maintains state for a single conversation, including the agent executor instance that preserves conversation history.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Unique identifier in ULID format. |
agent_executor |
AgentExecutor
|
Agent execution context with conversation history. |
created_at |
datetime
|
UTC timestamp when session was created. |
last_activity |
datetime
|
UTC timestamp of last request in session. |
message_count |
int
|
Number of messages exchanged in session. |
SessionStore¶
SessionStore(ttl_seconds=1800, max_sessions=1000, cleanup_interval_seconds=300)
¶
In-memory session storage with TTL-based cleanup.
Manages conversation sessions for the Agent Local Server. Sessions expire after a configurable TTL period of inactivity. Includes optional automatic background cleanup and max session limits.
Attributes:
| Name | Type | Description |
|---|---|---|
sessions |
dict[str, ServerSession]
|
Dictionary mapping session IDs to ServerSession objects. |
ttl_seconds |
Time-to-live for sessions in seconds (default: 30 minutes). |
|
max_sessions |
Maximum number of sessions allowed (default: 1000). |
|
cleanup_interval_seconds |
Interval for automatic cleanup (default: 300). |
Initialize session store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ttl_seconds
|
int
|
Session timeout in seconds. Default is 1800 (30 minutes). |
1800
|
max_sessions
|
int
|
Maximum sessions before rejecting new ones. Default is 1000. |
1000
|
cleanup_interval_seconds
|
int
|
Interval for auto-cleanup. Default is 300 (5 min). |
300
|
Source code in src/holodeck/serve/session_store.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
active_count
property
¶
Return count of active sessions.
get(session_id)
¶
Retrieve a session by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session identifier to look up. |
required |
Returns:
| Type | Description |
|---|---|
ServerSession | None
|
The ServerSession if found, None otherwise. |
Source code in src/holodeck/serve/session_store.py
85 86 87 88 89 90 91 92 93 94 | |
get_all()
¶
Retrieve all active sessions.
Returns:
| Type | Description |
|---|---|
list[ServerSession]
|
List of all active ServerSession objects. |
Source code in src/holodeck/serve/session_store.py
96 97 98 99 100 101 102 | |
create(agent_executor, session_id=None)
¶
Create a new session with the given agent executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_executor
|
AgentExecutor
|
The AgentExecutor instance for this session. |
required |
session_id
|
str | None
|
Optional custom session ID. If not provided, a new ULID will be generated. Useful for mapping external IDs (like AG-UI thread_id) to sessions. |
None
|
Returns:
| Type | Description |
|---|---|
ServerSession
|
The newly created ServerSession. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If max_sessions limit is reached. |
ValueError
|
If session_id already exists. |
Source code in src/holodeck/serve/session_store.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 132 133 134 135 136 137 138 139 140 141 142 | |
delete(session_id)
async
¶
Delete a session by ID, shutting down its executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session identifier to delete. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if session was deleted, False if not found. |
Source code in src/holodeck/serve/session_store.py
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 | |
touch(session_id)
¶
Update the last_activity timestamp for a session.
This should be called on each request to prevent session expiration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session identifier to update. |
required |
Source code in src/holodeck/serve/session_store.py
177 178 179 180 181 182 183 184 185 186 187 | |
cleanup_expired()
async
¶
Remove all expired sessions, shutting down their executors.
Sessions are considered expired if their last_activity timestamp is older than the configured TTL.
Returns:
| Type | Description |
|---|---|
int
|
Number of sessions removed. |
Source code in src/holodeck/serve/session_store.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
start_cleanup_task()
async
¶
Start the background cleanup task.
This should be called when the server starts to enable automatic cleanup of expired sessions.
Source code in src/holodeck/serve/session_store.py
214 215 216 217 218 219 220 221 222 223 224 225 | |
stop_cleanup_task()
async
¶
Stop the background cleanup task.
This should be called when the server stops to cleanly terminate the background task.
Source code in src/holodeck/serve/session_store.py
227 228 229 230 231 232 233 234 235 236 237 238 | |
File Utilities¶
Shared utilities for multimodal content processing across REST and AG-UI protocols, including MIME-type mappings, temporary file management, and binary content extraction.
Constants¶
MAX_FILE_SIZE_MB = 50
module-attribute
¶
MAX_TOTAL_SIZE_MB = 100
module-attribute
¶
MIME_TO_FILE_TYPE = {'image/png': 'image', 'image/jpeg': 'image', 'image/gif': 'image', 'image/webp': 'image', 'application/pdf': 'pdf', _WORD_MIME: 'word', _EXCEL_MIME: 'excel', _PPTX_MIME: 'powerpoint', 'text/plain': 'text', 'text/csv': 'csv', 'text/markdown': 'text'}
module-attribute
¶
MIME_TO_EXTENSION = {'image/png': '.png', 'image/jpeg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp', 'application/pdf': '.pdf', _WORD_MIME: '.docx', _EXCEL_MIME: '.xlsx', _PPTX_MIME: '.pptx', 'text/plain': '.txt', 'text/csv': '.csv', 'text/markdown': '.md'}
module-attribute
¶
Functions¶
create_temp_file_from_bytes(content_bytes, mime_type, description=None)
¶
Create a temporary file from binary content and return FileInput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_bytes
|
bytes
|
Binary content to write to temp file. |
required |
mime_type
|
str
|
MIME type of the content. |
required |
description
|
str | None
|
Optional description (e.g., filename). |
None
|
Returns:
| Type | Description |
|---|---|
FileInput
|
FileInput suitable for FileProcessor.process_file(). |
Source code in src/holodeck/serve/file_utils.py
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 | |
convert_file_content_to_file_input(file_content)
¶
Convert REST FileContent (base64) to FileProcessor-compatible FileInput.
Creates a temporary file with the decoded content and returns a FileInput pointing to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_content
|
FileContent
|
FileContent with base64-encoded data and MIME type. |
required |
Returns:
| Type | Description |
|---|---|
FileInput
|
FileInput suitable for FileProcessor.process_file(). |
Source code in src/holodeck/serve/file_utils.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
convert_binary_dict_to_file_input(binary_content)
¶
Convert AG-UI binary content dict to FileProcessor-compatible FileInput.
Handles two transport options: - data: Inline base64-encoded content (supported) - url: Remote URL reference (NOT supported - SSRF security risk) - id: File ID reference (NOT supported)
Note: URL downloads are intentionally disabled to prevent SSRF attacks. Clients must provide file content inline as base64-encoded data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_content
|
dict[str, Any]
|
Dict with type, mimeType, and data field. |
required |
Returns:
| Type | Description |
|---|---|
FileInput | None
|
FileInput suitable for FileProcessor, or None if not processable. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If base64 decoding fails. |
Source code in src/holodeck/serve/file_utils.py
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 210 211 212 213 214 215 216 217 | |
cleanup_temp_file(file_input)
¶
Clean up temporary file created during file conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_input
|
FileInput
|
FileInput with path to temporary file. |
required |
Source code in src/holodeck/serve/file_utils.py
220 221 222 223 224 225 226 227 228 229 230 231 | |
cleanup_temp_files(file_inputs)
¶
Clean up multiple temporary files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_inputs
|
list[FileInput]
|
List of FileInput objects to clean up. |
required |
Source code in src/holodeck/serve/file_utils.py
234 235 236 237 238 239 240 241 | |
process_multimodal_files(files, execution_config=None, is_agui_format=False)
¶
Process multimodal files and return combined content with cleanup list.
This is the unified file processing function for both REST and AG-UI protocols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[FileContent] | list[dict[str, Any]]
|
List of FileContent objects (REST) or binary content dicts (AG-UI). |
required |
execution_config
|
ExecutionConfig | None
|
Optional execution configuration for FileProcessor. |
None
|
is_agui_format
|
bool
|
If True, treat files as AG-UI binary content dicts. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[str, list[FileInput]]
|
Tuple of (combined_markdown_content, list_of_file_inputs_for_cleanup). |
Source code in src/holodeck/serve/file_utils.py
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 280 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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
extract_binary_parts_from_content(content)
¶
Extract binary content parts from AG-UI message content list.
Filters the content list for binary type parts and validates MIME types. Handles both dict format and AG-UI Pydantic objects (BinaryInputContent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
list[dict[str, Any] | Any]
|
List of content parts (text, binary, or strings). |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of binary content dicts with type, mimeType, and data/url/id fields. |
Source code in src/holodeck/serve/file_utils.py
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 | |
Protocols¶
Base Protocol¶
Abstract base class that both AG-UI and REST protocol adapters implement.
Protocol
¶
Bases: ABC
Abstract base class for server protocols.
Both AG-UI and REST protocols implement this interface to handle incoming requests and stream responses back to clients.
name
abstractmethod
property
¶
Return the protocol name.
Returns:
| Type | Description |
|---|---|
str
|
Protocol identifier string (e.g., 'ag-ui', 'rest'). |
content_type
abstractmethod
property
¶
Return the content type for responses.
Returns:
| Type | Description |
|---|---|
str
|
MIME type string for response Content-Type header. |
handle_request(request, session)
abstractmethod
¶
Handle incoming request and yield response chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Any
|
The incoming request (format depends on protocol). |
required |
session
|
ServerSession
|
The server session for this request. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[bytes, None]
|
Response chunks as bytes for streaming to the client. |
Source code in src/holodeck/serve/protocols/base.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
REST Protocol¶
REST protocol adapter providing synchronous and streaming (SSE) chat endpoints, plus multipart file upload support.
RESTProtocol
¶
Bases: Protocol
REST protocol implementation with sync and streaming endpoints.
Handles: - Synchronous requests: handle_sync_request() → ChatResponse - Streaming requests: handle_request() → AsyncGenerator[bytes, None] (SSE)
name
property
¶
Return the protocol name.
Returns:
| Type | Description |
|---|---|
str
|
Protocol identifier string. |
content_type
property
¶
Return the content type for streaming responses.
Returns:
| Type | Description |
|---|---|
str
|
MIME type string for response Content-Type header. |
handle_request(request, session)
async
¶
Handle streaming request and generate SSE events.
Processes the ChatRequest, executes the agent, and yields encoded SSE events for streaming to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Any
|
ChatRequest from client. |
required |
session
|
ServerSession
|
Server session with AgentExecutor. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[bytes, None]
|
Encoded SSE events as bytes. |
Source code in src/holodeck/serve/protocols/rest.py
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 433 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 | |
handle_sync_request(request, session)
async
¶
Handle synchronous request and return complete response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatRequest
|
ChatRequest from client. |
required |
session
|
ServerSession
|
Server session with AgentExecutor. |
required |
Returns:
| Type | Description |
|---|---|
ChatResponse
|
ChatResponse with agent's response. |
Raises:
| Type | Description |
|---|---|
Exception
|
If agent execution fails. |
Source code in src/holodeck/serve/protocols/rest.py
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 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
process_files(files, execution_config=None)
async
¶
Process base64 files through FileProcessor and return combined text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[FileContent]
|
List of FileContent with base64-encoded data. |
required |
execution_config
|
ExecutionConfig | None
|
Optional execution configuration for timeouts. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Combined markdown content from all processed files. |
Source code in src/holodeck/serve/protocols/rest.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
SSEEvent
¶
SSE event serializer following sse-events.md specification.
Event format
event: {type} data: {json}
Keepalive format
: keepalive
format(event_type, data)
staticmethod
¶
Format an SSE event with type and JSON data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
The event type name. |
required |
data
|
dict[str, Any]
|
Dictionary to serialize as JSON data. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted string: "event: {type}\ndata: {json}\n\n" |
Source code in src/holodeck/serve/protocols/rest.py
65 66 67 68 69 70 71 72 73 74 75 76 77 | |
stream_start(session_id, message_id)
staticmethod
¶
Create stream_start event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Session identifier (ULID). |
required |
message_id
|
str
|
Message identifier (ULID). |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted stream_start event. |
Source code in src/holodeck/serve/protocols/rest.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
message_delta(delta, message_id)
staticmethod
¶
Create message_delta event with text chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
str
|
Text content chunk. |
required |
message_id
|
str
|
Message identifier for correlation. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted message_delta event. |
Source code in src/holodeck/serve/protocols/rest.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
tool_call_start(tool_call_id, name, message_id)
staticmethod
¶
Create tool_call_start event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Unique tool call identifier. |
required |
name
|
str
|
Tool name being called. |
required |
message_id
|
str
|
Parent message identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted tool_call_start event. |
Source code in src/holodeck/serve/protocols/rest.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
tool_call_args(tool_call_id, args_delta)
staticmethod
¶
Create tool_call_args event with argument fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Tool call identifier for correlation. |
required |
args_delta
|
str
|
JSON fragment of tool arguments. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted tool_call_args event. |
Source code in src/holodeck/serve/protocols/rest.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
tool_call_end(tool_call_id, status)
staticmethod
¶
Create tool_call_end event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Tool call identifier. |
required |
status
|
str
|
Execution status ("success" or "error"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted tool_call_end event. |
Source code in src/holodeck/serve/protocols/rest.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
stream_end(message_id, tokens_used, execution_time_ms)
staticmethod
¶
Create stream_end event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Message identifier. |
required |
tokens_used
|
dict[str, int] | None
|
Token consumption statistics (may be None). |
required |
execution_time_ms
|
int
|
Total execution time in milliseconds. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted stream_end event. |
Source code in src/holodeck/serve/protocols/rest.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
error(type, title, status, detail=None)
staticmethod
¶
Create error event following RFC 7807 ProblemDetail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Error type URI. |
required |
title
|
str
|
Short human-readable description. |
required |
status
|
int
|
HTTP status code. |
required |
detail
|
str | None
|
Detailed error message (optional). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
SSE formatted error event. |
Source code in src/holodeck/serve/protocols/rest.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
keepalive()
staticmethod
¶
Create keepalive comment.
Returns:
| Type | Description |
|---|---|
str
|
SSE comment format: ": keepalive\n" |
Source code in src/holodeck/serve/protocols/rest.py
229 230 231 232 233 234 235 236 | |
convert_upload_file_to_file_content(upload_file, content_bytes=None)
async
¶
Convert FastAPI UploadFile to FileContent model.
Reads the uploaded file content and encodes it as base64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upload_file
|
UploadFile
|
FastAPI UploadFile from multipart form-data. |
required |
content_bytes
|
bytes | None
|
Pre-read file content to avoid redundant I/O. If provided, the file won't be read again. |
None
|
Returns:
| Type | Description |
|---|---|
FileContent
|
FileContent with base64-encoded content. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If file content type is not supported. |
Source code in src/holodeck/serve/protocols/rest.py
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 280 281 | |
process_multipart_files(files)
async
¶
Process multipart file uploads and convert to FileContent list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[UploadFile]
|
List of FastAPI UploadFile objects. |
required |
Returns:
| Type | Description |
|---|---|
list[FileContent]
|
List of FileContent objects with base64-encoded content. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any file has unsupported MIME type or exceeds size limits. |
Source code in src/holodeck/serve/protocols/rest.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
AG-UI Protocol¶
AG-UI protocol adapter implementing the ag-ui-protocol event-driven streaming pattern for agent interaction.
AGUIProtocol(accept_header=None)
¶
Bases: Protocol
AG-UI protocol implementation.
Handles /awp endpoint requests, converting between AG-UI events and HoloDeck's AgentExecutor.
The AG-UI protocol follows an event-driven streaming pattern: 1. RunStartedEvent - Signals execution start 2. TextMessageStartEvent - Opens message stream 3. ToolCall* events - For any tool invocations 4. TextMessageContentEvent - Streams response text 5. TextMessageEndEvent - Closes message stream 6. RunFinishedEvent/RunErrorEvent - Signals completion
Initialize the AG-UI protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accept_header
|
str | None
|
HTTP Accept header for format negotiation. |
None
|
Source code in src/holodeck/serve/protocols/agui.py
583 584 585 586 587 588 589 | |
name
property
¶
Return the protocol name.
Returns:
| Type | Description |
|---|---|
str
|
Protocol identifier string. |
content_type
property
¶
Return the content type for responses.
Returns:
| Type | Description |
|---|---|
str
|
MIME type string for response Content-Type header. |
handle_request(request, session)
async
¶
Handle AG-UI request and generate event stream.
Processes the RunAgentInput, executes the agent, and yields encoded AG-UI events for streaming to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Any
|
RunAgentInput from client. |
required |
session
|
ServerSession
|
Server session with AgentExecutor. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[bytes, None]
|
Encoded AG-UI events as bytes. |
Source code in src/holodeck/serve/protocols/agui.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
AGUIEventStream(accept_header=None)
¶
Wrapper for AG-UI event encoding and streaming.
Handles format negotiation based on HTTP Accept header and encodes events for streaming to clients.
Initialize event stream with format negotiation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accept_header
|
str | None
|
HTTP Accept header for format selection. Defaults to text/event-stream (SSE). |
None
|
Source code in src/holodeck/serve/protocols/agui.py
246 247 248 249 250 251 252 253 254 | |
content_type
property
¶
Get the content type for the streaming response.
Returns:
| Type | Description |
|---|---|
str
|
MIME type string for response Content-Type header. |
encode(event)
¶
Encode a single AG-UI event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
BaseEvent
|
AG-UI event to encode. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded bytes for SSE or binary format. |
Source code in src/holodeck/serve/protocols/agui.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
Event Factory Functions¶
extract_message_and_files_from_input(input_data)
¶
Extract text message and binary content parts from RunAgentInput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
RunAgentInput
|
AG-UI input containing messages list. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, list[dict[str, Any]]]
|
Tuple of (text_message, binary_parts_list). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no user messages found. |
Source code in src/holodeck/serve/protocols/agui.py
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 101 102 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 | |
extract_message_from_input(input_data)
¶
Extract the last user message from RunAgentInput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
RunAgentInput
|
AG-UI input containing messages list. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text content of the last user message. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no user messages found. |
Source code in src/holodeck/serve/protocols/agui.py
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 | |
map_session_id(thread_id)
¶
Map AG-UI thread_id to HoloDeck session_id.
The thread_id from AG-UI is used directly as the session_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
AG-UI conversation thread identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Session ID (uses thread_id directly). |
Source code in src/holodeck/serve/protocols/agui.py
211 212 213 214 215 216 217 218 219 220 221 222 | |
generate_run_id()
¶
Generate a unique run ID for this request.
Returns:
| Type | Description |
|---|---|
str
|
New ULID string for the run. |
Source code in src/holodeck/serve/protocols/agui.py
225 226 227 228 229 230 231 | |
create_run_started_event(thread_id, run_id)
¶
Create RunStartedEvent for stream beginning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
Conversation thread identifier. |
required |
run_id
|
str
|
Unique run identifier. |
required |
Returns:
| Type | Description |
|---|---|
RunStartedEvent
|
RunStartedEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
create_run_finished_event(thread_id, run_id)
¶
Create RunFinishedEvent for successful completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
Conversation thread identifier. |
required |
run_id
|
str
|
Unique run identifier. |
required |
Returns:
| Type | Description |
|---|---|
RunFinishedEvent
|
RunFinishedEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
create_run_error_event(message, code=None)
¶
Create RunErrorEvent for failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message describing the failure. |
required |
code
|
str | None
|
Optional error code for categorization. |
None
|
Returns:
| Type | Description |
|---|---|
RunErrorEvent
|
RunErrorEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
create_text_message_start(message_id)
¶
Create TextMessageStartEvent to open message stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Unique message identifier. |
required |
Returns:
| Type | Description |
|---|---|
TextMessageStartEvent
|
TextMessageStartEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
create_text_message_content(message_id, delta)
¶
Create TextMessageContentEvent with text chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Message identifier for correlation. |
required |
delta
|
str
|
Text chunk to stream. |
required |
Returns:
| Type | Description |
|---|---|
TextMessageContentEvent
|
TextMessageContentEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
create_text_message_end(message_id)
¶
Create TextMessageEndEvent to close message stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Message identifier for correlation. |
required |
Returns:
| Type | Description |
|---|---|
TextMessageEndEvent
|
TextMessageEndEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
379 380 381 382 383 384 385 386 387 388 389 390 391 | |
create_tool_call_start(tool_call_id, tool_call_name, parent_message_id=None)
¶
Create ToolCallStartEvent to initiate tool execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Unique tool call identifier. |
required |
tool_call_name
|
str
|
Name of the tool being called. |
required |
parent_message_id
|
str | None
|
Optional parent message identifier. |
None
|
Returns:
| Type | Description |
|---|---|
ToolCallStartEvent
|
ToolCallStartEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
create_tool_call_args(tool_call_id, delta)
¶
Create ToolCallArgsEvent with argument fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Tool call identifier for correlation. |
required |
delta
|
str
|
JSON fragment of arguments. |
required |
Returns:
| Type | Description |
|---|---|
ToolCallArgsEvent
|
ToolCallArgsEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
create_tool_call_end(tool_call_id)
¶
Create ToolCallEndEvent to complete argument transmission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
|
str
|
Tool call identifier for correlation. |
required |
Returns:
| Type | Description |
|---|---|
ToolCallEndEvent
|
ToolCallEndEvent instance. |
Source code in src/holodeck/serve/protocols/agui.py
439 440 441 442 443 444 445 446 447 448 449 450 451 | |
create_tool_call_events(tool_execution, message_id)
¶
Create complete tool call event sequence from ToolExecution.
Each tool call is wrapped in its own assistant message so CopilotKit renders a separate card per tool invocation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_execution
|
ToolExecution
|
HoloDeck tool execution result. |
required |
message_id
|
str
|
Unused (kept for backward compatibility). |
required |
Returns:
| Type | Description |
|---|---|
list[BaseEvent]
|
List of AG-UI events for this tool call. |
Source code in src/holodeck/serve/protocols/agui.py
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 489 490 491 492 493 494 495 496 497 | |