airflow.providers.common.ai.managed_agents.base¶
The contract a provider hook implements to expose a vendor-managed agent.
A managed agent runs its own reasoning loop on the vendor’s infrastructure – Snowflake
Cortex Agents, Amazon Bedrock AgentCore, Azure AI Foundry hosted agents, Vertex AI Agent
Engine. Airflow submits a request and reads an answer. This module defines the shape of that
exchange once, so that every consumer in common.ai (the toolset, the failover group)
is written against one interface rather than one per cloud.
The design follows DbApiHook in common.sql: a small base mixed into each vendor’s
own hook, with the agent as an argument to every method, because a hook is scoped to a
connection and one connection reaches many agents. Vendor providers adopt it the way they
adopt BaseMessageQueueProvider from common.messaging: behind an optional extra, in a
module whose import of this contract is guarded, so a provider that floors Airflow 2 never
has to raise its floor.
This module imports nothing from pydantic-ai on purpose. A vendor hook’s guarded import of the contract must stay cheap.
Classes¶
Normalized identity of a remote agent. |
|
What a |
|
One request to a managed agent. |
|
Usage the vendor reported for one invocation. Every field is optional because vendors differ. |
|
One answer from a managed agent. |
|
Mixin a vendor hook adopts to expose its managed agents through the common contract. |
|
What |
|
A |
Functions¶
|
Render a client's identity for a log line without letting identity resolution fail the caller. |
Module Contents¶
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentRef[source]¶
Normalized identity of a remote agent.
- Parameters:
platform – A stable, dotted platform id such as
aws.bedrock_agentcoreorgcp.vertex_agent_engine. Used as a metric tag, so keep the set small.name – The vendor’s canonical identifier for the agent: an ARN, a full resource name,
DATABASE.SCHEMA.NAME.version – The resolved version or revision when the platform exposes one. Recorded so a behaviour change can be attributed to a deployment rather than to Airflow.
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentCapabilities[source]¶
What a
(hook, agent)pair can do.Consumers check these and refuse rather than degrade: a bound agent rejects a request that carries a
session_idwhensessionsis False, and a failover group never offers sessions at all, because failing over discards the conversation the primary was holding.
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentRequest[source]¶
One request to a managed agent.
Exactly one of
promptandmessagesmust be set. Everything the contract does not type travels invendor_options. A hook may read some of them itself and passes the rest through to the vendor call. Hooks reject options that would re-target the call (the agent identity, the connection), because a model-facing caller must not be able to change what it is talking to.
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentUsage[source]¶
Usage the vendor reported for one invocation. Every field is optional because vendors differ.
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentResponse[source]¶
One answer from a managed agent.
textis what a calling model should read; the hook unwraps the vendor envelope to produce it.rawis that envelope, always populated and never handed to a model, so a Python caller loses nothing.- usage: ManagedAgentUsage | None = None[source]¶
- class airflow.providers.common.ai.managed_agents.base.BaseManagedAgentHook[source]¶
Bases:
abc.ABCMixin a vendor hook adopts to expose its managed agents through the common contract.
Mixed in beside the vendor’s own base and never replacing it:
class BedrockAgentCoreHook(AwsBaseHook, BaseManagedAgentHook): ...
It therefore has no
__init__and makes no assumption aboutget_conn. The agent is an argument to every method, the way a statement is an argument toDbApiHook.run.Method names are chosen to collide with nothing on the shipped vendor hooks. That matters more than it looks:
SnowflakeCortexAgentHookalready definesrun_agentanddescribe_agent, and an abstract method that a vendor base happens to define is silently satisfied with the wrong signature.Implementations sort failures into three classes, and conflating them is the most common way an adoption goes wrong:
ManagedAgentRejected– the agent rejected the request in a way rephrasing could fix. The toolset turns it into a pydantic-aiModelRetryso the calling model tries again.ManagedAgentInvocationError– terminal: bad credentials, missing agent, revoked quota. Nothing on the agent side recovers it; whether the task retries is the task’s retry policy.Anything transient (429, 5xx, connection reset, read timeout) – propagate unchanged. Airflow’s task-level retry is the right layer; a rephrase does nothing for a 503.
- agent_platform: ClassVar[str][source]¶
The
platformeveryManagedAgentReffrom this hook carries.
- abstractmethod resolve_agent(agent)[source]¶
Normalize
agentinto a platform-qualified reference. Must not make a network call.
- abstractmethod get_agent_capabilities(agent)[source]¶
Report what
agenton this connection can do. Must not make a network call.
- class airflow.providers.common.ai.managed_agents.base.ManagedAgentClient[source]¶
Bases:
ProtocolWhat
common.ai’s consumers are typed against.A
BoundManagedAgentsatisfies it. So doesFailoverManagedAgentClient, and so can anything that needs no Airflow connection at all.- property ref: ManagedAgentRef[source]¶
- property capabilities: ManagedAgentCapabilities[source]¶
- class airflow.providers.common.ai.managed_agents.base.BoundManagedAgent[source]¶
A
(hook, agent)pair. Forwards to the hook and resolves identity lazily.This is also where the contract’s “refuse rather than degrade” rule is enforced for every adopter: a request that asks for something the pair’s capabilities do not include is rejected before the hook is called.
- property ref: ManagedAgentRef[source]¶
- property capabilities: ManagedAgentCapabilities[source]¶