Skip to content

FelmonFekadu/CompetencyArcEngine

Repository files navigation

🧠 Multiscale Competency Architecture (MCA) Research System

A hierarchical multi-agent workflow system inspired by Michael Levin's work on morphogenetic competencies, designed for emerging technology research and under-discussed risk discovery.

🎯 Overview

This system implements a 4-tier hierarchical agent architecture with:

  • Confidence-based decision making with strict policy enforcement
  • Homeostasis loops for error detection and automatic escalation
  • Multiscale memory (episodic, pattern, morphogenetic, cryptic)
  • Goal-oriented coordination via JSON message envelopes
  • Production-ready REST API and CLI interfaces

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                     TIER 1: Director                        │
│         (Planning, Error Correction, Escalation)            │
└─────────────────────────────────────────────────────────────┘
                              │
        ┌─────────────────────┼─────────────────────┐
        │                     │                     │
┌───────▼──────┐    ┌────────▼────────┐    ┌──────▼──────┐
│   Research   │    │    Analysis     │    │   Critique  │
│  (Evidence)  │    │ (Risks/Patterns)│    │  (Quality)  │
└──────────────┘    └─────────────────┘    └─────────────┘
     TIER 2: Specialist Agents
        │                     │                     │
┌───────▼──────────────────────────────────────────────────┐
│           TIER 3: Executor Agents                        │
│   (fact_check, summarize, entity_extraction, etc.)       │
└──────────────────────────────────────────────────────────┘
                              │
        ┌─────────────────────┴─────────────────────┐
        │         TIER 4: RAG Agent                 │
        │    (Semantic Search, Entity Extraction)   │
        └───────────────────────────────────────────┘

🚀 Quick Start

Replit Run Button

Click the Run button in Replit to start the FastAPI server automatically.

Manual Start

# Install dependencies
pip install -r requirements.txt

# Run the API server
uvicorn app.main:app --host 0.0.0.0 --port 8000

# Access the API
# - Swagger UI: http://localhost:8000/docs
# - Status Dashboard: http://localhost:8000/status

CLI Usage

# Run research objective from terminal
python cli.py "Research quantum dot displays and identify under-discussed risks"

# More examples
python cli.py "Analyze AI safety challenges in autonomous systems"
python cli.py "Investigate biosecurity risks in synthetic biology"

📡 API Endpoints

POST /objective

Execute a research objective through the multi-agent workflow.

Request:

{
  "objective": "Research emerging quantum computing technologies and risks"
}

Response:

{
  "objective": "Research emerging quantum computing technologies and risks",
  "message_count": 42,
  "final_confidence": 0.78,
  "trace": [...]
}

GET /status

View live status dashboard with message trace visualization.

GET /health

Health check endpoint.

🧪 Testing

# Run all tests
make test

# Or directly with pytest
pytest tests/ -v

Test Coverage

  • test_envelope.py: Schema validation and confidence policy gates
  • test_homeostasis.py: Stuck state detection and escalation after 2 cycles
  • test_happy_path.py: Complete workflow integration test

🎛️ Configuration

Environment variables (see .env.example):

APP_NAME=mca-research-risk
DEBUG=true
RAG_ENABLED=true
HTTP_TIMEOUT=30
MAX_CYCLES=8
SESSION_SECRET=your-secret-here

📐 Confidence Policy

All agent outputs include confidence scores ∈ [0,1]:

  • ≥0.70: Proceed (note caveats)
  • 0.40-0.69: Proceed only with verification plan
  • <0.40: Refuse + list exact needs

🔄 Homeostasis & Escalation

Agents monitor their own progress:

  • Track completion state across cycles
  • Detect stuck states (no progress for ≥2 cycles)
  • Automatically escalate to Director
  • Trigger alternative approaches or resource requests

🧬 Morphogenetic Goals

System alignment is enforced against these constant goals:

  1. Safety Alignment: Avoid harmful outputs
  2. Epistemic Rigor: Maintain high evidence standards
  3. Goal Persistence: Complete objectives despite obstacles
  4. Error Minimization: Detect and correct mistakes
  5. Cooperative Autonomy: Collaborate while maintaining independence

🗂️ Memory Layers

  • Episodic: Recent event history (last 1000 events)
  • Pattern: Learned problem-solving strategies
  • Morphogenetic: Core alignment goals
  • Cryptic: Emergent patterns and meta-insights

🐳 Docker

# Build
docker build -t mca-research-risk .

# Run
docker run -p 8000:8000 mca-research-risk

📊 Evaluation Recipes

Robustness

Test with edge cases: vague objectives, conflicting requirements, missing data.

Novelty

Measure ability to identify under-discussed risks not in training data.

Uncertainty

Verify confidence scores correlate with actual accuracy.

Persistence

Confirm workflow completes despite simulated agent failures.

Scalability

Benchmark message throughput and MAX_CYCLES performance.

🛠️ Development

# Install dev dependencies
make install

# Format code
make format

# Lint
make lint

# Clean artifacts
make clean

📝 Message Envelope Schema

All inter-agent communication uses typed JSON envelopes:

MessageEnvelope(
    message_type: "goal_directive | status_update | help_request | goal_complete | error_signal",
    sender_agent: str,
    recipient_agent: str,
    priority: int (1-10),
    timestamp: ISO-8601,
    payload: {
        goal_description: str,
        success_criteria: List[str],
        current_state: str,
        confidence: float (0-1),
        uncertainty_factors: List[str],
        alternative_approaches: List[str],
        resource_requirements: List[str],
        expected_completion: str,
        can_delegate: bool,
        escalation_threshold: str,
        notes: str  # JSON-encoded artifacts
    }
)

🔬 Typed Artifacts

Structured data passed in payload.notes:

  • FactCheckResult: Claim verification with evidence
  • SectionDraft: Research section with provenance
  • HomeostasisReport: Error measurement and actions

🎓 Credits

Inspired by Michael Levin's work on:

  • Multiscale competency in biological systems
  • Goal-directed behavior in agent collectives
  • Morphogenetic fields and pattern formation

📜 License

MIT License - See LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Run tests: make test
  4. Submit a pull request

Built with: FastAPI • Pydantic • Python 3.11 • Rich • Pytest

About

Hierarchical multi-agent system with confidence-based routing, homeostasis loops, and morphogenetic memory — inspired by Michael Levin's competency research

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors