GoogleProvider#
Connect a provider and configure retries, credentials, and transport. See the guide.
- class zett_agent.providers.google.GoogleProvider(model, api_key, transport=None, *, response=False, retry=RetryOptions(base_delay=0.25, max_delay=8.0, max_retries=3), base_url=None, extra_headers=None, extra_body=None, timeout=TimeoutOptions(connect=5.0, first_byte=60.0, idle=600.0))[源代码]#
Map official Google GenAI SDK streams and preserve signed replay parts.
- 参数:
model (str) -- Google model identifier used for content generation.
api_key (str) -- API credential supplied by the application.
transport (httpx.AsyncBaseTransport | None) -- Optional HTTPX transport for test isolation or custom routing.
response (bool) -- Must remain false; this adapter uses Google GenerateContent.
retry (RetryOptions) -- Retry/backoff policy, applied before any model event is emitted.
timeout (TimeoutOptions) -- How long the provider may stay silent before the request is given up on. See
TimeoutOptions. The Google client sends its request when the first chunk is asked for, sofirst_bytecovers connecting, the response headers and the first chunk. A timeout raisesProviderTimeoutErrorand is not retried.base_url (str | None) -- API root; None uses Google's public Generative Language endpoint. Set it to reach a proxy, a gateway, or a local test server.
extra_headers (Mapping[str, str] | None) -- HTTP headers sent on every request, for gateways that route or bill on a header.
extra_body (Mapping[str, Any] | None) -- JSON fields merged into every request body, for options the adapter does not model.
备注
ModelResponse retains model-scoped replay parts for subsequent calls. Await aclose() to release the SDK and injected HTTP client.
示例
Configure the SDK adapter without exposing the key in source:
model = GoogleProvider( model=os.environ["GOOGLE_MODEL"], api_key=os.environ["GOOGLE_API_KEY"], ) try: client = await create_agent(model) reply = await client.run("Describe the attached image") finally: await model.aclose()
备注
Provider-specific signed parts are retained in
replay_blocksand reused only with the same Google model.参见
AssistantMessagedescribes model-scoped replay data, and 连接模型提供商 shows the common provider workflow.- 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.
- 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]