Backend Abstraction Layer¶
The backend abstraction layer provides a provider-agnostic interface for agent
execution. Downstream consumers (test runner, chat session, serve endpoint)
depend only on the protocols defined in holodeck.lib.backends.base -- no
provider-specific types leak through.
Routing¶
BackendSelector inspects model.provider and instantiates the correct
backend automatically:
| Provider | Backend |
|---|---|
openai, azure_openai |
OpenAIAgentsBackend |
anthropic, ollama |
ClaudeBackend |
holodeck.lib.backends.base -- Core Protocols & Data Classes¶
Defines the provider-agnostic contracts that every backend must satisfy and the unified result types returned to callers.
ExecutionResult¶
The unified result type returned by every backend. Fields: response,
tool_calls, tool_results, token_usage, structured_output, num_turns,
is_error, error_reason, and thinking (extended-thinking text, empty when
disabled or unsupported by the active backend).
ExecutionResult(response, tool_calls=list(), tool_results=list(), token_usage=TokenUsage.zero(), structured_output=None, num_turns=1, is_error=False, error_reason=None, thinking='')
dataclass
¶
Provider-agnostic result of a single agent turn.
Attributes:
| Name | Type | Description |
|---|---|---|
response |
str
|
The text response from the agent. |
tool_calls |
list[dict[str, Any]]
|
List of tool call records made during execution. |
tool_results |
list[dict[str, Any]]
|
List of tool result records returned during execution. |
token_usage |
TokenUsage
|
Token consumption metadata for this turn. |
structured_output |
Any | None
|
Optional structured output from the agent. |
num_turns |
int
|
Number of turns taken to produce this result. |
is_error |
bool
|
Whether the execution ended in an error state. |
error_reason |
str | None
|
Human-readable reason for the error, if any. |
thinking |
str
|
Extended-thinking text emitted by the model, concatenated in arrival order. Empty when extended thinking is disabled or unsupported by the backend. |
ToolEvent¶
ToolEvent(kind, tool_name, tool_use_id, tool_input=None, tool_response=None, error=None, parent_tool_use_id=None, text=None)
dataclass
¶
Real-time tool execution event from the backend.
Emitted by backends that support hook-based tool observation (e.g. Claude
Agent SDK). Events are pushed onto an asyncio.Queue that consumers
can drain concurrently during agent execution.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['start', 'end', 'error', 'subagent_message', 'parent_link', 'thinking']
|
Event type — |
tool_name |
str
|
Name of the tool being invoked. Empty for
|
tool_use_id |
str
|
Unique identifier correlating start/end/error for the
same invocation. For |
tool_input |
dict[str, Any] | None
|
Tool input parameters (present on |
tool_response |
str | None
|
Tool output (present on |
error |
str | None
|
Error description (present on |
parent_tool_use_id |
str | None
|
For nested events, the parent Task's
|
text |
str | None
|
Latest assistant text snapshot from a subagent (present on
|
AgentSession¶
AgentSession
¶
Bases: Protocol
Stateful multi-turn conversation session.
Implementations maintain conversation history across multiple send
calls. Callers must invoke close when the session is no longer needed
to release any held resources (connections, subprocesses, etc.).
close()
async
¶
Release session resources (connections, subprocesses, etc.).
Source code in src/holodeck/lib/backends/base.py
147 148 149 | |
prepare()
async
¶
Connect or otherwise ready the session before the first send.
Called by callers that need the session's underlying transport
opened in a specific async task context (e.g.
_TaskBoundSession requires the SDK's connect() to run in
the actor task so the anyio task group binds correctly).
Default behavior is a no-op. Implementations that have lazy
connect semantics — like ClaudeSession — should override
this to perform the connect explicitly. Implementations that
connect at construction time can leave this as a no-op.
Source code in src/holodeck/lib/backends/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
send(message)
async
¶
Send a message and receive a single-turn result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult containing the agent response and metadata. |
Source code in src/holodeck/lib/backends/base.py
124 125 126 127 128 129 130 131 132 133 | |
send_streaming(message)
async
¶
Send a message and stream the agent response token by token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
Successive string chunks of the agent response. |
Source code in src/holodeck/lib/backends/base.py
135 136 137 138 139 140 141 142 143 144 145 | |
AgentBackend¶
AgentBackend
¶
Bases: Protocol
Provider backend factory.
Each backend encapsulates provider-specific initialisation logic and
exposes a uniform surface for single-turn invocations (invoke_once)
and stateful sessions (create_session). Callers must call
initialize before any other method and teardown when done.
create_session(*, eager_connect=True)
async
¶
Create a new stateful multi-turn session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eager_connect
|
bool
|
When True (default), the backend may open its
underlying transport before returning. When False, the
backend must return a session whose transport is opened
lazily — typically by |
True
|
Returns:
| Type | Description |
|---|---|
AgentSession
|
A fresh AgentSession instance bound to this backend. |
Raises:
| Type | Description |
|---|---|
BackendInitError
|
If the backend was not initialised before calling. |
BackendSessionError
|
If the session cannot be created. |
Source code in src/holodeck/lib/backends/base.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
initialize()
async
¶
Prepare the backend for use.
Raises:
| Type | Description |
|---|---|
BackendInitError
|
If the backend cannot be initialised (e.g. missing API key, unavailable subprocess). |
Source code in src/holodeck/lib/backends/base.py
162 163 164 165 166 167 168 169 | |
invoke_once(message, context=None)
async
¶
Execute a single stateless agent turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
context
|
list[dict[str, Any]] | None
|
Optional list of prior conversation turns. |
None
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult containing the agent response and metadata. |
Raises:
| Type | Description |
|---|---|
BackendSessionError
|
If the invocation fails at runtime. |
BackendTimeoutError
|
If the invocation exceeds configured timeout. |
Source code in src/holodeck/lib/backends/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
teardown()
async
¶
Release all backend resources.
Source code in src/holodeck/lib/backends/base.py
214 215 216 | |
ContextGenerator¶
ContextGenerator
¶
Bases: Protocol
Backend-agnostic contextual embedding generation.
Implementations produce situating context for document chunks by summarising each chunk's role within the larger document. Both the existing Semantic Kernel generator and future Claude SDK generator should satisfy this protocol.
contextualize_batch(chunks, document_text, concurrency=None)
async
¶
Generate contextual descriptions for a batch of chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
list[DocumentChunk]
|
Document chunks to contextualize. |
required |
document_text
|
str
|
Full text of the source document. |
required |
concurrency
|
int | None
|
Maximum number of concurrent LLM calls. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of contextual description strings, one per chunk. |
Source code in src/holodeck/lib/backends/base.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
Exceptions¶
BackendError
¶
Bases: HoloDeckError
Base exception for all backend errors.
Catch this to handle any backend-related failure without needing to know the specific subtype.
BackendInitError
¶
Bases: BackendError
Raised during initialize() — startup validation failures.
Examples include a missing API key, an unreachable subprocess, or an incompatible runtime environment.
BackendSessionError
¶
Bases: BackendError
Raised during send() — session-level failures.
Examples include unexpected disconnections, malformed responses, or provider-reported errors during an active session.
BackendTimeoutError
¶
Bases: BackendError
Raised when a single invocation exceeds the configured timeout.
Callers may choose to retry with a longer timeout or surface this as a user-visible error.
holodeck.lib.backends.selector -- Backend Routing¶
Routes an Agent configuration to the correct backend based on
model.provider.
BackendSelector¶
BackendSelector
¶
Selects and initializes the appropriate backend for an agent configuration.
select(agent, tool_instances=None, mode='test')
async
staticmethod
¶
Select and initialize the appropriate backend for the given agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
Agent configuration with model provider information. |
required |
tool_instances
|
dict[str, Any] | None
|
Initialized tool instances for Claude backend. |
None
|
mode
|
str
|
Execution mode ( |
'test'
|
Returns:
| Type | Description |
|---|---|
AgentBackend
|
An initialized AgentBackend instance ready for use. |
Raises:
| Type | Description |
|---|---|
BackendInitError
|
If the provider is not supported or initialization fails. |
Source code in src/holodeck/lib/backends/selector.py
18 19 20 21 22 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 48 49 50 51 52 53 54 55 56 57 | |
holodeck.lib.backends.openai_agents_backend -- OpenAI Agents Backend¶
Implements the backend for provider: openai and provider: azure_openai
natively on the OpenAI Agents SDK, behind the provider-agnostic backend
interfaces.
OpenAIAgentsBackend¶
OpenAIAgentsBackend(agent, base_dir=None)
¶
OpenAI Agents SDK backend implementing the AgentBackend protocol.
Wraps an SDK Agent (built from the HoloDeck agent config) and drives it
through Runner.run for single-turn invocations and SQLiteSession-
backed multi-turn sessions.
Initialize the backend with agent configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
The HoloDeck agent configuration. |
required |
base_dir
|
Path | None
|
Directory for resolving relative tool/instruction paths.
Falls back to the |
None
|
Source code in src/holodeck/lib/backends/openai_agents_backend.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | |
create_session(*, eager_connect=True)
async
¶
Create a stateful multi-turn session backed by a fresh SQLiteSession.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eager_connect
|
bool
|
Accepted for protocol compatibility; the SQLite session is created synchronously regardless. |
True
|
Returns:
| Type | Description |
|---|---|
AgentSession
|
An |
Source code in src/holodeck/lib/backends/openai_agents_backend.py
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | |
initialize()
async
¶
Build the SDK Agent — validating credentials and tools.
Raises:
| Type | Description |
|---|---|
BackendInitError
|
If credentials are missing or the provider is unsupported. |
ConfigError
|
If a tool config is unsupported or fails to load. |
Source code in src/holodeck/lib/backends/openai_agents_backend.py
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
invoke_once(message, context=None)
async
¶
Execute a single stateless agent turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
context
|
list[dict[str, Any]] | None
|
Optional prior turns (unused in the MVP). |
None
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult for the turn. |
Raises:
| Type | Description |
|---|---|
BackendSessionError
|
If the SDK run fails at runtime. |
Source code in src/holodeck/lib/backends/openai_agents_backend.py
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | |
teardown()
async
¶
Release backend resources, cleaning up RAG tools and MCP servers.
Source code in src/holodeck/lib/backends/openai_agents_backend.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | |
OpenAIAgentsSession¶
OpenAIAgentsSession(sdk_agent, sqlite_session, *, agent_config=None, group_id=None, max_turns=20, budget_usd=None, structured_output=False)
¶
Stateful multi-turn session backed by an SDK SQLiteSession.
Each send runs the SDK agent loop with the shared SQLiteSession so
the SDK persists turn history. Idle sessions are SQLite rows, not held
processes.
Bind the session to an SDK agent and its SQLite-backed history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdk_agent
|
Any
|
The built SDK |
required |
sqlite_session
|
Any
|
The SDK |
required |
agent_config
|
Agent | None
|
The HoloDeck agent config used to build the per-run
|
None
|
group_id
|
str | None
|
The session id, carried as |
None
|
max_turns
|
int
|
The agent-loop cap passed to |
20
|
budget_usd
|
float | None
|
The configured |
None
|
structured_output
|
bool
|
Whether the agent has an output schema, so each
turn's |
False
|
Source code in src/holodeck/lib/backends/openai_agents_backend.py
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 | |
close()
async
¶
Release the SQLite session connection, if any.
Source code in src/holodeck/lib/backends/openai_agents_backend.py
792 793 794 795 796 797 798 | |
prepare()
async
¶
No-op. The SQLite session is ready at construction time.
Source code in src/holodeck/lib/backends/openai_agents_backend.py
719 720 721 | |
send(message)
async
¶
Run one turn against the persistent session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult for this turn. Runtime failures are returned as an |
ExecutionResult
|
error result ( |
ExecutionResult
|
executor can record per-turn failures. |
Source code in src/holodeck/lib/backends/openai_agents_backend.py
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 | |
send_streaming(message)
async
¶
Stream the agent response token by token.
Runs the SDK agent loop via Runner.run_streamed and forwards each
model text delta as it arrives. Text deltas surface as raw-response
events carrying a ResponseTextDeltaEvent; tool-call and lifecycle
events are ignored for the streamed text channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The user message to send to the agent. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
String chunks of the agent response as the model produces them. |
Source code in src/holodeck/lib/backends/openai_agents_backend.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
holodeck.lib.backends.claude_backend -- Claude Agent SDK Backend¶
Implements the backend for provider: anthropic (and local provider: ollama
models). Single-turn invocations use the top-level query() SDK function;
multi-turn chat sessions use ClaudeSDKClient.
ClaudeBackend¶
ClaudeBackend(agent, tool_instances=None, mode='test')
¶
Backend implementation for the Claude Agent SDK.
Implements the AgentBackend protocol. Both single-turn invocations
and multi-turn sessions are built on the top-level query() function;
multi-turn state is threaded via resume=<sdk_session_id> inside
ClaudeSession.
The constructor stores config only — no I/O, no subprocess spawned.
Initialization is deferred to initialize() (called lazily on first use).
Store configuration without performing any I/O.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
Agent configuration. |
required |
tool_instances
|
dict[str, Any] | None
|
Initialized vectorstore/hierarchical-doc tool instances. |
None
|
mode
|
str
|
Execution mode ( |
'test'
|
Source code in src/holodeck/lib/backends/claude_backend.py
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 | |
create_session(*, eager_connect=True)
async
¶
Create a new multi-turn session.
Automatically initializes if not yet done. Under spec 034 P4 the
session no longer holds a persistent ClaudeSDKClient; each
turn opens its own subprocess via query(resume=session_id).
eager_connect is retained as a no-op for API compatibility —
ClaudeSession.prepare() is itself a no-op under P4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eager_connect
|
bool
|
Retained for backwards compatibility; has no effect under spec 034 P4. |
True
|
Returns:
| Type | Description |
|---|---|
ClaudeSession
|
A new |
Source code in src/holodeck/lib/backends/claude_backend.py
2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 | |
initialize()
async
¶
Initialize the backend — validate config, build options.
Idempotent: calling multiple times is a no-op after the first.
Raises:
| Type | Description |
|---|---|
BackendInitError
|
On validation or configuration failure. |
Source code in src/holodeck/lib/backends/claude_backend.py
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 | |
invoke_once(message, context=None)
async
¶
Invoke the agent for a single turn.
Automatically initializes if not yet done. Retries on ProcessError
(subprocess crash) with exponential backoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message text. |
required |
context
|
list[dict[str, Any]] | None
|
Optional conversation context (unused for Claude backend). |
None
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
|
Raises:
| Type | Description |
|---|---|
BackendSessionError
|
After max retries exhausted. |
Source code in src/holodeck/lib/backends/claude_backend.py
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 | |
teardown()
async
¶
Reset backend state, releasing any built options.
Source code in src/holodeck/lib/backends/claude_backend.py
2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 | |
ClaudeSession¶
ClaudeSession(options)
¶
Stateful multi-turn session backed by query(resume=...) (spec 034 P4).
Each send() / send_streaming() opens a fresh CLI subprocess via
the top-level query() function. Turn 1 has no resume; the CLI
assigns a session id which is captured from ResultMessage and
stored on _sdk_session_id. Subsequent turns pass that id via
options.resume so the CLI rehydrates the JSONL transcript at
~/.claude/projects/<encoded-cwd>/<sdk_session_id>.jsonl.
The _base_options reference is never mutated. Turn-specific
options are created as new ClaudeAgentOptions instances.
Initialize session with base options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
ClaudeAgentOptions
|
Base options (immutable reference for the session lifetime). |
required |
Source code in src/holodeck/lib/backends/claude_backend.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 | |
tool_events
property
¶
Queue of real-time tool events emitted via SDK hooks.
close()
async
¶
Delete the on-disk JSONL transcript and clear session state.
Under spec 034 P4 the session has no persistent subprocess to
disconnect. Conversation state lives on disk at
~/.claude/projects/<encoded-cwd>/<sdk_session_id>.jsonl. Closing
the session permanently discards that transcript so the next
open of the same threadId starts fresh.
Source code in src/holodeck/lib/backends/claude_backend.py
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 | |
prepare()
async
¶
No-op under spec 034 P4.
Retained for backwards compatibility with the chat executor's
_TaskBoundSession. Under the hybrid-session model the SDK's
anyio task group is created inside each query() call frame,
so there is no task-binding to do up front.
Source code in src/holodeck/lib/backends/claude_backend.py
1327 1328 1329 1330 1331 1332 1333 1334 1335 | |
release_transport()
async
¶
No-op under spec 034 P4.
Retained for backwards compatibility with the chat executor's
_TaskBoundSession. Under the hybrid-session model each turn's
subprocess is created and torn down inside query(); there is no
persistent transport to release between turns.
Source code in src/holodeck/lib/backends/claude_backend.py
1934 1935 1936 1937 1938 1939 1940 1941 1942 | |
send(message)
async
¶
Send a message and collect the full response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message text. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
|
Raises:
| Type | Description |
|---|---|
BackendSessionError
|
On subprocess or SDK error. |
Source code in src/holodeck/lib/backends/claude_backend.py
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 | |
send_agui(input_data, message_override=None)
async
¶
Send an AG-UI request through this Claude session.
Yields AG-UI events translated directly from Claude SDK stream messages.
Source code in src/holodeck/lib/backends/claude_backend.py
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 | |
send_streaming(message)
async
¶
Send a message and yield text chunks progressively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message text. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
Text chunks as they arrive from the SDK. |
Raises:
| Type | Description |
|---|---|
BackendSessionError
|
On subprocess or SDK error. |
Source code in src/holodeck/lib/backends/claude_backend.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 | |
build_options¶
build_options(*, agent, tool_server, tool_names, mcp_configs, auth_env, otel_env, mode)
¶
Assemble ClaudeAgentOptions from agent config and bridge outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
The agent configuration. |
required |
tool_server
|
McpSdkServerConfig | None
|
In-process MCP server for vectorstore/hierarchical-doc tools. |
required |
tool_names
|
list[str]
|
Allowed tool names from the in-process server. |
required |
mcp_configs
|
dict[str, Any]
|
External MCP server configs from |
required |
auth_env
|
dict[str, str]
|
Auth env vars from |
required |
otel_env
|
dict[str, str]
|
OTel env vars from |
required |
mode
|
str
|
Execution mode ( |
required |
Returns:
| Type | Description |
|---|---|
ClaudeAgentOptions
|
Configured |
Source code in src/holodeck/lib/backends/claude_backend.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 | |
holodeck.lib.backends.tool_adapters -- Claude SDK Tool Adapters¶
Wraps HoloDeck vectorstore and hierarchical-document tools as @tool-decorated
functions, bundles them into an in-process MCP server, and provides a factory
for ClaudeBackend to call during initialization.
VectorStoreToolAdapter¶
VectorStoreToolAdapter(config, instance)
¶
Wraps a VectorStoreTool for use with the Claude Agent SDK.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
VectorstoreTool
|
The vectorstore tool configuration from the agent YAML. |
required |
instance
|
VectorStoreTool
|
An initialized |
required |
Source code in src/holodeck/lib/backends/tool_adapters.py
161 162 163 164 165 166 167 | |
to_sdk_tool()
¶
Return an SdkMcpTool backed by this adapter's search method.
Source code in src/holodeck/lib/backends/tool_adapters.py
169 170 171 172 173 174 175 | |
HierarchicalDocToolAdapter¶
HierarchicalDocToolAdapter(config, instance)
¶
Wraps a HierarchicalDocumentTool for use with the Claude Agent SDK.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
HierarchicalDocumentToolConfig
|
The hierarchical document tool configuration from the agent YAML. |
required |
instance
|
HierarchicalDocumentTool
|
An initialized |
required |
Source code in src/holodeck/lib/backends/tool_adapters.py
215 216 217 218 219 220 221 | |
to_sdk_tool()
¶
Return an SdkMcpTool backed by this adapter's search method.
Source code in src/holodeck/lib/backends/tool_adapters.py
223 224 225 226 227 228 229 | |
create_tool_adapters¶
create_tool_adapters(tool_configs, tool_instances, base_dir=None)
¶
Build adapters for vectorstore, hierarchical-document, and function tools.
Filters tool_configs for supported types, matches each to its initialized instance (vectorstore / hierarchical) or loads the Python callable (function tools) and returns adapter objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_configs
|
list[ToolUnion]
|
All tool configurations from the agent YAML. |
required |
tool_instances
|
dict[str, VectorStoreTool | HierarchicalDocumentTool]
|
Initialized tool instances keyed by config name. |
required |
base_dir
|
Path | None
|
Directory used to resolve relative |
None
|
Returns:
| Type | Description |
|---|---|
list[VectorStoreToolAdapter | HierarchicalDocToolAdapter | FunctionToolAdapter]
|
List of adapter objects ready for |
Raises:
| Type | Description |
|---|---|
BackendInitError
|
If a supported tool config has no matching instance. |
ConfigError
|
If a function tool fails to load. |
Source code in src/holodeck/lib/backends/tool_adapters.py
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 298 299 300 301 | |
build_holodeck_sdk_server¶
build_holodeck_sdk_server(adapters)
¶
Bundle adapters into an in-process MCP server for the Claude subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapters
|
list[VectorStoreToolAdapter | HierarchicalDocToolAdapter | FunctionToolAdapter]
|
Adapter objects produced by |
required |
Returns:
| Type | Description |
|---|---|
McpSdkServerConfig
|
A tuple of |
list[str]
|
server_config is a |
tuple[McpSdkServerConfig, list[str]]
|
allowed_tool_names are the fully-qualified MCP tool names. |
tuple[McpSdkServerConfig, list[str]]
|
Search-backed adapters contribute |
tuple[McpSdkServerConfig, list[str]]
|
adapters contribute the raw tool name. |
Source code in src/holodeck/lib/backends/tool_adapters.py
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 | |
holodeck.lib.backends.mcp_bridge -- MCP Configuration Bridge¶
Translates HoloDeck MCPTool configurations into Claude Agent SDK
McpStdioServerConfig format for subprocess-based MCP servers. Only stdio
transport tools are supported.
build_claude_mcp_configs¶
build_claude_mcp_configs(mcp_tools)
¶
Translate HoloDeck MCPTool configs to Claude SDK MCP server configs.
Only stdio transport tools are supported by the Claude subprocess. Non-stdio tools are skipped with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp_tools
|
list[MCPTool]
|
List of MCPTool configurations from agent YAML. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, McpStdioServerConfig]
|
Dictionary mapping tool names to McpStdioServerConfig TypedDicts. |
Source code in src/holodeck/lib/backends/mcp_bridge.py
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 | |
holodeck.lib.backends.otel_bridge -- Observability Bridge¶
Translates HoloDeck ObservabilityConfig into environment variable dicts that
configure OpenTelemetry for the Claude subprocess.
translate_observability¶
translate_observability(config)
¶
Translate ObservabilityConfig to env vars for the Claude subprocess.
Produces a dict of environment variable key-value pairs that configure OpenTelemetry in the Claude subprocess. All values are strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ObservabilityConfig
|
HoloDeck observability configuration from agent YAML. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of environment variable names to string values. |
dict[str, str]
|
Empty dict if observability is disabled. |
Source code in src/holodeck/lib/backends/otel_bridge.py
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 | |
holodeck.lib.backends.validators -- Startup Validators¶
Pre-flight checks called by ClaudeBackend.initialize() before spawning the
Claude subprocess. These surface configuration errors at startup rather than at
runtime.
validate_nodejs¶
validate_nodejs(agent)
¶
Validate that Node.js is available on PATH when the agent needs it.
Node.js is only required when at least one MCP tool spawns a Node interpreter (node, npx, yarn, pnpm). Agents without such tools skip this check entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
Agent configuration to inspect for Node-dependent tools. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If node is not found on PATH and the agent needs it. |
Source code in src/holodeck/lib/backends/validators.py
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 | |
validate_credentials¶
validate_credentials(model)
¶
Validate authentication credentials for the LLM provider.
Checks that the required environment variables are present for the configured auth_provider, including cloud routing context for Bedrock, Vertex, and Foundry. Returns a dict of environment variables to inject into the Claude subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LLMProvider
|
LLM provider configuration. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of environment variables to set for the subprocess. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If required credentials are absent. |
Source code in src/holodeck/lib/backends/validators.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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
validate_embedding_provider¶
validate_embedding_provider(agent)
¶
Validate embedding provider configuration for vectorstore tools.
Anthropic does not support generating embeddings, so an external embedding_provider must be specified when using vectorstore tools with the Anthropic LLM provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
Agent configuration to validate. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If embedding configuration is invalid for the provider. |
Source code in src/holodeck/lib/backends/validators.py
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 | |
validate_working_directory¶
validate_working_directory(path)
¶
Warn if CLAUDE.md in working directory may conflict with agent instructions.
Detects a CLAUDE.md file that contains a '# CLAUDE.md' header, which is the standard format used by Claude Code project instructions. Such a file may override or conflict with the agent's configured instructions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Working directory path, or None to skip validation. |
required |
Source code in src/holodeck/lib/backends/validators.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 | |
validate_response_format¶
validate_response_format(response_format)
¶
Validate response format schema is serializable and accessible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_format
|
dict[str, Any] | str | None
|
Inline schema dict, file path string, or None. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the schema is not JSON-serializable or file not found. |
Source code in src/holodeck/lib/backends/validators.py
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 | |