aap_core
Agent design pattern core framework for building, orchestrating, and training AI agents.
What is this?
aap_core is the foundational framework within the AI Agent Pattern project. It provides a unified abstraction layer for building AI agents, orchestrating multi-agent workflows, and training policies via reinforcement learning — all built on Pydantic and compatible with the A2A protocol v1.0 (a2a-sdk>=1.0.0).
The framework separates orchestration logic from LLM manipulation, delegating model interaction to integration packages (aap_langchain, aap_llamaindex, aap_dspy, aap_transformers). This lets you swap backends without changing agent architecture.
Quick Start
pip install aap_core
# or
uv add aap_core
from a2a.types import AgentCard
from aap_core.agent import BaseAgent
from aap_core.types import AgentMessage
# Define a minimal agent
class MyAgent(BaseAgent):
card: AgentCard = AgentCard(
name="my-agent",
description="A simple agent",
skills=[],
)
def execute(self, message: AgentMessage, **kwargs) -> AgentMessage:
# Your agent logic here
message.responses = [("my-agent", "Hello!")]
message.execution_result = "success"
return message
Features
- Agent Abstraction: Clean
BaseAgentinterface with A2AAgentCardintegration for self-describing agent metadata - Orchestration Patterns: Built-in agents for reflection, looping, voting, coordination, and debate patterns
- Chain System: Generic multi-turn causal chains with history management, tool processing, and token tracking
- Prompt Augmentation: Data and structure-based prompt enhancement with configurable looping strategies
- Retrieval System: Pluggable retrievers with post-processing (e.g., rerankers, summarizers)
- RL Policy Training: Full RL loop with replay buffers, exploration modules, and trainers (PPO, DPO, GRPO, Reinforce++), powered by Gymnasium
- Thought Chains: Chain-of-Thought, Tree-of-Thought, Graph-of-Thought, and Self-Consistency patterns
- Guardrails: Extensible guardrail system for input/output filtering
- Async Support: All agent execution methods have async counterparts (
aexecute) - Token Usage Tracking: Automatic token accounting across multi-agent chains
Installation
Core
pip install aap_core
Integration Packages
pip install aap_langchain # LangChain integration
pip install aap_llamaindex # LlamaIndex integration
pip install aap_dspy # DSPy integration
pip install aap_transformers # Hugging Face Transformers integration
Usage
Building an Agent
from aap_core.agent import BaseAgent
from aap_core.types import AgentMessage
from a2a.types import AgentCard
class TaskAgent(BaseAgent):
def execute(self, message: AgentMessage, **kwargs) -> AgentMessage:
self.state = "running"
# Process the message...
message.responses = [(self.card.name, "Task completed")]
message.execution_result = "success"
self.state = "idle"
return message
Using Orchestration Patterns
from aap_core.orchestration import ReflectionAgent, LoopAgent
# Self-reflection: execute then reflect on the result
reflector = ReflectionAgent(
chain_task=my_chain,
chain_reflection=reflection_chain,
)
result = reflector.execute(message)
# Loop until a condition is met
stopper = lambda msg: "done" in msg.query.lower()
loop = LoopAgent(agent=my_agent, stop_condition=stopper)
result = loop.execute(message)
Prompt Augmentation
from aap_core.prompt_augmenter import SimplePromptAugmenter
# Augment prompts with external context data
augmenter = SimplePromptAugmenter(
format="Context:\n{context}\n\nQuery: {query}",
loop=3, # Apply 3 times
)
augmented = augmenter(message)
RL-Based Prompt Optimization
from aap_core.policy_trainer import PPOTrainer, SimpleReplayBuffer
from aap_core.prompt_augmenter import PromptOptimizationEnv
# Create the environment with multiple augmenters
env = PromptOptimizationEnv(augmenters=[augmenter_a, augmenter_b])
# Create a replay buffer and trainer
buffer = SimpleReplayBuffer(capacity=10000)
trainer = PPOTrainer(policy=my_policy, buffer=buffer)
trainer.train(env, num_steps=10000)
Architecture
aap_core is organized into the following modules:
| Module | Description |
|---|---|
agent |
Base agent interface with A2A AgentCard support and state management |
orchestration |
Multi-agent patterns: reflection, looping, voting, coordination, debate |
chain |
Generic multi-turn causal chains with history, tool processing, and token tracking |
policy |
RL policy models |
policy_trainer |
Replay buffers, exploration modules, and trainers (PPO, DPO, GRPO, Reinforce++) |
prompt_augmenter |
Data and structure-based prompt enhancement with Gymnasium environments |
retriever |
Pluggable retrieval system with post-processing support |
guardrail |
Input/output filtering system |
types |
Core type definitions: AgentMessage, TokenUsage, BaseLLMChain, BaseChain |
utils |
Utility functions (e.g., thinking tag removal) |
Documentation
- Full project documentation: aap_core docs
- Example notebooks: example
- A2A Protocol: a2a-protocol.org · Python SDK a2aproject/a2a-python
Contributing
See the main project README for contribution guidelines.
License
This project is licensed under the MIT License — see the LICENSE file for details.
Metadata
Release files for aap-core 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aap_core-0.3.2.tar.gz | 84.0 kB | With provenance | Details for aap_core-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aap_core-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for aap_core-0.3.2-py3-none-any.whl |
Total release size: 175.2 kB
Release files / aap_core-0.3.2.tar.gz
| Download URL | aap_core-0.3.2.tar.gz |
|---|---|
| Size | 84.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bd4ba9df8d901fabecf4e985490b84362241471891a84eccae69967cbe196fd
|
|
BLAKE2b-256 checksum How to use checksums |
c5a58c1ffdffd3443ca08aa0e346da753b110534d9c4cf972646ddff2b82538b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 26, 2026.
Transparency logRelease files / aap_core-0.3.2-py3-none-any.whl
| Download URL | aap_core-0.3.2-py3-none-any.whl |
|---|---|
| Size | 91.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a32d0da7648c329c1967dba63adb794be81c3eaef43487fe04680db21eb50376
|
|
BLAKE2b-256 checksum How to use checksums |
4ce68cb9a6542eb989ac931010b2826725a049c4711a5317f683f5d83b66b025
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 26, 2026.
Transparency logSecurity for aap-core 0.3.2
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for aap_core-0.3.2.tar.gz
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 Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.