LLM providers¶
limen_agents.llm.resolver ¶
Which provider to use, from a plain :class:LlmConfig.
The order, when provider is not given:
- an Anthropic key, if the SDK is installed;
- an OpenAI key, if the SDK is installed;
- a Foundry endpoint and key;
- llama.cpp, the self-hosted server: the fallback with no credentials.
A cloud key whose SDK is missing does not crash: the self-hosted engine is the
intended one where the SDKs are not installed. provider set explicitly
wins, and fails loudly when its credentials are missing.
LlmConfig
dataclass
¶
Everything the resolver needs, with no settings framework behind it.
role_models maps a role ("RiskAnalyst") to a model id for the cloud
providers. declared_role_models is the part of it the operator really
set: the self-hosted engines use only that, because default Claude ids
mean nothing to a local gateway, and every other role falls back to the
engine's *_model.
build ¶
build(config: LlmConfig, provider: Provider, *, budget: Budget = NO_BUDGET, post: Post = post_with_retry) -> LlmClientFactory
The factory of provider, without checking credentials.
resolve ¶
resolve(config: LlmConfig, *, budget: Budget = NO_BUDGET, post: Post = post_with_retry) -> LlmClientFactory
The factory the configuration selects, in the order of the module docstring.
limen_agents.llm.base ¶
Vendor-agnostic chat-client Protocols.
The intent is minimal: every executor + agent code path only depends
on :class:ChatClient. Provider SDKs (Anthropic, OpenAI, …) live behind
concrete factories that lazily import their dependencies.
ChatMessage
dataclass
¶
One chat turn — the same DTO whatever the backing provider.
LlmFactoryError ¶
Bases: RuntimeError
Raised when a factory can't be constructed (missing SDK, missing creds).
ChatClient ¶
Bases: Protocol
A thin async chat-completion abstraction.
Implementations must:
- Be deterministic given the same inputs and a temperature of 0 (best-effort — vendors may drift; we don't depend on it).
- Return raw text. JSON / Pydantic schemas live one layer up in the ChatAgent's response-validation logic.
limen_agents.llm.anthropic ¶
Claude through the official anthropic SDK (extra providers).
AnthropicChatClient
dataclass
¶
A :class:~limen_agents.llm.base.ChatClient on Claude.
AnthropicFactory
dataclass
¶
One :class:AnthropicChatClient per role, with the role's model.
system_and_body ¶
system_and_body(messages: Sequence[ChatMessage]) -> tuple[str | None, list[dict[str, str]]]
The system prompt apart, and the turns as the Messages API wants them.
limen_agents.llm.openai ¶
limen_agents.llm.foundry ¶
Microsoft Foundry: Claude or Azure OpenAI, whichever has an endpoint and a key.
With both, Claude wins, as in the global order of :mod:limen_agents.llm.resolver.
limen_agents.llm.selfhosted ¶
Self-hosted engines with an OpenAI-compatible endpoint: llama.cpp (llama-swap, a LiteLLM gateway) and Ollama, host or cloud. Plain HTTP, no SDK.
LlamaCppChatClient
dataclass
¶
llama.cpp, or a gateway in front of it that may route some models to paid APIs.
OllamaChatClient
dataclass
¶
Ollama on a host (no key) or Ollama Cloud (a bearer key).
payload ¶
payload(model: str, messages: Sequence[ChatMessage], *, temperature: float, max_tokens: int | None, response_format: str) -> dict[str, Any]
The body of an OpenAI-compatible chat completion.