LLM providers¶
The vendor-neutral provider protocol and its implementations (OpenAI,
Anthropic, and a deterministic mock for tests), so the agent loop is decoupled
from any single LLM vendor. The real providers import their SDKs lazily, so this
layer is importable without the optional llm extra and only fails if a real
provider is instantiated without its SDK.
llm
¶
Vendor-neutral LLM provider layer for the Fugacio copilot.
Importing this package pulls in only the neutral types and the in-memory
MockProvider; the real providers (OpenAIProvider,
AnthropicProvider) import their SDKs lazily, so they are importable here
without the optional llm extra installed and only fail if instantiated
without the SDK.
Modules:
| Name | Description |
|---|---|
anthropic |
Anthropic (Claude) Messages-API adapter for the Fugacio copilot. |
base |
Provider-neutral chat/tool-calling types for the Fugacio copilot. |
mock |
A deterministic in-memory provider for testing the agent loop without an API. |
openai |
OpenAI chat-completions adapter for the Fugacio copilot. |
Classes:
| Name | Description |
|---|---|
AnthropicProvider |
An |
ChatResponse |
A model's reply: free-text content and/or requested tool calls. |
LLMProvider |
A function-calling chat model. |
Message |
One turn in a chat transcript. |
ToolCall |
A model's request to invoke a tool. |
MockProvider |
A scripted |
OpenAIProvider |
An |
Functions:
| Name | Description |
|---|---|
anthropic_tools |
Map engine tool schemas to Anthropic's |
openai_tools |
Wrap engine tool schemas in OpenAI's |
AnthropicProvider
¶
AnthropicProvider(
model: str = "claude-3-5-sonnet-latest",
*,
client: Any | None = None,
api_key: str | None = None,
)
An LLMProvider backed by the Anthropic API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Claude model name (e.g. |
'claude-3-5-sonnet-latest'
|
client
|
Any | None
|
An existing |
None
|
api_key
|
str | None
|
API key passed to a freshly created client. |
None
|
Methods:
| Name | Description |
|---|---|
chat |
Call the Messages API and parse the reply into a |
ChatResponse
dataclass
¶
A model's reply: free-text content and/or requested tool calls.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
The assistant's text (the final answer when there are no calls). |
tool_calls |
tuple[ToolCall, ...]
|
Any tool calls the model wants executed before continuing. |
raw |
Any
|
The provider's raw response object, for debugging (not portable). |
LLMProvider
¶
Message
dataclass
¶
Message(
role: str,
content: str = "",
tool_calls: tuple[ToolCall, ...] = (),
tool_call_id: str | None = None,
name: str | None = None,
)
One turn in a chat transcript.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
str
|
|
content |
str
|
Text content (may be empty for an assistant tool-call turn). |
tool_calls |
tuple[ToolCall, ...]
|
Tool calls requested by an assistant turn. |
tool_call_id |
str | None
|
For a |
name |
str | None
|
For a |
Methods:
| Name | Description |
|---|---|
system |
A system instruction message. |
user |
A user message. |
assistant |
An assistant message, optionally requesting tool calls. |
tool |
A tool-result message answering a specific tool call. |
assistant
classmethod
¶
An assistant message, optionally requesting tool calls.
ToolCall
dataclass
¶
MockProvider
dataclass
¶
MockProvider(
script: Script,
calls: list[
tuple[list[Message], list[JsonDict]]
] = list(),
_index: int = 0,
)
A scripted LLMProvider.
Attributes:
| Name | Type | Description |
|---|---|---|
script |
Script
|
Either a list of replies returned in order, or a function
|
calls |
list[tuple[list[Message], list[JsonDict]]]
|
Recorded |
Methods:
| Name | Description |
|---|---|
chat |
Return the next scripted reply (or evaluate the script callable). |
OpenAIProvider
¶
OpenAIProvider(
model: str = "gpt-4o-mini",
*,
client: Any | None = None,
api_key: str | None = None,
)
An LLMProvider backed by the OpenAI API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Chat model name (e.g. |
'gpt-4o-mini'
|
client
|
Any | None
|
An existing |
None
|
api_key
|
str | None
|
API key passed to a freshly created client. |
None
|
Methods:
| Name | Description |
|---|---|
chat |
Call chat-completions and parse the reply into a |
anthropic_tools
¶
Map engine tool schemas to Anthropic's {"name", "description", "input_schema"}.