Metadata-Version: 2.4
Name: arc-advisor
Version: 0.1.0
Summary: The learning co-pilot for AI agents. Implements the Executor-Advisor pattern for building self-improving agentic systems.
Author-email: The Arc AI Team <team@arc.computer>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           Copyright 2024 The Arc AI Team
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
Project-URL: Homepage, https://arc.computer
Project-URL: Documentation, https://docs.arc.computer
Project-URL: Repository, https://github.com/arc-ai/arc-advisor
Project-URL: Issues, https://github.com/arc-ai/arc-advisor/issues
Keywords: ai,agents,machine-learning,reinforcement-learning,llm,advisor,executor
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Requires-Dist: huggingface_hub>=0.20.0
Requires-Dist: torch>=2.0.0
Requires-Dist: transformers>=4.38.0
Requires-Dist: pydantic>=2.0
Requires-Dist: chromadb>=0.4.0
Requires-Dist: sentence-transformers>=2.2.0
Provides-Extra: examples
Requires-Dist: openai>=1.0.0; extra == "examples"
Requires-Dist: python-dotenv>=1.0.0; extra == "examples"
Dynamic: license-file

# Arc Advisor - Learning Infrastructure for Agentic Systems

[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org)
[![PyPI](https://img.shields.io/pypi/v/arc-advisor.svg)](https://pypi.org/project/arc-advisor/)

> **Reference Implementation**: This is an experimental reference implementation of the Arc methodology, designed for developers to extend. The library provides a complete infrastructure for building self-improving agents through the Executor-Advisor pattern, with full data collection pipelines for GRPO training and multi-agent orchestration.

Arc Advisor implements the **Executor-Advisor pattern** - an architecture for building self-improving AI agents through separation of reasoning and learning. This library provides production-ready infrastructure for deploying agents that learn from their failures.

## Key Innovation: The Executor-Advisor Pattern

Traditional AI agents fail at complex, multi-step tasks due to lack of specialization. The Executor-Advisor pattern addresses this through architectural separation:

- **Executor**: General-purpose reasoning model (e.g., GPT-4.1) that handles task execution
- **Advisor**: Smaller, specialized model providing strategic guidance based on learned patterns
- **Learning Loop**: Continuous improvement through failure analysis and model updates

This pattern enables agents to improve performance without modifying the base LLM, reducing risk while enabling specialization.

![Arc Advisor Architecture](public/arc-advisor.png)

## Multi-Agent Evolution Roadmap

![Arc Progression](public/roadmap-background.png)

Arc Advisor enables a progressive deployment strategy for agentic systems, where the next level of contextual intelligence is determined by the quality of orchestration. Each stage builds upon the previous, allowing teams to start with human oversight and evolve toward autonomous agent networks.

**Stage 1: Human-in-the-Loop** represents the foundation where humans orchestrate agent control flow through the Arc API. This stage uses the `ArcAdvisorClient` with local advisor models and the `@monitor_and_learn` decorator to provide safe deployment with human oversight. The learning infrastructure captures all interactions for future training while maintaining human control over critical decisions.

**Stage 2: Mediated Agent-to-Sub-Agent Interaction** introduces autonomous operation with learned pattern matching. Here, production agents query the Arc Sub Agent for strategic guidance using `ToolAugmentedAdvisor` with semantic search capabilities. The advisor actively uses tools like `get_remediation_plan` and `query_success_patterns` to provide data-driven strategies based on historical failure analysis and success patterns.

**Stage 3: Autonomous Agent Network with Shared Learning** represents the full vision where the Arc Sub Agent orchestrates multiple specialized agents. The `multi_agent_demo()` showcases A2A-compliant hub managing GPT-4.1, Claude Sonnet-4, and O4-Mini agents working in parallel on complex business scenarios. Each agent contributes its expertise while the Arc Sub Agent synthesizes results and collects reward signals for future GRPO training.

The open-source library provides the complete infrastructure for all three stages, with structured failure data collection preparing organizations for reinforcement learning-trained advisor models. This methodology combines semantic similarity clustering for failure pattern discovery with reward signal aggregation from multi-agent collaboration outcomes, creating a foundation for truly autonomous agentic systems.

## Technical Overview

Arc Advisor provides:

1. **Inference Pipeline**: Local execution of advisor models with automatic device optimization (CUDA/MPS/CPU)
2. **Vector Database**: Semantic search powered by ChromaDB for intelligent pattern discovery
3. **Failure Tracking**: Structured logging with automatic indexing for similarity search
4. **Tool-Augmented Reasoning**: Advisor actively queries its knowledge base for data-driven strategies
5. **Model Agnostic**: Support for any HuggingFace causal language model as advisor
6. **Production Ready**: Robust error handling, configurable failure modes, and comprehensive logging

## Installation

```bash
pip install arc-advisor
```

For development with latest features:
```bash
git clone https://github.com/arc-computer/arc-advisor.git
cd arc-advisor
pip install -e .
```

## Quick Start

### Try the Interactive Demos

Experience the Arc methodology across all three stages of the agentic evolution:

```bash
# Stage 1-2: Single agent with Arc Sub Agent advisor
arc-advisor single-agent

# Stage 3: Multi-agent autonomous network
arc-advisor multi-agent

# Export learning data for analysis
arc-advisor export
```

**Requirements for live inference:**
```bash
# Required for all demos
echo "OPENAI_API_KEY=your-key-here" > .env

# Additional requirement for multi-agent
echo "ANTHROPIC_API_KEY=your-key-here" >> .env
```

The demos showcase real learning infrastructure with:
- **Live streaming inference** - No mocks, only production AI models
- **Semantic failure analysis** - ChromaDB vector search for pattern discovery
- **GRPO reward collection** - Structured signals for future RL training
- **A2A protocol compliance** - Industry-standard agent communication

### Integrate in Your Code

```python
from arc_advisor import ArcAdvisorClient

# Initialize with pre-trained advisor model
advisor = ArcAdvisorClient(
    agent_id="my-agent-001",
    hf_repo_id="Qwen/Qwen3-4B"  # Default general advisor
    # hf_repo_id="arc-computer/qwen3-4b-grpo"  # RL-trained advisor (coming soon)
)

# Decorate your agent's task function
@advisor.monitor_and_learn
def execute_task(query: str, context: dict) -> dict:
    # Get strategic advice before execution
    advice = advisor.get_advice(
        task_description="Complex multi-step workflow",
        context={"query": query, "business_context": context}
    )
    
    # Execute with your primary model
    result = your_executor_model(
        prompt=f"Task: {query}\nStrategy: {advice['strategy']}\nExecute:"
    )
    
    # Return structured outcome
    return {
        "success": validate_result(result),
        "output": result,
        "metrics": {"latency_ms": 150}
    }
```

## Architecture Details

### System Components

The Arc Advisor system consists of three primary components:

1. **Advisor Model**: Provides strategic guidance based on task context
2. **Executor Agent**: Implements the actual task using advisor strategies  
3. **Learning Infrastructure**: Captures failures for continuous improvement

### Data Flow

1. Task request arrives with context
2. Advisor generates strategy based on learned patterns
3. Executor implements task using strategy
4. Outcome logged for learning
5. Failures trigger improvement requests

### Learning Loop

![Arc Learning Infrastructure](public/architecture-background.png)

The learning loop operates as follows:

- **Production Environment**: Agent traces collected during normal operation
- **Failure Bank**: Structured storage of failure patterns and context
- **Learning Orchestrator**: Converts failures into training data
- **RL Training**: Updates advisor model using policy gradient methods
- **Evaluation**: Validates improvements before deployment

**Note**: This open-source reference implementation provides complete data collection infrastructure including:
- Structured failure tracking with semantic embeddings
- GRPO reward signal collection with custom metrics
- A2A-compliant multi-agent orchestration
- Export pipelines for training data preparation

The full continuous learning loop with automated RL training shown above is available through Arc's managed cloud.

## Advanced Configuration

### Vector Database for Semantic Search

Arc Advisor includes a vector database that enables:
- **Semantic Similarity**: Find related failures beyond keyword matching
- **Failure Clustering**: Discover common patterns across failures
- **Intelligent Remediation**: Data-driven strategies based on historical patterns

```python
# Migrate existing events to vector DB
arc-advisor-migrate

# Use tool-augmented advisor with semantic search
from arc_advisor import ToolAugmentedAdvisor

advisor = ToolAugmentedAdvisor(
    agent_id="my-agent",
    on_failure="warn"
)

# Advisor now uses semantic search in its tools
advice = advisor.get_advice(
    task_description="Handle database connection timeout",
    context={"error": "Connection pool exhausted"},
    enable_tools=True
)
```

### Custom Advisor Models

Deploy your own trained advisor:

```python
advisor = ArcAdvisorClient(
    agent_id="domain-specific-agent",
    hf_repo_id="your-org/custom-advisor-7b",
    local_model_dir="~/.arc/models"
)
```

### Generation Parameters

Control advisor output characteristics:

```python
advice = advisor.get_advice(
    task_description="Generate SQL for complex join",
    context={"schema": database_schema},
    generation_config={
        "temperature": 0.3,
        "max_new_tokens": 512,
        "top_p": 0.9
    }
)
```

### Failure Handling

Configure behavior when advisor fails:

```python
# Default: Continue without advice
advisor = ArcAdvisorClient(agent_id="prod-agent", on_failure="warn")

# Strict: Raise exception on failure  
advisor = ArcAdvisorClient(agent_id="test-agent", on_failure="raise")
```

## Interactive Learning Methodology

Arc Advisor implements a novel training methodology inspired by Reinforcement Learning Teachers (RLT) and GRPO optimization, where **advisors learn to teach rather than solve**:

### Stage-Based Learning Architecture

```bash
# Stage 1-2: Single-agent with advisor learning
arc-advisor single-agent
```
- **ToolAugmentedAdvisor** queries semantic failure patterns 
- **Streaming inference** with real-time strategy generation
- **Semantic clustering** discovers failure categories automatically
- **Reward signal collection** for GRPO policy optimization

```bash  
# Stage 3: Multi-agent collaborative learning
arc-advisor multi-agent
```
- **A2A-compliant orchestration** of specialized agents (GPT-4.1, Claude, O4-Mini)
- **Competitive evaluation** through agent collaboration outcomes
- **Relative performance metrics** replace binary success/failure signals
- **Round-robin learning** where agents teach each other through shared experiences

### Learning Infrastructure Features

**Semantic Pattern Discovery:**
- Vector similarity search beyond keyword matching
- Automatic failure clustering using ChromaDB embeddings
- Context-aware remediation strategies from historical patterns

**GRPO Reward Collection:**
- Structured signals from multi-agent collaboration outcomes
- Comparative performance evaluation between agent strategies
- Policy gradient preparation for advisor model fine-tuning
- **Enhanced custom metrics capture** for domain-specific optimization

**Real-Time Learning:**
- Live streaming inference during strategy generation
- Immediate failure indexing and pattern recognition  
- Bidirectional A2A communication for collaborative improvement

## Data Export and Analysis

Export collected failure data for analysis:

```bash
# Export all events
arc-advisor export > agent_events.json

# Extract failure patterns
cat agent_events.json | jq '.[] | select(.event.message_type == "ArcImprovementRequest")'
```

## Example: CRM Automation

See [examples/crm_pro_example.py](examples/crm_pro_example.py) for a complete implementation of a Salesforce CPQ agent using the Executor-Advisor pattern, demonstrating:

- Integration with GPT-4 as executor
- Structured context building for CRM workflows
- Failure tracking for quote generation tasks
- BANT qualification and compliance checking

## Performance Characteristics

- **Advisor Latency**: <100ms on consumer GPUs (MPS/CUDA)
- **Memory Requirements**: 8GB RAM for 4B parameter models
- **Disk Storage**: 10GB for model weights
- **Logging Overhead**: <5ms per event
- **Reward Signal Storage**: ~1KB per interaction (JSONL format)

## API Reference

### ArcAdvisorClient

```python
ArcAdvisorClient(
    agent_id: str,                    # Unique identifier for agent instance
    api_key: Optional[str] = None,    # For future cloud integration
    hf_repo_id: str = "Qwen/Qwen3-4B", # HuggingFace model repository
    local_model_dir: str = "~/.arc/models",  # Local model cache
    on_failure: str = "warn"          # Failure mode: "warn" or "raise"
)
```

### Core Methods

- `get_advice(task_description, context, generation_config)` - Retrieve strategic guidance
- `@monitor_and_learn` - Decorator for automatic outcome tracking
- Event logs: `~/.arc/logs/events.log` (JSON Lines format)

## Protocol Specification

Arc Advisor implements A2A (Agent-to-Agent) protocol for learning communication:

- `ArcLearningReport`: Captures task execution outcomes
- `ArcImprovementRequest`: Signals need for learning from failures

See [arc_advisor/protocols.py](arc_advisor/protocols.py) for schema definitions.

## Contributing

We welcome contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

## License

Apache 2.0. See [LICENSE](LICENSE) for details.

## Citation

If you use Arc Advisor in your research, please cite:

```bibtex
@software{arc_advisor,
  title = {Arc Advisor: Learning Infrastructure for Agentic Systems},
  author = {The Arc Intellgence Team},
  year = {2025},
  url = {https://github.com/arc-computer/arc-advisor}
}
```

---

Built by [The Arc Intelligence Team](https://arc.computer)
