airflow.providers.common.ai.tools.anthropic¶
Give Airflow tools to an agent loop run by the Anthropic SDK’s tool runner.
Note
Experimental; see Stable and experimental features.
Classes¶
Airflow's tools for the tool runner of a synchronous |
|
Airflow's tools for the tool runner of an |
Module Contents¶
- class airflow.providers.common.ai.tools.anthropic.AirflowTools(*sources)[source]¶
Airflow’s tools for the tool runner of a synchronous
Anthropicclient.Pass toolsets that implement
ToolProvider, such asSQLToolsetandHookToolset, or individualAirflowToolobjects. Givetoolstoclient.beta.messages.tool_runnerand drive the runner withrun():from anthropic import Anthropic from airflow.providers.common.ai.tools.anthropic import AirflowTools from airflow.providers.common.ai.toolsets import SQLToolset client = Anthropic() tools = AirflowTools(SQLToolset("warehouse", allowed_tables=["orders"])) runner = client.beta.messages.tool_runner( model="claude-opus-5-5", max_tokens=16000, tools=tools.tools, messages=[...], ) message = tools.run(runner)
Each tool keeps the source tool’s name, description and argument schema, and every result passes through Airflow’s secret masker first. A failure the model can correct, such as a query naming a missing column, reaches it as a
tool_resultwithis_error: true, counted against the tool’s retry limit once per model turn. A tool that is still failing once the limit is used up, or a failure the model cannot fix, such as a hook raising, makesrun()raiseToolCallErrorbefore the next model request, so the task fails and Airflow retries it. The runner on its own hands every exception back to the model, so drive it withrun()rather thanuntil_done(). A runner that reaches itsmax_iterationswhile the model is still calling tools makesrun()raiseToolRunnerMaxIterationsError, since its last message holds no answer. A runner created withstream=Trueis not supported.For an
AsyncAnthropicclient, useAsyncAirflowTools.- Parameters:
sources (airflow.providers.common.ai.tools.ToolProvider | airflow.providers.common.ai.tools.AirflowTool) – Toolsets and tools to add, in order.
- tools: list[anthropic.lib.tools.BetaFunctionTool[collections.abc.Callable[..., str]]][source]¶
- run(runner)[source]¶
Drive
runnerto its final message.- Raises:
ToolCallError – when a tool failed in a way the model cannot fix.
ToolRunnerMaxIterationsError – when the runner reached
max_iterationswhile the model was still calling tools.
- class airflow.providers.common.ai.tools.anthropic.AsyncAirflowTools(*sources)[source]¶
Airflow’s tools for the tool runner of an
AsyncAnthropicclient.The asynchronous counterpart of
AirflowTools, with the same behaviour:tools = AsyncAirflowTools(SQLToolset("warehouse", allowed_tables=["orders"])) runner = AsyncAnthropic().beta.messages.tool_runner( model="claude-opus-5-5", max_tokens=16000, tools=tools.tools, messages=[...], ) message = await tools.run(runner)
- Parameters:
sources (airflow.providers.common.ai.tools.ToolProvider | airflow.providers.common.ai.tools.AirflowTool) – Toolsets and tools to add, in order.
- tools: list[anthropic.lib.tools.BetaAsyncFunctionTool[collections.abc.Callable[..., collections.abc.Coroutine[Any, Any, str]]]][source]¶
- async run(runner)[source]¶
Drive
runnerto its final message.- Raises:
ToolCallError – when a tool failed in a way the model cannot fix.
ToolRunnerMaxIterationsError – when the runner reached
max_iterationswhile the model was still calling tools.