Skip to content

Dm Invoker

[BETA] Modules concerning the decision model invokers used in Gen AI applications.

AnyJevDMInvoker(model_name, base_url, api_key=None, model_kwargs=None, decider_kwargs=None, default_hyperparameters=None, retry_config=None, client_config=None, content_policy=None)

Bases: BaseDMInvoker

[BETA] Invoke AnyJev in-process against an OpenAI-compatible vLLM server.

AnyJev owns question rendering, label readout, permutation marginalization, and calibration. This adapter only translates the SDK schemas and runs AnyJev's synchronous decider off the event loop for direct calls to an OpenAI-compatible vLLM server without a gateway service.

Supported features
  1. Structured state input accepted by AnyJev's state renderer.
  2. Noul, Choice, and Score questions.
  3. Retry and timeout handling through the shared invoker policy.

Attributes:

Name Type Description
model_id str

Provider-qualified model ID.

model_provider str

Provider name used for the transport.

model_name str

Provider-local model name.

default_config dict[str, Any]

Default arguments passed to Decider.decide.

retry_config RetryConfig

Retry and timeout configuration for provider calls.

client_config ClientConfig

Client lifecycle and ownership configuration.

content_policy ContentPolicy | None

Content constraints applied to the state and question text.

Initialize an embedded AnyJev decider.

Parameters:

Name Type Description Default
model_name str

Model name exposed by the vLLM server.

required
base_url str

Base URL of the OpenAI-compatible vLLM server.

required
api_key str | None

AnyJev vLLM server API key. Defaults to the ANYJEV_API_KEY environment variable.

None
model_kwargs dict[str, Any] | None

Additional anyjev.backends.vllm.VLLMBackend arguments. Defaults to None.

None
decider_kwargs dict[str, Any] | None

Additional anyjev.Decider constructor arguments. Defaults to None.

None
default_hyperparameters dict[str, Any] | None

Default arguments passed to Decider.decide. Defaults to None.

None
retry_config RetryConfig | dict[str, Any] | None

Retry and timeout configuration for provider calls. Defaults to None.

None
client_config ClientConfig | dict[str, Any] | None

Client lifecycle settings. AnyJev's backend has no close operation. Defaults to None.

None
content_policy ContentPolicy | dict[str, Any] | None

The per-modality content constraint configuration applied to each string leaf of the state and question text. Defaults to None, in which case no content constraints are applied.

None

Raises:

Type Description
InferenceValueError

If the API key is missing.

ImportError

If the anyjev optional extra is not installed.

OpenAIDMInvoker(model_name, api_key=None, model_kwargs=None, default_hyperparameters=None, retry_config=None, client_config=None, content_policy=None)

Bases: BaseDMInvoker, PersistentClientMixin

[BETA] A decision model invoker that uses OpenAI's typed Decisions API.

Supported features
  1. Text, inline image, and structured state input, with mappings serialized as JSON text.
  2. Noul, Choice, and Score questions.
  3. Noul criteria folded into predicate instructions, since OpenAI predicate questions have no criteria field.
  4. Per-question refusals.
  5. Retry and timeout handling through the shared invoker policy.
  6. Ephemeral or persistent OpenAI client lifecycle management through ClientConfig.

Attributes:

Name Type Description
model_id str

Provider-qualified model ID.

model_provider str

Provider name used for the transport.

model_name str

Provider-local model name.

default_config dict[str, Any]

Default config for invoking the decision model.

retry_config RetryConfig

Retry and timeout configuration for provider calls.

client_config ClientConfig

Client lifecycle and ownership configuration.

content_policy ContentPolicy | None

Content constraints applied to the state and question text.

client_kwargs dict[str, Any]

Keyword arguments for the OpenAI SDK client.

Initialize the beta OpenAI decision model invoker.

Parameters:

Name Type Description Default
model_name str

OpenAI decision model name.

required
api_key str | None

OpenAI API key. Defaults to the OPENAI_API_KEY environment variable.

None
model_kwargs dict[str, Any] | None

Additional AsyncOpenAI parameters. Defaults to None.

None
default_hyperparameters dict[str, Any] | None

Default request options. Defaults to None.

None
retry_config RetryConfig | dict[str, Any] | None

Shared retry and timeout settings. Defaults to None.

None
client_config ClientConfig | dict[str, Any] | None

OpenAI client lifecycle settings. Defaults to None.

None
content_policy ContentPolicy | dict[str, Any] | None

The per-modality content constraint configuration applied to each string leaf of the state and question text. Defaults to None, in which case no content constraints are applied.

None

OpenRouterDMInvoker(model_name, api_key=None, provider=None, default_hyperparameters=None, retry_config=None, client_config=None, model_kwargs=None, content_policy=None, state_format=OpenRouterStateFormat.NATIVE)

Bases: TypeSafeDMInvoker

[BETA] A decision model invoker to interact with OpenRouter API.

This invoker reaches OpenRouter decision models through OpenRouter's System One API. It extends TypeSafeDMInvoker with OpenRouter authentication and provider routing preferences.

Supported features
  1. Structured state input. Supported modalities: a. Text b. Image
  2. Noul, Choice, Score, and Box questions. Supported modalities: a. Text b. Image
  3. Native or flattened state serialization through state_format.
  4. OpenRouter provider routing preferences.
  5. Retry and timeout handling through the shared invoker policy.
  6. Ephemeral or persistent client lifecycle management through ClientConfig.

Examples:

dm_invoker = OpenRouterDMInvoker(
    model_name="typesafe/jev-1.14",
    api_key="<OPENROUTER_API_KEY>",
    provider=["typesafe"],
)
result = await dm_invoker.invoke(
    state="A customer requests a refund.",
    questions={"refund": DMQuestion.noul(instructions="Is a refund requested?")},
)

Use flat state formatting for models that only read images from the top-level state array:

dm_invoker = OpenRouterDMInvoker(..., state_format="flat")
result = await dm_invoker.invoke(
    state={"photo": attachment, "note": "Inspect this listing."},
    questions={"matches": DMQuestion.noul(instructions="Does the photo match the note?")},
)

Attributes:

Name Type Description
model_id str

Provider-qualified model ID.

model_provider str

Provider name used for the transport.

model_name str

Provider-local model name.

default_config dict[str, Any]

Default config for invoking the decision model.

retry_config RetryConfig

Retry and timeout configuration for provider calls.

client_config ClientConfig

Client lifecycle and ownership configuration.

content_policy ContentPolicy | None

Content constraints applied to the state and question text.

client_kwargs dict[str, Any]

Keyword arguments for the TypeSafe SDK client.

provider_config dict[str, Any] | None

OpenRouter provider routing preferences.

state_format OpenRouterStateFormat

How decision state is serialized for OpenRouter.

Initialize the beta OpenRouter decision model invoker.

Parameters:

Name Type Description Default
model_name str

TypeSafe decision model name available through OpenRouter.

required
api_key str | None

OpenRouter API key. Defaults to the OPENROUTER_API_KEY environment variable.

None
provider str | list[str] | dict[str, Any] | None

OpenRouter provider routing preferences. A provider name or list becomes an order preference; a dictionary supports advanced routing options. Defaults to None.

None
default_hyperparameters dict[str, Any] | None

Default request options for each invocation. Defaults to None.

None
retry_config RetryConfig | dict[str, Any] | None

Shared retry and timeout configuration. Defaults to None.

None
client_config ClientConfig | dict[str, Any] | None

Client lifecycle and ownership settings. Defaults to None, which creates a client for each invocation.

None
model_kwargs dict[str, Any] | None

Additional TypeSafe client parameters, e.g. base_url to target a custom OpenRouter-compatible endpoint. They take precedence over the invoker's own client parameters. Defaults to None.

None
content_policy ContentPolicy | dict[str, Any] | None

The per-modality content constraint configuration applied to each string leaf of the state and question text. Defaults to None, in which case no content constraints are applied.

None
state_format OpenRouterStateFormat | str

How decision state is serialized. native preserves structured state and encodes nested attachments in place, while flat renders structured state as text and moves nested images to the top-level state array. Defaults to OpenRouterStateFormat.NATIVE.

NATIVE

Raises:

Type Description
InferenceValueError

If the API key is missing.

CoreValueError

If the state format is unsupported.

PerplexityDMInvoker(model_name, api_key=None, default_hyperparameters=None, retry_config=None, client_config=None, model_kwargs=None, content_policy=None)

Bases: BaseDMInvoker, PersistentClientMixin

[BETA] A decision model invoker to interact with the Perplexity Decisions API.

Supported features
  1. Structured state input, including inline image attachments.
  2. Noul, Choice, and Score questions.
  3. Retry and timeout handling through the shared invoker policy.
  4. Ephemeral or persistent client lifecycle management through ClientConfig.

Examples:

dm_invoker = PerplexityDMInvoker(model_name="pplx-decider-v1-27b", api_key="<PERPLEXITY_API_KEY>")
result = await dm_invoker.invoke(
    state="A customer requests a refund.",
    questions={"refund": DMQuestion.noul(instructions="Is a refund requested?")},
)

Attributes:

Name Type Description
model_id str

Provider-qualified model ID.

model_provider str

Provider name used for the transport.

model_name str

Provider-local model name.

default_config dict[str, Any]

Default config for invoking the decision model.

retry_config RetryConfig

Retry and timeout configuration for provider calls.

client_config ClientConfig

Client lifecycle and ownership configuration.

content_policy ContentPolicy | None

Content constraints applied to the state and question text.

client_kwargs dict[str, Any]

Keyword arguments for the HTTP client.

Initialize the beta Perplexity decision model invoker.

Parameters:

Name Type Description Default
model_name str

Perplexity decision model name, e.g. pplx-decider-v1-27b.

required
api_key str | None

Perplexity API key. Defaults to the PERPLEXITY_API_KEY environment variable.

None
default_hyperparameters dict[str, Any] | None

Default request body fields for each invocation. Defaults to None.

None
retry_config RetryConfig | dict[str, Any] | None

Shared retry and timeout configuration. Defaults to None.

None
client_config ClientConfig | dict[str, Any] | None

Client lifecycle and ownership settings. Defaults to None, which creates a client for each invocation.

None
model_kwargs dict[str, Any] | None

Additional httpx.AsyncClient parameters. They take precedence over the invoker's own client parameters. Defaults to None.

None
content_policy ContentPolicy | dict[str, Any] | None

The per-modality content constraint configuration applied to each string leaf of the state and question text. Defaults to None, in which case no content constraints are applied.

None

Raises:

Type Description
InferenceValueError

If the API key is missing.

TypeSafeDMInvoker(model_name, api_key=None, default_hyperparameters=None, retry_config=None, client_config=None, model_kwargs=None, content_policy=None)

Bases: BaseDMInvoker, PersistentClientMixin

[BETA] A decision model invoker to interact with the TypeSafe API directly.

Supported features
  1. Structured state input. Supported modalities: a. Text b. Image
  2. Noul, Choice, Score, and Box questions. Supported modalities: a. Text b. Image
  3. Retry and timeout handling through the shared invoker policy.
  4. Ephemeral or persistent client lifecycle management through ClientConfig.

Examples:

dm_invoker = TypeSafeDMInvoker(model_name="jev-latest", api_key="<TYPESAFE_API_KEY>")
result = await dm_invoker.invoke(
    state="A customer requests a refund.",
    questions={"refund": DMQuestion.noul(instructions="Is a refund requested?")},
)

Attributes:

Name Type Description
model_id str

Provider-qualified model ID.

model_provider str

Provider name used for the transport.

model_name str

Provider-local model name.

default_config dict[str, Any]

Default config for invoking the decision model.

retry_config RetryConfig

Retry and timeout configuration for provider calls.

client_config ClientConfig

Client lifecycle and ownership configuration.

content_policy ContentPolicy | None

Content constraints applied to the state and question text.

client_kwargs dict[str, Any]

Keyword arguments for the TypeSafe SDK client.

Initialize the beta TypeSafe decision model invoker.

Parameters:

Name Type Description Default
model_name str

TypeSafe decision model name, e.g. jev-latest.

required
api_key str | None

TypeSafe API key. Defaults to the TYPESAFE_API_KEY environment variable.

None
default_hyperparameters dict[str, Any] | None

Default request options for each invocation. Defaults to None.

None
retry_config RetryConfig | dict[str, Any] | None

Shared retry and timeout configuration. Defaults to None.

None
client_config ClientConfig | dict[str, Any] | None

Client lifecycle and ownership settings. Defaults to None, which creates a client for each invocation.

None
model_kwargs dict[str, Any] | None

Additional TypeSafe client parameters, e.g. base_url. They take precedence over the invoker's own client parameters. Defaults to None.

None
content_policy ContentPolicy | dict[str, Any] | None

The per-modality content constraint configuration applied to each string leaf of the state and question text. Defaults to None, in which case no content constraints are applied.

None

Raises:

Type Description
InferenceValueError

If the API key is missing.