agent_framework.drivers#

Module API#

Provider-specific model driver implementations.

class agent_framework.drivers.DialChatCompletionsDriver(base_url, deployment='', api_version='2024-10-21', api_key='', custom_fields=None, retry_without_response_format=True, retry_on_rate_limit=True, rate_limit_max_attempts=3, rate_limit_initial_delay_seconds=5.0, rate_limit_max_delay_seconds=60.0, timeout=120.0, on_request_trace=None, on_response_trace=None, _client=None, _httpx_loop=None, _fallback_state=<factory>)[source]#

Bases: ModelDriverBase, _FallbackMixin

Async driver for DIAL (OpenAI-compatible chat completions).

Uses aidial_sdk.chat_completion.request types for well-typed request construction. Uses agent_framework’s standard ProviderRequestTrace / ProviderResponseTrace callbacks for tracing — dial-agent should adopt this trace mechanism rather than its custom logging hooks.

Parameters:
  • base_url (str)

  • deployment (str)

  • api_version (str)

  • api_key (str)

  • custom_fields (dict[str, Any] | None)

  • retry_without_response_format (bool)

  • retry_on_rate_limit (bool)

  • rate_limit_max_attempts (int)

  • rate_limit_initial_delay_seconds (float)

  • rate_limit_max_delay_seconds (float)

  • timeout (float)

  • on_request_trace (Any | None)

  • on_response_trace (Any | None)

  • _client (Any | None)

  • _httpx_loop (Any | None)

  • _fallback_state (dict[tuple[str, ...], int])

base_url#

DIAL API base URL (e.g. https://dial.example.com).

Type:

str

deployment#

Optional default deployment name. Kept for backward compatibility and direct construction in tests. In normal use the active deployment is taken from the model_names argument passed to decide() on each call.

Type:

str

api_version#

api-version query parameter (default "2024-10-21").

Type:

str

api_key#

DIAL API key sent as the Api-Key header.

Type:

str

custom_fields#

Optional custom_fields dict merged into the request body (DIAL-specific extensions).

Type:

dict[str, Any] | None

retry_without_response_format#

If True (default), re-try once without response_format when DIAL returns HTTP 400.

Type:

bool

timeout#

HTTP timeout in seconds (default 120).

Type:

float

on_request_trace#

Optional ProviderRequestTrace callback.

Type:

Any | None

on_response_trace#

Optional ProviderResponseTrace callback.

Type:

Any | None

_fallback_state#

Per-model-list fallback index map (managed by _FallbackMixin). Call reset_model_fallback() to restart from the first model.

Type:

dict[tuple[str, …], int]

base_url: str#
deployment: str#
api_version: str#
api_key: str#
custom_fields: dict[str, Any] | None#
retry_without_response_format: bool#
retry_on_rate_limit: bool#
rate_limit_max_attempts: int#
rate_limit_initial_delay_seconds: float#
rate_limit_max_delay_seconds: float#
timeout: float#
on_request_trace: Any | None#
on_response_trace: Any | None#
async aclose()[source]#

Release the underlying httpx.AsyncClient.

Return type:

None

capabilities: ClassVar[DriverCapabilities] = DriverCapabilities(is_async=True, supports_multimodal=True, supports_response_format=True, supports_tools=True, supports_streaming=False)#
async decide(*, agent_id, provider_name, model_names, temperature, context)[source]#

Request a structured response from a DIAL deployment.

Tries each model in model_names in order, starting from the last known-good index. The active deployment name for each attempt is taken directly from the model list; self.deployment is not used.

Parameters:
  • agent_id (str | None)

  • provider_name (str)

  • model_names (tuple[str, ...])

  • temperature (float)

  • context (ModelContext)

Return type:

ModelResponse

set_trace_callbacks(*, on_request=None, on_response=None)[source]#

Attach optional trace callbacks for provider I/O logging.

Parameters:
  • on_request (Any | None)

  • on_response (Any | None)

Return type:

None

class agent_framework.drivers.OpenAiModelDriver(api_key, on_request_trace=None, on_response_trace=None, _fallback_state=<factory>, _client=None)[source]#

Bases: ModelDriverBase, _FallbackMixin

OpenAI-backed model driver for the Responses API.

Parameters:
  • api_key (str)

  • on_request_trace (Any | None)

  • on_response_trace (Any | None)

  • _fallback_state (dict[tuple[str, ...], int])

  • _client (Any)

api_key: str#
on_request_trace: Any | None#
on_response_trace: Any | None#
capabilities: ClassVar[DriverCapabilities] = DriverCapabilities(is_async=False, supports_multimodal=False, supports_response_format=True, supports_tools=False, supports_streaming=False)#
decide(*, agent_id, provider_name, model_names, temperature, context)[source]#

Request a structured decision from the OpenAI Responses API.

Parameters:
  • agent_id (str | None)

  • provider_name (str)

  • model_names (tuple[str, ...])

  • temperature (float)

  • context (ModelContext)

Return type:

ModelResponse

set_trace_callbacks(*, on_request=None, on_response=None)[source]#

Attach optional trace callbacks for exact provider I/O logging.

Parameters:
  • on_request (Any | None)

  • on_response (Any | None)

Return type:

None