Skip to content

Add spec_file support to PydanticAIHook.create_agent#67788

Open
gopidesupavan wants to merge 4 commits into
apache:mainfrom
gopidesupavan:add-agent-spec-file
Open

Add spec_file support to PydanticAIHook.create_agent#67788
gopidesupavan wants to merge 4 commits into
apache:mainfrom
gopidesupavan:add-agent-spec-file

Conversation

@gopidesupavan
Copy link
Copy Markdown
Member

Add spec_file parameter to PydanticAIHook.create_agent to load
agent settings from a pydantic-ai AgentSpec YAML or JSON file instead
of hard-coding them in Python.

https://pydantic.dev/docs/ai/core-concepts/agent-spec/#loading-specs


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the 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) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a spec_file parameter to PydanticAIHook.create_agent, allowing agent configuration (model, instructions, model_settings, retries, etc.) to be loaded from a pydantic-ai YAML/JSON AgentSpec file via Agent.from_file(...) instead of being hard-coded in Python. Also bumps the pydantic-ai-slim minimum to >=1.72.0 (which introduced from_file) and adds docs plus an example DAG + example YAML spec.

Changes:

  • Add spec_file parameter and new overloads to PydanticAIHook.create_agent; raise ValueError when neither instructions nor spec_file is given.
  • Add docs section, example DAG, and example YAML spec for the new spec-file workflow.
  • Bump pydantic-ai-slim minimum to >=1.72.0 in pyproject.toml, README, docs index, and uv.lock.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
providers/common/ai/src/airflow/providers/common/ai/hooks/pydantic_ai.py New spec_file branch in create_agent delegating to Agent.from_file with overloads.
providers/common/ai/tests/unit/common/ai/hooks/test_pydantic_ai.py Adds tests for spec_file routing, Path support, instruction override, output_type, kwargs forwarding, and validation error.
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_pydantic_ai_hook.py New example DAG demonstrating spec_file use and instruction override.
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_agent_spec.yaml New example AgentSpec YAML file used by the example DAG.
providers/common/ai/docs/hooks/pydantic_ai.rst New "Loading Agent Config from a Spec File" docs section with YAML sample and example include.
providers/common/ai/pyproject.toml Bump pydantic-ai-slim minimum to >=1.72.0.
providers/common/ai/README.rst Reflect bumped pydantic-ai-slim version.
providers/common/ai/docs/index.rst Reflect bumped pydantic-ai-slim version.
uv.lock Lockfile update for the bumped pydantic-ai-slim minimum.

Comment thread providers/common/ai/pyproject.toml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants