Skip to main content

Self-improving tool ecosystem with V1 (pattern-based generation), V2 (learning-based optimization), and V3 (unified coordination)

Project description

accuralai-adaptive-tools

Self-improving tool ecosystem for AccuralAI

Overview

This package implements the V3 unified adaptive tools architecture that combines:

  • V1 (Exploration): Pattern-based tool generation from telemetry analysis
  • V2 (Exploitation): Learning-based workflow optimization with PlanLang DSL
  • V3 (Coordination): Unified system that compounds gains through cross-system effects

Features

V1: Tool Generation

  • ✅ Telemetry collection and pattern detection
  • ✅ LLM-powered code synthesis
  • ✅ Sandboxed evaluation with safety validation
  • ✅ Human-in-the-loop approval workflows
  • ✅ A/B testing for auto-promotion

V2: Workflow Optimization

  • ✅ PlanLang DSL for declarative tool composition
  • ✅ Multi-objective Bayesian optimization
  • ✅ Strategy support (caching, retries, parallel execution)
  • ✅ Git-versioned recipe memory
  • ✅ Statistical A/B testing

V3: Unified Coordination

  • ✅ Shared telemetry routing to V1 and V2
  • ✅ Unified registry for tools and plans
  • ✅ Cross-system synchronization
  • ✅ Compound gains tracking
  • ✅ Seamless CLI experience

Installation

# From repository root
pip install -e packages/accuralai-adaptive-tools

# With dev dependencies
pip install -e packages/accuralai-adaptive-tools[dev]

Quick Start

See /plan/QUICKSTART-ADAPTIVE-TOOLS.md for detailed setup instructions.

Basic Configuration

Create ~/.accuralai/config.toml:

[adaptive_tools]
enabled = true
mode = "v3"  # "v1", "v2", or "v3"

[adaptive_tools.v1.synthesis]
backend_id = "google"
model = "gemini-2.5-flash-lite"
temperature = 0.2

[adaptive_tools.v2.optimizer]
algorithm = "bayesian"
max_trials = 50

Usage Examples

# Start AccuralAI CLI
accuralai

# Generate new tool from pattern (V1)
>>> /tool propose "merge CSV files"

# Optimize existing workflow (V2)
>>> /plan optimize analyze_logs

# View unified status (V3)
>>> /adaptive status

# Evolve tools and plans together
>>> /tool evolve

Architecture

Package Structure

accuralai_adaptive_tools/
├── contracts/          # Data models and protocols
│   ├── models.py      # Pydantic models
│   └── protocols.py   # Protocol definitions
├── telemetry/         # Shared telemetry system
│   ├── collector.py   # Main collector
│   ├── router.py      # Route to V1/V2
│   └── storage.py     # SQLite persistence
├── registry/          # Unified registry
│   └── unified.py     # Tools + Plans
├── v1/                # Pattern-based generation
│   ├── telemetry/    # Pattern detection
│   ├── synthesis/    # Code generation
│   ├── sandbox/      # Safe execution
│   └── approval/     # Workflows
├── v2/                # Learning-based optimization
│   ├── planlang/     # DSL parser/validator
│   ├── execution/    # Plan executor
│   ├── optimization/ # Bayesian optimizer
│   └── memory/       # Recipe store
├── coordinator/       # V3 coordination
│   └── v3.py         # Main coordinator
└── cli/              # CLI integration
    └── commands.py   # All commands

Data Flow

User Action
    ↓
Telemetry Event
    ↓
Router (decides V1 vs V2)
    ↓
┌───────────────┴───────────────┐
↓                               ↓
V1 System                    V2 System
(Pattern → Tool)             (Metrics → Plan)
↓                               ↓
└──────→ Unified Registry ←─────┘
         ↓
    Better Performance
         ↓
    (Loop continues)

Commands

V1 Commands (Tool Generation)

/tool evolve              # Analyze patterns and propose improvements
/tool propose <desc>      # Create tool from description
/tool review <id>         # Review specific proposal
/tool approve <id>        # Approve proposal
/tool reject <id>         # Reject proposal
/tool metrics <name>      # View tool performance
/tool versions <name>     # View tool history
/tool rollback <name> <v> # Rollback to version

V2 Commands (Plan Optimization)

/plan generate <task>     # Generate plan from description
/plan run <name>          # Execute saved plan
/plan optimize <name>     # Optimize hyperparameters
/plan compare <p1> <p2>   # Statistical A/B test

V3 Commands (Unified)

/adaptive status          # View V1+V2+V3 status

Configuration Reference

[adaptive_tools]
enabled = true
mode = "v3"  # "v1", "v2", or "v3"

[adaptive_tools.v3]
auto_coordinate = true
compound_tracking = true
v1_sequence_threshold = 10
v1_failure_threshold = 0.2
v2_latency_threshold_ms = 500
v2_cost_threshold_cents = 10

[adaptive_tools.v1]
auto_propose = false
approval_mode = "manual"

[adaptive_tools.v1.synthesis]
backend_id = "google"
model = "gemini-2.5-flash-lite"
temperature = 0.2

[adaptive_tools.v1.sandbox]
executor = "subprocess"
timeout_s = 10
max_memory_mb = 256

[adaptive_tools.v2]
max_optimization_trials = 50
ab_test_sample_size = 100
significance_level = 0.05

[adaptive_tools.v2.optimizer]
algorithm = "bayesian"
acquisition_function = "ei"

[adaptive_tools.telemetry]
storage_path = "~/.accuralai/adaptive-tools/telemetry.db"
retention_days = 30
batch_size = 100

Development

Running Tests

# All tests
pytest packages/accuralai-adaptive-tools/tests -v

# Specific subsystem
pytest packages/accuralai-adaptive-tools/tests/v1 -v
pytest packages/accuralai-adaptive-tools/tests/v2 -v
pytest packages/accuralai-adaptive-tools/tests/coordinator -v

Linting

ruff check packages/accuralai-adaptive-tools/
ruff format packages/accuralai-adaptive-tools/

Running Benchmarks

Adaptive Tools vs Baseline Benchmark

Compare AccuralAI performance with and without adaptive tools using the Google Gemini backend:

# Set your Google API key
export GOOGLE_GENAI_API_KEY=your_key_here

# Run all scenarios
python packages/accuralai-adaptive-tools/tests/benchmarks/run_adaptive_benchmark.py

# Run specific scenario
python packages/accuralai-adaptive-tools/tests/benchmarks/run_adaptive_benchmark.py "Multi-Step Data Processing"

# Or via pytest
pytest packages/accuralai-adaptive-tools/tests/benchmarks/test_adaptive_vs_baseline_benchmark.py -v -s

What it tests:

  • Multi-Step Data Processing: Processes data across multiple LLM calls
  • Code Generation Workflow: Generates and refines code iteratively
  • Research and Analysis: Research synthesis workflow
  • Repeated Pattern Detection: Tests adaptive tool generation from patterns

Metrics compared:

  • Latency (response time)
  • Cost (API usage costs)
  • Token efficiency
  • Response quality
  • Cache hit rates
  • Tools generated and optimizations applied

Expected results:

  • Adaptive tools should show improvements in repeated scenarios through:
    • Pattern detection and tool generation (V1)
    • Workflow optimization (V2)
    • Caching and optimization strategies
  • First-time scenarios may show neutral performance (adaptive tools overhead)
  • Repeated scenarios should show 10-30% improvements in latency and cost

System Benchmark Suite

Run the comprehensive system benchmark:

python packages/accuralai-adaptive-tools/tests/benchmarks/test_adaptive_system_benchmark.py

This tests all subsystems (V1, V2, V3) and provides scores across 7 categories.

Documentation

  • Specification: See /plan/accuralai-adaptive-tools-v3-spec.md
  • Quick Start: See /plan/QUICKSTART-ADAPTIVE-TOOLS.md
  • Comparison: See /plan/adaptive-tools-comparison.md
  • Integration: See /plan/accuralai-adaptive-tools-integration.md

Contributing

Contributions welcome! Please see the main AccuralAI repository for guidelines.

License

MIT License - see repository root for details.


Questions? See /plan/ directory for detailed specifications or open an issue.

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

accuralai_adaptive_tools-0.2.1.tar.gz (61.6 kB view details)

Uploaded Source

Built Distribution

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

accuralai_adaptive_tools-0.2.1-py3-none-any.whl (74.1 kB view details)

Uploaded Python 3

File details

Details for the file accuralai_adaptive_tools-0.2.1.tar.gz.

File metadata

  • Download URL: accuralai_adaptive_tools-0.2.1.tar.gz
  • Upload date:
  • Size: 61.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for accuralai_adaptive_tools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a1c064354523f2fc67470e0a6cbff3091f922ef8d56cf4bd8cb5d1075c632424
MD5 cb7974fe1d4455285f313dad595f18c4
BLAKE2b-256 bfa26c85edc615dae41b82242df2543d4227c4faf4df08d414e0a7d4cb6a00aa

See more details on using hashes here.

File details

Details for the file accuralai_adaptive_tools-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for accuralai_adaptive_tools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef6de998609916fa4f072d8e85845f8fcbebd974825835189f745a4ad9d34f4f
MD5 2d30cab70629ec980aa4c77f72f1209e
BLAKE2b-256 7c835e0d6ce51cdf0ea4f344c6ba9b5f16d04ff4f9d5dd52fb68844cd8bb700b

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