airflow.providers.common.ai.durable.caching_model¶
Caching model wrapper for durable execution.
Attributes¶
Classes¶
Wraps a model to cache responses in ObjectStorage for durable execution. |
Module Contents¶
- class airflow.providers.common.ai.durable.caching_model.CachingModel(wrapped, *, storage, counter, replay_usage=None)[source]¶
Bases:
pydantic_ai.models.wrapper.WrapperModelWraps a model to cache responses in ObjectStorage for durable execution.
On each
request()call, checks if a cached response exists for the current step index and was produced by an equivalent request (same model, message history, settings, and tools – compared via fingerprint). If so, returns the cached response without calling the underlying model. Otherwise, calls the model and caches the response. A fingerprint mismatch means the agent changed between attempts; the stale entry is discarded and the step re-runs live.With a
replay_usageledger, a replay hit does not count toward the run’s usage (seeReplayUsageLedger). The cached response is returned unchanged – it is part of what later steps’ fingerprints hash, so zeroing its usage would make every step after this one diverge and re-run live – and the ledger subtracts what the graph is about to add instead.- replay_usage: airflow.providers.common.ai.durable.replay_usage.ReplayUsageLedger | None = None[source]¶
- credit_first_replay()[source]¶
Credit the run’s first model request if the cache holds a response for it.
Called before the run starts, because pydantic-ai checks
request_limitbefore the first request reaches this model; without the credit, a retry whose seededrequestsalready equalsrequest_limitcould not start even when every step would replay for free.