Catalog PyPI
PACKAGE EXPLORERView in registry

aap-core

PyPI

Agent design pattern core framework

agentaillmpattern
Versions collected1
Direct dependencies11From release 0.3.0
Last observed20 Oct, 17:00 UTC

README

Version 0.3.0 documentation

aap_core

Agent design pattern core framework for building, orchestrating, and training AI agents.

PyPI - License PyPI - Downloads PyPI - Version Python Version

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.

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 BaseAgent interface with A2A AgentCard integration 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:

ModuleDescription
agentBase agent interface with A2A AgentCard support and state management
orchestrationMulti-agent patterns: reflection, looping, voting, coordination, debate
chainGeneric multi-turn causal chains with history, tool processing, and token tracking
policyRL policy models (GPT-2 based) with RMSNorm, RoPE, and GQA
policy_trainerReplay buffers, exploration modules, and trainers (PPO, DPO, GRPO, Reinforce++)
prompt_augmenterData and structure-based prompt enhancement with Gymnasium environments
retrieverPluggable retrieval system with post-processing support
thoughtThought chain patterns: CoT, ToT, GoT, Self-Consistency
guardrailInput/output filtering system
typesCore type definitions: AgentMessage, TokenUsage, BaseLLMChain, BaseChain
utilsUtility functions (e.g., thinking tag removal)

Documentation

Contributing

See the main project README for contribution guidelines.

License

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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.3.016 Oct 202611

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
quanghona/aap_core

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 17:00 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:bc9625ceef2359fffecdc71570691fd212e9452ca0f7ad3d4c0c88f346a64c94