Skip to main content

A framework for creating AI agents.

Project description

Agenty

A Pythonic framework for building AI agents and LLM pipelines, powered by pydantic-ai. The framework emphasizes simplicity and maintainability without sacrificing power, making it an ideal choice for rapid prototyping.

📚 Documentation

[!Caution] Initial Development: Agenty is under active development. Expect frequent breaking changes until we reach a stable release.

Agenty provides a clean, type-safe interface for creating:

  • Conversational AI agents with structured inputs and outputs
  • LLM pipelines
  • Complex agent interactions with minimal boilerplate

Key Features

  • Built on pydantic-ai for type validation
  • Automatic conversation history management
  • Intuitive Pythonic interfaces

The framework is currently only officially tested with the OpenAI API (through a proxy such as LiteLLM/OpenRouter) although theoretically it supports all the models supported by pydantic-ai.

[!TIP] Looking for a more mature alternative? Check out atomic-agents, which heavily inspired this project.

Installation

pip install agenty

Or with uv:

uv add agenty

Quick Preview

Here's a simple example to get started:

import asyncio
from agenty import Agent
from pydantic_ai.models.openai import OpenAIModel

async def main():
    agent = Agent(
        model=OpenAIModel(
            "gpt-4o",
            api_key="your-api-key"
        ),
        system_prompt="You are a helpful and friendly AI assistant."
    )

    response = await agent.run("Hello, how are you?")
    print(response)

asyncio.run(main())

In most cases, to build a custom AI agent, you'll want to create your own class that inherits from Agent. The below is functionally equivalent to the above code (and is the recommended way to use this framework)

import asyncio
from agenty import Agent
from pydantic_ai.models.openai import OpenAIModel

class Assistant(Agent):
    model = OpenAIModel("gpt-4o", api_key="your-api-key")
    system_prompt = "You are a helpful and friendly AI assistant."

async def main():
    agent = Assistant()
    response = await agent.run("Hello, how are you?")
    print(response)

asyncio.run(main())

Tools

Add capabilities to your agents with simple decorators:

class WeatherAgent(Agent):
    system_prompt = "You help users check the weather."

    def __init__(self, location: str):
        super().__init__()
        self.location = location
        self.temperature = 72  # Simulated temperature

    @tool
    def get_temperature(self) -> float:
        """Get the current temperature."""
        return self.temperature

    @tool
    def get_location(self) -> str:
        """Get the configured location."""
        return self.location

Structured I/O

Define type-safe inputs and outputs for predictable behavior:

from agenty import Agent
from agenty.types import BaseIO

class User(BaseIO):
    name: str
    age: int
    hobbies: List[str]

class UserExtractor(Agent[str, User]):
    input_schema = str
    output_schema = User
    system_prompt = "Extract user information from the text"

Agent Pipelines

Chain multiple agents together for complex workflows:

class TextCleaner(Agent[str, str]):
    model = OpenAIModel("gpt-4o-mini", api_key="your-api-key")
    system_prompt = "Clean and format the input text"

class SentimentAnalyzer(Agent[str, str]):
    model = OpenAIModel("gpt-4o-mini", api_key="your-api-key")
    system_prompt = "Analyze the sentiment of the text"

# Create and use the pipeline
pipeline = TextCleaner() | SentimentAnalyzer()
result = await pipeline.run("This is my input text!")

Templates

Create dynamic prompts with Jinja templates:

class DynamicGreeter(Agent):
    system_prompt = """
    You are a greeter who:
    - Speaks in a {{TONE}} tone
    - Gives {{LENGTH}} responses
    """
    TONE: str = "friendly"
    LENGTH: str = "concise"

Hooks

Transform inputs and outputs with hooks:

class MyAgent(Agent[str, str]):
    @hook.input
    def add_prefix(self, input: str) -> str:
        return f"prefix_{input}"
        
    @hook.output 
    def add_suffix(self, output: str) -> str:
        return f"{output}_suffix"

📚 Like what you see? Read the Documentation to learn more!


Requirements

  • Python >= 3.12

License

MIT License - see the LICENSE file for details.

Author

Jonathan Chun (@jonchun)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agenty-0.2.0.tar.gz (121.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agenty-0.2.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file agenty-0.2.0.tar.gz.

File metadata

  • Download URL: agenty-0.2.0.tar.gz
  • Upload date:
  • Size: 121.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for agenty-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ff7fe1be040549218cd1db6dd257173b74ae9bfca122fc063be04b1bab5197a7
MD5 541b1616fe81e0123144546deb7d4d28
BLAKE2b-256 1688e96e030179eab5dda0e4def5eb1945bcbe641a51f2627bf49c6d9c44417a

See more details on using hashes here.

File details

Details for the file agenty-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: agenty-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for agenty-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8be55914de639f49af06e25533f01d042b2974d34707e29b8143147003e3ecec
MD5 d863c4f9e8cad15a538ab87de5fc9d9f
BLAKE2b-256 a055351ba71e4ec7885d183ee501df20ad295cc107a6df1f479a2f83256d10a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page