Skip to content

Sample code for building AI agents using Pydantic for structured data handling

Notifications You must be signed in to change notification settings

Dingzeefs/pydantic-ai-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Pydantic AI Agents

This repository contains sample code for building AI agents using Pydantic for structured data handling. The examples demonstrate how to create a system of agents that work together to generate blog content.

Overview

The Agent_structure.py file provides a skeleton structure for creating an AI agent system that:

  1. Researches a topic using web search tools
  2. Plans a blog outline with appropriate sections
  3. Writes content for each section
  4. Reviews and polishes the final blog post

Architecture

The code is organized into four main components:

1. Data Models

Using Pydantic BaseModel classes to define structured data formats for:

  • Research results
  • Blog section tasks
  • Review feedback
  • Source citations

2. Agent Dependencies

Using dataclasses to define what information each agent needs:

  • Research dependencies
  • Outline dependencies
  • Section writing dependencies
  • Review dependencies

3. Agent Implementations

Example agent classes that:

  • Take in dependencies
  • Execute specific tasks (research, planning, writing, reviewing)
  • Return structured outputs

4. Workflow Function

An orchestration function that:

  • Coordinates the agents in a logical sequence
  • Handles data passing between agents
  • Manages the iterative feedback loop
  • Produces the final output

Getting Started

This repository is intended as a starting point for your own AI agent implementations. The examples use dummy agent implementations that you should replace with your own integration to an LLM provider (like OpenAI, Anthropic, etc.).

Requirements

  • Python 3.9+
  • Pydantic
  • An LLM integration library (like openai)

Usage

# Example usage
async def main():
    blog = await create_blog(
        topic="Artificial Intelligence Ethics",
        style="Informative and engaging",
        type_of_blog="Educational"
    )
    print(blog)

Extending the Framework

You can extend this framework by:

  1. Adding more specialized agents
  2. Enhancing the research capabilities
  3. Implementing additional review criteria
  4. Adding more complex workflows for different content types

License

MIT

About

Sample code for building AI agents using Pydantic for structured data handling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages