Skip to content

pydanticai example - #127

Closed
Guidosalimbeni wants to merge 2 commits into
a2aproject:mainfrom
Guidosalimbeni:guido/pydantic_ai
Closed

Guidosalimbeni wants to merge 2 commits into
a2aproject:mainfrom
Guidosalimbeni:guido/pydantic_ai

Conversation

@Guidosalimbeni

Copy link
Copy Markdown

feat: Add Pydantic AI Summarizer Agent with A2A Integration

This pull request introduces the SummarizerAgent, a new agent built using Pydantic AI, showcasing how to integrate this library with the A2A framework. The SummarizerAgent is designed to take a text string as input and return a concise summary of that text.

Motivation:

This example provides a clear illustration of how Pydantic AI can be leveraged to create agents and how such agents can be easily integrated into the A2A ecosystem.

Changes:

  • samples/python/agents/pydantic_agent/agent.py:
    • Defines the SummarizerAgent class, inheriting from Pydantic's BaseModel.
    • Utilizes Pydantic AI's @AICallable decorator to define the summarize method, which handles the summarization logic.
    • Configures the agent to use the OpenAI API key fetched from the OPENAI_API_KEY environment variable.
    • The summarize function has a string as input, and a string as output.
  • samples/python/agents/pydantic_agent/__main__.py:
    • Creates an instance of the SummarizerAgent.
    • Wraps the agent instance in an A2AAgent to make it compatible with the A2A protocol.
    • Starts an A2AServer to host the agent and handle incoming A2A requests.
  • samples/python/agents/pydantic_agent/README.md:
    • Provides instructions on how to run the agent locally.
    • Explains how to connect to the agent.
    • Describes the input and output of the agent.
  • samples/python/agents/pydantic_agent/__init__.py:
    • Empty file, to make the module a python module.

How to Run and Test:

  1. Ensure the OPENAI_API_KEY environment variable is set.
  2. Navigate to the samples/python/agents/pydantic_agent/ directory.
  3. Execute python __main__.py.
  4. Find the agent card url printed on the console.
  5. Add the agent to the demo UI or any other A2A client.
  6. You will be able to interact with the agent, sending texts and getting summaries.

Benefits:

  • Provides a practical example of using Pydantic AI for agent development.
  • Demonstrates the integration of a Pydantic AI agent with the A2A framework.

@google-cla

google-cla Bot commented Apr 12, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@djsamseng djsamseng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not an owner, but I think since this is a python example, all the files should be under samples/python instead of top level?

Also it would be great if we could have this based off of this pull request that properly sets up the samples/python directory structure for proper namespacing

@@ -0,0 +1,9 @@
from a2a.server import A2AServer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is the import a2a coming from? I only see common and server being exported per pyproject.toml

@@ -0,0 +1,22 @@
from pydantic import BaseModel, Field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pydantic and pydantic_ai both need to be added as dependencies? In pyproject.toml

Comment thread mindlink/requirements.txt
@@ -0,0 +1,3 @@
pydantic
pydantic_ai
a2a No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This a2a from 2020? Doesn't seem right.

@holtskinner

Copy link
Copy Markdown
Member

Please move this PR to the new samples repo here https://github.com/google-a2a/a2a-samples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants