OllamaProvider#

Connect a provider and configure retries, credentials, and transport. See the guide.

class zett_agent.providers.ollama.OllamaProvider(model, transport=None, *, base_url='http://localhost:11434', response=False, retry=RetryOptions(base_delay=0.25, max_delay=8.0, max_retries=3), extra_headers=None, extra_query=None, timeout=TimeoutOptions(connect=5.0, first_byte=600.0, idle=600.0))[源代码]#

Stream Ollama SDK events without buffering the entire HTTP response.

参数:
  • model (str) -- Model name installed or available on the target Ollama server.

  • transport (httpx.AsyncBaseTransport | None) -- Optional HTTPX transport for custom routing or tests.

  • base_url (str) -- Ollama server root; defaults to localhost port 11434.

  • response (bool) -- Must remain false; this adapter uses Ollama's chat endpoint.

  • retry (RetryOptions) -- Backoff policy for failures before the first streamed event.

  • timeout (TimeoutOptions) -- How long the server may stay silent before the request is given up on. See TimeoutOptions. The default allows ten minutes for the first chunk, because a local model may need to be loaded first. A timeout raises ProviderTimeoutError and is not retried.

  • extra_headers (Mapping[str, str] | None) -- HTTP headers sent on every request, such as the Authorization a reverse proxy in front of Ollama expects.

  • extra_query (Mapping[str, str] | None) -- URL query parameters sent on every request.

备注

This adapter does not install models or start the server. Reasoning, vision, and tool support depend on the selected model. Close with aclose().

示例

Connect to a locally running Ollama service:

model = OllamaProvider(model="qwen3", base_url="http://127.0.0.1:11434")
try:
    client = await create_agent(model)
    reply = await client.run("List the public classes")
finally:
    await model.aclose()

备注

base_url selects an existing service. Constructing this adapter does not download a model or launch the Ollama daemon.

参见

连接模型提供商 covers shared adapter ownership and retries; AgentModel defines the normalized stream contract.

response: bool = False#

Whether this adapter uses a Responses-style endpoint instead of its provider's traditional message or chat-completions endpoint. Only the providers read it; the runtime does not.

async aclose()[源代码]#

Close the SDK-owned HTTP connection pool.

返回类型:

None

native_deferred_tools: bool = False#

See zett_agent.model.NativeDeferredToolsModel.native_deferred_tools. A provider opts in by overriding this on its class; the default keeps Responses, Chat Completions, Google, and Ollama on the withhold-and-search path.

sync(*, runtime=None)#

Return a context-managed synchronous view; optionally share a runtime.

Omitting runtime creates a new background thread for this view. Passing an existing runtime reuses its loop and leaves its shutdown to the caller. This API is for service entry points, not Extension lifecycle hooks.

示例

Use a model or tool from a plain function:

with read_file.sync() as read:
    result = read({"path": "README.md"})
参数:

runtime (SyncRuntime | None)

返回类型:

SyncObject[Self]