Models¶
Registry¶
get_model ¶
Get a model from a string identifier.
Format: "provider:model_name"
Examples:
- "openai:gpt-4o"
- "oci:cohere.command-r-plus"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_string
|
str
|
Model identifier in "provider:model" format |
required |
**kwargs
|
Any
|
Provider-specific configuration |
{}
|
Returns:
| Type | Description |
|---|---|
ModelProtocol
|
Model instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If provider is unknown or model string is invalid |
Source code in src/locus/models/registry.py
OCI Generative AI¶
OCIOpenAIModel ¶
OCIOpenAIModel(model: str, *, profile: str | None = None, auth_type: str | None = None, compartment_id: str | None = None, region: str = DEFAULT_OCI_GENAI_REGION, config_file: str = '~/.oci/config', base_url: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, **kwargs: Any)
Bases: OpenAIModel
OCI GenAI model accessed through the /openai/v1 endpoint.
Reuses :class:OpenAIModel for message conversion, tool handling,
response parsing, and streaming. The only thing this class adds is
the OCI-specific auth wiring.
Pass exactly one of profile, auth_type.
Initialize the OCI OpenAI-compat model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
OCI model identifier (e.g. |
required |
profile
|
str | None
|
OCI config profile name from |
None
|
auth_type
|
str | None
|
|
None
|
compartment_id
|
str | None
|
OCI compartment OCID, sent as
|
None
|
region
|
str
|
OCI region hosting the inference endpoint. |
DEFAULT_OCI_GENAI_REGION
|
config_file
|
str
|
Path to the OCI config file (used with |
'~/.oci/config'
|
base_url
|
str | None
|
Override the derived endpoint URL (e.g. for a custom
realm). Defaults to the OpenAI-compat URL for |
None
|
max_tokens
|
int
|
Default max tokens. For |
4096
|
temperature
|
float
|
Default sampling temperature. |
0.7
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If zero or both auth modes are set, if |
Source code in src/locus/models/providers/oci/openai_compat.py
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 235 236 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 279 280 281 282 283 284 285 286 287 288 289 290 | |
client
property
¶
Build the AsyncOpenAI client wired with the OCI request signer.
supports_structured_output
property
¶
Native response_format={"type":"json_schema",...} support.
OpenAI's chat-completions API accepts a JSON-schema response_format and guarantees a parseable instance. The agent loop uses this property to skip the prompted-JSON fallback when the provider ships native structured output.
close
async
¶
__aenter__
async
¶
__aexit__
async
¶
ainvoke
async
¶
LangChain-compatible alias — returns Message (AIMessage equivalent).
Source code in src/locus/models/native/openai.py
bind_tools ¶
LangChain-compatible bind_tools.
Source code in src/locus/models/native/openai.py
OpenAI¶
OpenAIModel ¶
OpenAIModel(model: str = 'gpt-4o', api_key: str | None = None, base_url: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, **kwargs: Any)
Bases: BaseModel
OpenAI model provider.
Supports GPT-4o, GPT-4, o1, o3 models with streaming and tool calling.
Example
model = OpenAIModel(model="gpt-4o") response = await model.complete([Message.user("Hello!")])
Initialize OpenAI model.
Source code in src/locus/models/native/openai.py
supports_structured_output
property
¶
Native response_format={"type":"json_schema",...} support.
OpenAI's chat-completions API accepts a JSON-schema response_format and guarantees a parseable instance. The agent loop uses this property to skip the prompted-JSON fallback when the provider ships native structured output.
client
property
¶
Get or create the OpenAI client.
The client is configured with explicit max_retries and
timeout from :class:OpenAIConfig so transient errors
(429, 5xx, network resets) don't kill the agent loop on first
try. The openai SDK retries with exponential backoff between
attempts.
close
async
¶
__aenter__
async
¶
__aexit__
async
¶
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation history |
required |
tools
|
list[dict[str, Any]] | None
|
Tool schemas in OpenAI format |
None
|
**kwargs
|
Any
|
Additional OpenAI-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
ModelResponse
|
Model response with message and metadata |
Source code in src/locus/models/native/openai.py
ainvoke
async
¶
LangChain-compatible alias — returns Message (AIMessage equivalent).
Source code in src/locus/models/native/openai.py
bind_tools ¶
LangChain-compatible bind_tools.
Source code in src/locus/models/native/openai.py
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation history |
required |
tools
|
list[dict[str, Any]] | None
|
Tool schemas in OpenAI format |
None
|
**kwargs
|
Any
|
Additional OpenAI-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[ModelChunkEvent]
|
Streaming chunks with content and/or tool calls |
Source code in src/locus/models/native/openai.py
358 359 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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
Anthropic¶
AnthropicModel ¶
AnthropicModel(model: str = 'claude-sonnet-4-20250514', api_key: str | None = None, base_url: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, prompt_cache: bool = False, **kwargs: Any)
Bases: BaseModel
Anthropic model provider.
Supports Claude 4.6, 4.5, 3.5 models with streaming and tool calling.
Example
model = AnthropicModel(model="claude-sonnet-4-20250514") response = await model.complete([Message.user("Hello!")])
Source code in src/locus/models/native/anthropic.py
supports_structured_output
property
¶
Anthropic doesn't ship OpenAI-style response_format.
The agent loop falls back to the prompted-JSON path with post-hoc parsing for Anthropic models.
client
property
¶
Get or create the Anthropic client.
Configured with explicit max_retries + timeout so a
transient 529 (overloaded) / 5xx / connection reset doesn't
kill the agent loop on the first try. Retries use exponential
backoff inside the anthropic SDK.
close
async
¶
Close the underlying httpx client.
Agent.run_sync calls this in a finally block so the
loop-bound httpx connections are shut down inside the same
event loop that opened them. Without this, the next
asyncio.run invocation closes the prior loop and the
leftover client's __del__ later tries to aclose against
it, raising RuntimeError: Event loop is closed.
Source code in src/locus/models/native/anthropic.py
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request.
Recognises an OpenAI-style response_format={"type": "json_schema", ...}
kwarg and translates it into Anthropic's tool-use mechanism: a synthetic
respond_with_schema tool is appended to the call and tool_choice
is pinned to it. The tool arguments are then surfaced as the message
content (canonical JSON) so callers can parse them with
:func:locus.core.structured.parse_structured exactly as they would
with native response_format providers.
Source code in src/locus/models/native/anthropic.py
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 302 303 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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 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 | |
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.
Source code in src/locus/models/native/anthropic.py
Ollama¶
OllamaModel ¶
OllamaModel(model: str = 'llama3.3', base_url: str = 'http://localhost:11434', max_tokens: int = 4096, temperature: float = 0.7, **kwargs: Any)
Bases: BaseModel
Ollama model provider for local LLMs.
Supports any model available in Ollama (Llama, Mistral, Gemma, etc.) with tool calling support.
Example
model = OllamaModel(model="llama3.3") response = await model.complete([Message.user("Hello!")])
Source code in src/locus/models/native/ollama.py
supports_structured_output
property
¶
Ollama doesn't yet ship OpenAI-style response_format.
The agent loop falls back to the prompted-JSON path with post-hoc parsing for Ollama models.
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request.
Source code in src/locus/models/native/ollama.py
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.