airflow.providers.common.ai.utils.prompt_cache

Prompt caching that works the same way whichever provider the connection resolves to.

Attributes

PROMPT_CACHE_SETTING_NAMES

Classes

PromptCaching

Ask the model's provider to cache the repeated prefix of each request.

Module Contents

airflow.providers.common.ai.utils.prompt_cache.PROMPT_CACHE_SETTING_NAMES[source]
class airflow.providers.common.ai.utils.prompt_cache.PromptCaching[source]

Bases: pydantic_ai.capabilities.AbstractCapability[Any]

Ask the model’s provider to cache the repeated prefix of each request.

Backs AgentOperator(cache_prompt=True). A provider-agnostic setting does not exist in pydantic-ai, so this turns on each provider’s own: Anthropic models (direct, Bedrock, Vertex), and Bedrock Converse and OpenRouter models that support caching, are marked; OpenAI and Gemini already cache automatically. Settings the agent or its model already carry for a provider win over these, and a CachePoint in the prompt or history turns them all off.

id: str | None = 'prompt_caching'[source]

Optional identifier used to reference this capability within a run.

Must be unique within a run, not per instance: it identifies the capability across the run — including the fresh instance a [for_run][pydantic_ai.capabilities.AbstractCapability.for_run] override may return — rather than a specific object.

Required when defer_loading=True. If omitted for an always-on capability, the run derives a local id from the class name.

get_model_settings()[source]

Return model settings to merge into the agent’s defaults, or None.

Return a static ModelSettings dict when the settings don’t change between requests. Return a callable that receives [RunContext][pydantic_ai.tools.RunContext] when settings need to vary per step (e.g. based on ctx.run_step or ctx.deps).

When the callable is invoked, ctx.model_settings contains the merged result of all layers resolved before this capability (model defaults and agent-level settings). The returned dict is merged on top of that.

When [defer_loading][pydantic_ai.capabilities.AbstractCapability.defer_loading] is True, these settings are registered up front but merge as an empty dict until the model calls the load_capability tool for this capability.

Was this entry helpful?