Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyAgentic

Python Version License: MIT Code style: black Tests

A declarative, type-safe framework for building AI agents with OpenAI integration. PyAgentic lets you create sophisticated LLM agents using clean Python class syntax, with full support for tools, persistent state, agent linking, and agent inheritance.

Documentation

Read the Getting Started!

Complete documentation, tutorials, and examples can be found here

Features

  • Declarative Design - Define agents with simple class-based syntax and decorators
  • Powerful Tools - Easy @tool decoration with automatic OpenAI schema generation
  • Persistent State - Stateful agents with State fields that persist across conversations
  • Agent Linking - Compose complex workflows by linking agents together
  • Structured Responses - Type-safe Pydantic responses with full tool execution details
  • Dynamic Constraints - Use ref to create smart parameter validation
  • Inheritance & Extensions - Build agent hierarchies and mix in cross-cutting capabilities
  • Native Async Support - Built for scalable applications with async/await throughout
  • Type Safety - Complete typing support with validation and IDE autocompletion

Quick Start

Installation

pip install pyagentic-core

Simple Agent Example

from pyagentic import BaseAgent, tool, State, spec

class ResearchAgent(BaseAgent):
    __system_message__ = "I help with research tasks and maintain a collection of papers"

    # Persistent state that survives across conversations
    paper_count: State[int] = spec.State(default=0)
    current_topic: State[str] = spec.State(default="general", access="write")

    @tool("Search for academic papers")
    def search_papers(self, query: str, max_results: int = 5) -> str:
        # Your search logic here
        self.paper_count += max_results
        return f"Found {max_results} papers about '{query}'"

# Create and use the agent
agent = ResearchAgent(model="openai::gpt-4", api_key="your-key")
response = await agent("Help me research machine learning papers")

# Access structured response data
print(response.final_output)  # Natural language response
print(len(response.tool_responses))  # Number of tools called
print(agent.paper_count)  # Persistent state

Advanced Features

Agent Linking

Create multi-agent workflows where agents can call other agents as tools:

class DatabaseAgent(BaseAgent):
    __system_message__ = "I query databases"
    __description__ = "Retrieves data from SQL databases"

    @tool("Execute SQL query")
    def query(self, sql: str) -> str: ...

class WebAgent(BaseAgent):
    __system_message__ = "I search the web"
    __description__ = "Searches the internet"

    @tool("search")
    def search(self, terms: list[str]) -> str: ...

class ReportAgent(BaseAgent):
    __system_message__ = "I generate business reports"
    database: DatabaseAgent  # Linked agent appears as a tool
    searcher: WebAgent

    @tool("Create visualization")
    def create_chart(self, data: str) -> str: ...

# The report agent can automatically coordinate with the database agent
report_agent = ReportAgent(database=DatabaseAgent(...), searcher=WebAgent(...))
response = await report_agent("Generate a plot of the latest financial data")

Dynamic Parameter Constraints

Use ref with Pydantic computed fields to create intelligent parameter validation:

from pydantic import BaseModel, computed_field
from pyagentic import ref, spec

class DatasetState(BaseModel):
    available_datasets: list = []

    @computed_field
    @property
    def dataset_names(self) -> list[str]:
        return [ds['name'] for ds in self.available_datasets]

class DataAgent(BaseAgent):
    __system_message__ = "I manage datasets"

    datasets: State[DatasetState] = spec.State(default_factory=DatasetState)

    @tool("Analyze specific dataset")
    def analyze(
        self,
        dataset: str = spec.Param(
            description="Dataset to analyze",
            values=ref.datasets.dataset_names  # LLM can only pick from available datasets
    )) -> str: ...

Contributing

Contribution is welcome! Whether it's bug fixes, new features, documentation improvements, or examples, help is appreciated.

Development Setup

  1. Clone the repository

    git clone https://github.com/your-username/pyagentic.git
    cd pyagentic
    
  2. Install dependencies with uv

    # Install uv if you haven't already
    pip install uv
    
    # Install all dependencies including dev tools
    uv sync --group dev
    

Code Quality

Several tools are used to maintain code quality:

Formatting with Black

# Format all Python files
uv run black -l99 pyagentic tests

# Check formatting without making changes
uv run black -l99 --check pyagentic tests

Linting with Flake8

# Run linting checks
uv run flake8 --max-line-length=99 pyagentic tests 

Testing

# Run all tests
uv run pytest tests

# Run tests with coverage
uv run coverage run -m pytest tests

Documentation

Documentation is built with MkDocs and deployed automatically:

Local Development

# Install docs dependencies
uv sync --group docs

# Serve docs locally (auto-reloads on changes)
uv run task serve-docs

# Build docs to ./site/
uv run task build-docs

Docs are automatically deployed on pushes to main via GitHub Actions.

Submitting Changes

  1. Create a feature branch

    git checkout -b feature/your-feature-name
    
  2. Make your changes following the code style guidelines

  3. Run the full test suite

    uv run black pyagentic tests
    uv run flake8 pyagentic tests --max-line-length=99
    uv run pytest
    
  4. Commit with conventional commit messages

    git commit -m "feat: add new agent linking feature"
    git commit -m "fix: resolve context persistence issue"
    git commit -m "docs: improve getting started guide"
    
  5. Push and create a Pull Request

    git push origin feature/your-feature-name
    

Conventional Commits

Conventional commits are used for automatic versioning:

  • feat: - New features (minor version bump)
  • fix: - Bug fixes (patch version bump)
  • docs: - Documentation changes
  • test: - Test additions or improvements
  • refactor: - Code refactoring
  • style: - Code style changes (formatting, etc.)

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for pyagentic-core 2.15.1.dev1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyagentic-core 2.15.1.dev1
File Size Uploaded
pyagentic_core-2.15.1.dev1.tar.gz 1.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyagentic-core 2.15.1.dev1
File Interpreter ABI Platform
pyagentic_core-2.15.1.dev1-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / pyagentic_core-2.15.1.dev1.tar.gz

Download URL pyagentic_core-2.15.1.dev1.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
d4021c026af61b2f31b58e28af4cbf9dd6f4bebd6f70f824ae06dce876862d45
BLAKE2b-256 checksum
How to use checksums
9e5ae7bdd1a8a792a2b62ae234ae679c54f4df872f4590b239ee8a778a9ccae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / pyagentic_core-2.15.1.dev1-py3-none-any.whl

Download URL pyagentic_core-2.15.1.dev1-py3-none-any.whl
Size 131.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7804449bc48c2f07f6fa6df03bbdd301afdf938b8f7834dab8045f2870d8d8a
BLAKE2b-256 checksum
How to use checksums
2529a7c8de2b59514a98ba09ca8eaf7a6ca605662e507fcd649a58ba60d60627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.15.1.dev1 This release

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page