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.
The Agent_structure.py
file provides a skeleton structure for creating an AI agent system that:
- Researches a topic using web search tools
- Plans a blog outline with appropriate sections
- Writes content for each section
- Reviews and polishes the final blog post
The code is organized into four main components:
Using Pydantic BaseModel classes to define structured data formats for:
- Research results
- Blog section tasks
- Review feedback
- Source citations
Using dataclasses to define what information each agent needs:
- Research dependencies
- Outline dependencies
- Section writing dependencies
- Review dependencies
Example agent classes that:
- Take in dependencies
- Execute specific tasks (research, planning, writing, reviewing)
- Return structured outputs
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
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.).
- Python 3.9+
- Pydantic
- An LLM integration library (like openai)
# Example usage
async def main():
blog = await create_blog(
topic="Artificial Intelligence Ethics",
style="Informative and engaging",
type_of_blog="Educational"
)
print(blog)
You can extend this framework by:
- Adding more specialized agents
- Enhancing the research capabilities
- Implementing additional review criteria
- Adding more complex workflows for different content types
MIT