Skip to main content

Open Agent Compliance Protocol - Governance layer for LangGraph

Project description

Open Agent Compliance Protocol (OACP)

A governance layer for LangGraph that adds voting, consensus, and audit trails to multi-agent workflows. OACP transforms your agent systems with democratic decision-making, adaptive prompting, and comprehensive oversight.

Overview

OACP provides a framework for building trustworthy multi-agent systems by adding governance mechanisms on top of LangGraph. It enables agents to vote on decisions, reach consensus, maintain audit trails, and adapt their behavior based on feedback.

Key Features

  • Governance Layer: Add voting and consensus mechanisms to any LangGraph workflow
  • Adaptive Prompting: Automatically improve prompts based on rejection feedback
  • Audit Trails: Complete logging and tracking of all agent decisions and votes
  • Multiple Storage Backends: File, SQLite, and PostgreSQL support
  • Voting Strategies: Unanimous, majority, and weighted voting systems
  • Retry Logic: Intelligent retry mechanisms with exponential backoff
  • LLM Integration: Built-in adapters for popular language models
  • CLI Tools: Command-line interface for management and monitoring

Installation

From Source

git clone https://github.com/your-org/oacp.git
cd oacp
pip install -e .

Dependencies

OACP requires Python 3.10+ and depends on:

  • LangGraph: Core workflow framework
  • Pydantic: Data validation and settings
  • SQLAlchemy: Database abstraction layer
  • Typer: CLI framework
  • Rich: Terminal formatting

Optional dependencies:

  • psycopg: PostgreSQL support
  • FastAPI: Web interface
  • Google Generative AI: Gemini integration

Quick Start

Basic Usage

from oacp import with_oacp, decision_contract, vote, VoteDecision
from langgraph.graph import StateGraph

# Wrap any function with OACP governance
@with_oacp(
    role="researcher",
    invariants=["factual_accuracy", "comprehensive_coverage"],
    log_inputs=True,
    log_outputs=True
)
def research_agent(research_request: dict) -> dict:
    """Conducts initial research on the given topic."""
    # Your agent logic here
    return {"research_results": "..."}

# Create decision contracts for consensus
@with_oacp(
    role="synthesizer",
    contract=decision_contract(
        required_approvers=["researcher", "analyst", "critic"],
        strategy="unanimous",
        timeout_seconds=30
    )
)
def synthesis_agent(data) -> dict:
    """Synthesizes inputs into final report (requires consensus)."""
    # Your synthesis logic here
    return {"final_report": "..."}

# Voting functions
def researcher_vote(run_id: str, content: str):
    if meets_standards(content):
        vote(run_id=run_id, voter_id="researcher", 
             decision=VoteDecision.APPROVE, 
             reason="Content meets research standards")
    else:
        vote(run_id=run_id, voter_id="researcher", 
             decision=VoteDecision.REJECT, 
             reason="Insufficient research depth")

LangGraph Integration

from langgraph.graph import StateGraph

# Create your workflow
workflow = StateGraph(YourState)
workflow.add_node("research", research_agent)
workflow.add_node("synthesis", synthesis_agent)
workflow.add_edge("research", "synthesis")

# OACP governance is automatically applied
app = workflow.compile()

Examples

Research Team Workflow

A multi-agent research team with four specialized agents:

cd examples/research_team
export GOOGLE_AI_API_KEY=your_api_key
python main.py

Features demonstrated:

  • Multi-agent collaboration
  • Consensus-based decision making
  • Real LLM integration (Gemini 2.5 Flash)
  • Audit trails and governance

Flappy Bird Game Design

Agent-based game design with component compatibility voting:

cd examples/flappy_bird_sim
python main.py

Features demonstrated:

  • Component compatibility validation
  • Quality control through voting
  • Design iteration with feedback

Architecture

Core Components

  • Decorators (@with_oacp, wrap_node): Apply governance to functions
  • Contracts: Define voting requirements and strategies
  • Votes: Cast and track voting decisions
  • Context: Access current execution context
  • Storage: Pluggable storage backends
  • Events: Comprehensive event system
  • Adaptive Prompting: Automatic prompt improvement

Storage Backends

  • File Storage: JSON-based local storage
  • SQLite: Lightweight database storage
  • PostgreSQL: Production-ready database storage

Voting Strategies

  • Unanimous: All voters must approve
  • Majority: More than 50% approval required
  • Weighted: Votes have different weights

Configuration

Environment Variables

# Storage configuration
OACP_STORAGE_TYPE=sqlite
OACP_STORAGE_URL=sqlite:///oacp.db

# PostgreSQL example
OACP_STORAGE_TYPE=postgresql
OACP_STORAGE_URL=postgresql://user:pass@localhost/oacp

# File storage example
OACP_STORAGE_TYPE=file
OACP_STORAGE_PATH=./oacp_data

Programmatic Configuration

from oacp.storage import configure_storage

# Configure storage backend
configure_storage(
    storage_type="sqlite",
    storage_url="sqlite:///my_oacp.db"
)

CLI Usage

OACP includes a command-line interface for management:

# View recent activity
oacp logs --limit 50

# Show statistics
oacp stats

# Export audit trail
oacp export --format json --output audit.json

# View voting patterns
oacp votes --agent researcher --days 7

Development

Setup Development Environment

git clone https://github.com/your-org/oacp.git
cd oacp
pip install -e ".[dev]"
pre-commit install

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=oacp --cov-report=html

# Run specific test file
pytest tests/test_decorators.py

Code Quality

# Format code
black oacp tests

# Lint code
ruff check oacp tests

# Type checking
mypy oacp

API Reference

Core Decorators

  • @with_oacp(): Apply OACP governance to functions
  • wrap_node(): Wrap LangGraph nodes with governance

Decision Making

  • decision_contract(): Define voting requirements
  • vote(): Cast votes on decisions
  • VoteDecision: Vote decision enum (APPROVE, REJECT, ABSTAIN)

Context Access

  • current_context(): Access current execution context
  • get_adaptation_statistics(): View adaptive prompting stats

Storage Interface

  • IStorage: Abstract storage interface
  • FileStorage: File-based storage implementation
  • SqliteStorage: SQLite storage implementation
  • PostgresStorage: PostgreSQL storage implementation

Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Ensure code quality checks pass
  5. Submit a pull request

Development Guidelines

  • Follow PEP 8 style guidelines
  • Write comprehensive tests
  • Update documentation for new features
  • Use type hints throughout
  • Add docstrings for public APIs

License

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

Support

  • Documentation: Full documentation available in the docs/ directory
  • Issues: Report bugs and request features on GitHub Issues
  • Examples: See examples/ directory for working implementations
  • CLI Help: Run oacp --help for command-line usage

Roadmap

  • Integration with more LLM providers
  • Advanced voting strategies
  • Web-based monitoring dashboard
  • Distributed agent coordination
  • Performance optimizations
  • Enhanced adaptive prompting algorithms

Version

Current version: 0.1.0 (Beta)

OACP is under active development. APIs may change between versions until 1.0.0 release.

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

oacp-0.1.8.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

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

oacp-0.1.8-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file oacp-0.1.8.tar.gz.

File metadata

  • Download URL: oacp-0.1.8.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for oacp-0.1.8.tar.gz
Algorithm Hash digest
SHA256 61a43b44822aaa046d0b80f81f55dea67fc1761e4f9895931d7899f8ed95a620
MD5 99e1f3be708a324369370f39eec60dbe
BLAKE2b-256 8b935f43c9756017918189603502a7592ea3cdd68ccb13aa5c9cb6b6dd786e3c

See more details on using hashes here.

File details

Details for the file oacp-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: oacp-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for oacp-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 06c5082f0a85d1530c9acec63f8c87c47c3086ef1ebb357bc35ecd355ecae563
MD5 2aed3481ac25cfcf71ef2b86e5807cd5
BLAKE2b-256 83518df9ccc1f985442f1b7044077183d17e3416ea45bcbfe0f84d3e3920e519

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