agentix.providers¶
providers ¶
Model provider adapters.
Each adapter defers its heavy SDK import to construction, so importing the class
is always safe even when the provider's package isn't installed — you only need
the matching extra (agentix[openai], agentix[gemini], …) to use one.
AnthropicModel ¶
AnthropicModel(
*,
model: str = DEFAULT_MODEL,
max_tokens: int = 4096,
api_key: str | None = None,
client: Any = None,
thinking: Thinking | None = None,
effort: Effort | None = None,
task_budget: int | None = None,
**extra: Any,
)
A :class:~agentix.model.ModelFn backed by the Anthropic Messages API.
Example::
from agentix import Agent
from agentix.providers.anthropic import AnthropicModel
agent = Agent(model=AnthropicModel(), system_prompt="...")
Typed knobs (the cost-vs-quality / reasoning controls):
thinking—True/"adaptive"(let the model decide how much to think),"summarized"(adaptive + a visible summary),"disabled", or a raw dict. Note: on Opus 4.7+/Fable, extended thinking is adaptive only;"disabled"is rejected on Fable — omit it there.effort—"low" | "medium" | "high" | "xhigh" | "max"; setsoutput_config.effort(default is"high"). Lower = fewer tokens.task_budget— an int token budget the model self-moderates against for the whole agentic loop (≥ 20000); adds the required beta header. Distinct frommax_tokens(a hard per-response cap).
extra keyword arguments are forwarded to messages.create. For
provider-enforced JSON, pass
output_config={"format": {"type": "json_schema", "schema": ...}} (merged
with effort/task_budget); pair with the agent's output_validator
for client-side validation + retry. Tool schemas with a strict key are
forwarded for strict tool validation.
Refusal fallback: a safety refusal surfaces as a normal final answer
(stop_reason == "refusal"), not an exception — so
:class:~agentix.resilience.FallbackModel (which falls back on errors) does
not catch it. To fall back on a refusal, use the Claude API's server-side
fallbacks parameter (pass it via extra) or detect the refusal text in
your app. FallbackModel/RetryModel remain the right tools for
outages and transient errors.
with_response_format ¶
Return a copy that enforces JSON-schema output via
output_config.format (used by Agent(response_model=…)).
BedrockModel ¶
BedrockModel(
*,
model: str,
max_tokens: int = 4096,
region_name: str | None = None,
client: Any = None,
**extra: Any,
)
A :class:~agentix.model.ModelFn backed by bedrock-runtime.converse.
model is a Bedrock model id or inference-profile id (e.g.
"anthropic.claude-3-5-sonnet-20241022-v2:0" or
"us.anthropic.claude-opus-4-..."). extra is forwarded to converse
(e.g. additionalModelRequestFields for thinking, guardrailConfig).
max_tokens sets inferenceConfig.maxTokens. For tests, inject
client= — any object with a sync converse(**kwargs).
GeminiModel ¶
GeminiModel(
*,
model: str = DEFAULT_MODEL,
api_key: str | None = None,
client: Any = None,
**extra: Any,
)
A :class:~agentix.model.ModelFn backed by Gemini generate_content.
extra is merged into the request config (e.g.
temperature, max_output_tokens, response_mime_type /
response_schema for JSON). For tests, inject client= — any object
exposing client.aio.models.generate_content(...).
with_response_format ¶
Return a copy that enforces JSON output against schema via Gemini's
response_mime_type / response_schema (used by response_model).
LiteLLMModel ¶
A :class:~agentix.model.ModelFn backed by litellm.acompletion.
model uses LiteLLM's provider-prefixed ids. extra is forwarded to
acompletion (e.g. api_base, api_key, temperature,
num_retries). For tests, inject client= — any object exposing an
async acompletion(**kwargs) (the litellm module itself by default).
with_response_format ¶
Return a copy that requests JSON-schema output (for response_model).
MockModel ¶
Returns pre-scripted :class:ModelResponse objects.
script is either:
* a list of ModelResponse — popped in order; when exhausted, a final
empty response is returned so the loop always terminates; or
* a callable (messages) -> ModelResponse for dynamic behavior.
OllamaModel ¶
OllamaModel(
*,
model: str = DEFAULT_MODEL,
host: str | None = None,
client: Any = None,
**extra: Any,
)
A :class:~agentix.model.ModelFn backed by a local Ollama server.
extra is forwarded to chat (e.g. options={"temperature": 0},
keep_alive, format for JSON mode). For tests, inject client= —
any object exposing an async chat(**kwargs).
with_response_format ¶
Return a copy that constrains output to schema via Ollama's
format (used by Agent(response_model=…)).
OpenAIModel ¶
OpenAIModel(
*,
model: str = DEFAULT_MODEL,
api_key: str | None = None,
base_url: str | None = None,
client: Any = None,
**extra: Any,
)
A :class:~agentix.model.ModelFn backed by OpenAI Chat Completions.
Example::
from agentix import Agent
from agentix.providers.openai import OpenAIModel
agent = Agent(model=OpenAIModel(model="gpt-4o"), system_prompt="...")
extra keyword arguments are forwarded to chat.completions.create —
e.g. temperature, response_format for JSON mode, or reasoning_effort
for reasoning models. Tool schemas carrying strict are forwarded for
OpenAI strict structured tool calls. Pricing for unknown model ids is 0.0
until registered via :func:agentix.register_price.
with_response_format ¶
Return a copy that enforces JSON-schema output (used by
Agent(response_model=…)).