kaxil opened a new pull request, #73602:
URL: https://github.com/apache/airflow/pull/73602
The Common AI docs don't yet say how to iterate on an agent without
deploying a Dag each time, or how to test an agent task in CI without an API
key. This adds a "Develop and test locally" page for both, and a section on the
agent operator page for sharing one agent definition across tasks.
The new page follows one agent from a notebook to a tested Dag:
- **Iterate in a notebook.** Build the agent with
`PydanticAIHook.get_hook(...).create_agent(...)` and the same toolsets the task
will use. Connections come from `AIRFLOW_CONN_*` variables, so no scheduler or
metadata database is involved. It then shows the same agent as an `@task.agent`
Dag and which argument maps to which.
- **Test without calling a model.** Patch `PydanticAIHook.get_conn` to
return a pydantic-ai `FunctionModel` with scripted replies, and run
`dag.test()`. The real task runs, including template rendering, tool calls
against a test database and XCom. The page lists what `dag.test()` needs from
the test environment, and why a connection with model `test` doesn't work for
an agent with a `SQLToolset`: `TestModel` calls every tool with generated
arguments, and the SQL it generates fails validation until the retries run out.
- **Check the answers.** A pointer to running evals against a real model,
since a scripted test can't tell you whether a prompt change made the answers
worse.
The reuse section shows an agent kept as a dict of operator kwargs in a
module next to the Dags, overriding single keys per task, with
`agent_params={"name": ...}` so traces from every task group under one
`gen_ai.agent.name`. It also covers the pydantic-ai spec file route, and its
two gotchas: a relative `spec_file` path resolves against the worker's working
directory, and tools from spec-file capabilities are not replayed by
`durable=True`.
Every code block ran as printed in Breeze against a SQLite `orders` table:
the notebook snippet (with only the model swapped), both Dags, the spec-file
operator with and without `system_prompt`, and the guide's pytest, which passes.
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]