backends
backends ¶
LLM CLI backends for :func:HookContext.call_llm.
Each backend maps the framework's abstract :data:TModel sizes to provider
model names and knows how to build the CLI invocation and parse its response.
LlmBackend ¶
Bases: ABC
Abstract interface for an LLM CLI backend.
Concrete backends map abstract :data:TModel sizes to provider-specific
model names and encapsulate how to invoke the provider's CLI and parse the
raw response.
Attributes:
| Name | Type | Description |
|---|---|---|
models |
dict[TModel, str]
|
Mapping from abstract model size to the provider's model name. |
build_command
abstractmethod
¶
Build the CLI argv for a single LLM invocation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider-specific model name. |
required |
schema_path
|
str | None
|
Path to a JSON schema for structured output, or |
required |
agent
|
bool
|
Whether the invocation may use tools / agent capabilities. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The argv list to execute. |
parse_response
abstractmethod
¶
Parse raw CLI stdout into text or a validated model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str
|
Raw stdout from the backend CLI. |
required |
response_model
|
type[BaseModel] | None
|
Model to validate against, or |
required |
Returns:
| Type | Description |
|---|---|
str | BaseModel
|
|
env
abstractmethod
¶
Return extra environment variables to set for the CLI invocation.
CodexBackend ¶
ClaudeBackend ¶
Bases: LlmBackend
:class:LlmBackend for the Anthropic claude CLI.
extract_structured
staticmethod
¶
Return the validated structured_output from a stream-json event list, if present.