# Project export: Conductor AI

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: TreeHacks 2025
- Tagline: Agentic routing at scale for 66x cheaper and 4x faster — Powering the Agentic Future
- Devpost: https://devpost.com/software/conductor-ai
- GitHub: https://github.com/shloknatarajan/ariadne-routing
- Demo: https://docs.google.com/presentation/d/1SJoZzRauls_bHquv1L-HxrW5x9swVYLvnOsvtVu0Tj8/edit?usp=sharing
- Video: https://www.youtube.com/embed/0vY9tj6UDJE?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Result: winner (Codegen: Best Code Generation Application ($1.5k Cash))
- Team: 3 GitHub contributor(s) — Advay (24 commits), Shlok Natarajan (16 commits), Victor Cheng (15 commits)

## Devpost submission (written by the team)

### Overview

Agentic Routing At Scale: The Cornerstone of an Agentic Future Enterprises run a large number of agents, and being able to choose which agent to run a query on is a complex and expensive task. Routers exist today that can handle O(10) agents, but what about O(1000). Salesforce has O(10000) agents and — in a future where agents seem poised to replace many jobs — organizations may come to rely on the orchestration of O(1,000,000) agents with O(100,000,000) prompts/day. If we want a future driven by agents, with companies formed of agents, and to maximize performance/$ for inference, we need to solve the large-scale routing problem. The routing space is large and continuing to explode, and there exist no systems that can scale to the size that is needed. We develop a novel recommendation-system based algorithm for prompt routing, drawing inspiration from the TikTok algorithm Fortunately, our team (check below) is adept at handling matching problems at scale. Taking inspiration from the recommendation system at TikTok, ConductorAI matches queries and routers through a two-stage embedding approach, learning prompt and agent embeddings from exploring the interaction between the two and without manual encoding or intensive processing of either. Check out the technical details in our slides! ConductorAI: 66x cost savings, 4x latency reduction, better than any single AI model, and exponentially better performance with many agents ConductorAI provides unheard of speed and cost reduction at reasonable accuracy for an agent-driven future. Conductor implicitly learns a mapping between a semantic-embedding space and an agentic-embedding space, where coordinates correspond to features such as problem difficulty, tools required, and context that may be relative when deciding between agents. Additionally, adding agents to the system requires no hard-coded rules or descriptions, Conductor can naturally learn agent embeddings that exceed human performance. With A agents and P prompts, a traditionally LLM based router has inference scale on the order of O(PA), as each agent needs to be referenced in context, a classification-based router scales on the order of O(PA), and the theoretical perfect router scales at O(P). We scale at O(P log A) amortized, being the only neural-network based approach to do so. With the Intersystems vector search system, this O(log A) term is practically unnoticed. Conductor Composer To showcase the power of ConductorAI routing on practical problems, we have orchestrated an Agentic Suite around ConductorAI, incorporating agents for: Perplexity Search Code Generation Customer Service Database Management Executive Assistant HR Questions Legal Advice Software QA Web Automation Calendar Agent Here is our github repo containing our router, completely open-source: https://github.com/shloknatarajan/ariadne-routing Codegen Developer Tool: SWE-Bench Agent Harness & Evaluator For our code generation service, we extended it to provide a dev tool for Codegen users to run SWE-Bench on. We've made it very easy to run, test, and evaluate on SWE-Bench using Codegen's SDK, and included our own Codegen Agent that works on SWE-Bench. Here is the pull request containing the addition: https://github.com/codegen-sh/codegen-sdk/pull/521 Team Shlok Natarajan - Stanford University, Routing Research with Prof. Azalia Mirhoseini and Prof. Roxana Daneshjou Devan Shah - Princeton, Recommendation Systems at TikTok Advay Goel - MIT, Building @ Prod Victor Cheng - vly.ai, a Y Combinator company for Coding Agents

## README (from the GitHub repository)

# Routing
Problem: We want to be able to route a user's query to the best agent based on the query. This solves an increasingly difficult problem as the number of agents grows. This solution is inspired by social media recommendation systems to recommend agents based on the user's query. 

To get started, run `python app.py`

## Cluster Generation
1. Take a set of queries
2. Convert each query into a vector using a pre-trained embedding model
3. Cluster the queries into different groups based on the similarity of their vectors
4. For each cluster, select the query that is most representative of the cluster or convert the cluster into a single embedding vector

## Routing
1. Take a set of queries
2. Convert the queries into a vector using the same pre-trained embedding model
3. For each set of similar queries, convert the cluster into a single embedding vector
4. Return cluster embedding vector
5. Map cluster embedding vector to agent space
6. Map to agent embedding



## Detected evidence (automated analysis)

Indexed codebase: 47 recognized source files, 187 KB.
- HTML (language) — detected in the code
- Python (language) — detected in the code
- PyTorch (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (65 of 65)

```
.codegen/config.toml
.gitattributes
.gitignore
.vscode/launch.json
agents/calendar_agent.py
agents/codegen_agent.py
agents/coding_agent.py
agents/customer_service.py
agents/database_agent.py
agents/employee_data.csv
agents/executive_assistant.py
agents/hr.py
agents/legal.py
agents/perplexity.py
agents/software_qa.py
agents/web_automation.py
app.py
clustering.py
conda_environment.yml
experiments/router_test.ipynb
experiments/routerbench copy.ipynb
experiments/routerbench_existing.ipynb
experiments/routerbench.ipynb
ideation.py
math_visual/animation.html
math_visual/manim_vid.py
media/Tex/d61bb4f3d1f7face.tex
media/videos/manim_vid/1080p60/partial_movie_files/PromptToVector/partial_movie_file_list.txt
media/videos/manim_vid/480p15/partial_movie_files/PromptToVector/partial_movie_file_list.txt
mistral_embed.py
old_agents/accounting.py
old_agents/business_development.py
old_agents/business_intelligence.py
old_agents/codegen_code_research.py
old_agents/compliance.py
old_agents/data_science.py
old_agents/devops.py
old_agents/inventory_management.py
old_agents/it_support.py
old_agents/marketing.py
old_agents/network_monitoring.py
old_agents/operations.py
old_agents/procurement.py
old_agents/project_management.py
old_agents/risk_management.py
old_agents/rnd.py
old_agents/security.py
old_agents/social_media.py
old_agents/supply_chain.py
old_agents/text_to_speech.py
old_agents/text_to_video.py
pixi.lock
pixi.toml
prompts.md
prompts.py
README.md
router_demo.ipynb
router_states/router_state_12.pkl
router_states/router_state.pkl
router_states/router.pkl
routing.py
run_agents.py
stream_router.py
templates/index.html
vs_stream_router.py
```

### Dependencies

No dependency index available.

### Recent commits (newest first)

- Merge pull request #8 from shloknatarajan/shlok/feat/pixi-setup
- feat: pixi additions + added missing file
- Update README.md
- chore: folder rename
- chore: cleanup
- Merge pull request #7 from shloknatarajan/shlok/feat/planner
- feat: app
- fix: threshold update
- fix: threshold update
- Merge pull request #5 from shloknatarajan/shlok/feat/planner
- feat: readme updates
- Merge pull request #4 from shloknatarajan/shlok/feat/planner
- feat: planner
- print statements
- feat: pickle runs and console logs
- fix: no more len checks
- fix: remove pycache
- feat: advays agents
- Merge branch 'main' into advay
- fix: response ingestion

## Key source files (fetched from GitHub, selected and truncated for size)

### prompts.md

```markdown
# Detailed Example Prompts by Agent

## HR Agent
1. "My Workday system did not update my overtime hours for the past two weeks; can you review my work log and advise on how to correct the records in the HR portal?"
2. "Could you provide detailed information about the new healthcare benefits package, including co-pay details, network providers, and enrollment deadlines?"
3. "I need a step-by-step guide on how to request paid leave through the new HR self-service portal, including any necessary approvals."
4. "Please retrieve and display my three most recent pay stubs from the internal payroll system with complete breakdowns."
5. "I want to file a formal complaint regarding workplace harassment; what is the detailed process and required documentation?"
6. "Can you guide me on how to update my direct deposit information, including verifying my new bank account details in Workday?"
7. "Please list all available career development and training programs for employees along with registration deadlines."
8. "Who should I contact for detailed questions about my 401(k) contributions and investment options, and what are their contact details?"
9. "I require an official employment verification letter for a mortgage application; what specific information will it include and how do I request it?"
10. "Could you explain the updated remote work policy in detail, including eligibility criteria and the application process for telecommuting?"

## Code Research Agent
1. "Provide a Python script that fetches live weather data from the OpenWeatherMap API, parses the JSON response, and logs errors with detailed comments."
2. "Write a JavaScript function that uses advanced regex to validate complex email formats, including internationalized domains and subdomains, with inline documentation."
3. "Draft a SQL query that retrieves the top 10 customers by revenue for Q2, incorporating date filtering and regional grouping, and include comments on each join."
4. "Create a Python utility that batch renames files by appending their creation date; include error handling and logging for files that cannot be renamed."
5. "Develop a Dockerfile for a Node.js Express application that connects securely to a PostgreSQL database; ensure environment variables and volumes are clearly defined."
6. "Generate a React component for a search bar that supports real-time suggestions using an external API, with debounce functionality and explanatory comments."
7. "Write a Terraform script to provision an AWS EC2 instance with a custom security group, including tags and keypair configurations, with detailed inline explanations."
8. "Develop a Jest test suite for a user authentication module that covers both valid and invalid login scenarios, with clear descriptions for each test case."
9. "Create a Kubernetes deployment YAML file for a Flask application, detailing autoscaling settings, resource limits, and environment variables for a production setup."
10. "Develop a Python web scraper that extrac
[truncated — 41974 more characters]
```

### app.py

```python
from flask import Flask, render_template, request, jsonify, Response
from flask_cors import CORS
from run_agents import run_agent, run_planning_agent
import json
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})  # Enable CORS for all routes

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/chat', methods=['POST'])
def chat():
    try:
        print('starting stream_router')
        from stream_router import StreamRouter
        import pickle
        data = request.get_json()
        message = data.get('message', '')
        # Load the state and create a new router
        print('message received')
        with open('router_states/router_state_12.pkl', 'rb') as f:
            state = pickle.load(f)
            
        new_router = StreamRouter(
            state['agents'],
            embedding_dim=state['embedding_dim'],
            learning_rate=state['learning_rate'],
            min_samples=20
        )
        new_router.clusters = state['clusters']
        new_router.agent_embeddings = state['agent_embeddings']
        predicted_agent, agent_probabilities = new_router.inference(message)
        agent_probabilities = sorted(agent_probabilities.items(), key=lambda x: x[1], reverse=True)
        print('predicted_agent: ', predicted_agent)
        print('agent_probabilities: ', agent_probabilities)

        def generate():
            try:
                # First message - prediction
                yield json.dumps({
                    "type": "prediction",
                    "content": str(predicted_agent)  # Ensure it's a string
                }, ensure_ascii=False).strip() + '\n'
                
                # Status message
                yield json.dumps({
                    "type": "status",
                    "content": f"Running {str(predicted_agent)} agent..."
                }, ensure_ascii=False).strip() + '\n'
                
                # Run the agent
                # If first and second agent have similar probabilities, run planning agent
                # Cuttoff number thats agent probability that's 0.04 less than the highest probability
                threshold = 0.04
                cutoff = agent_probabilities[0][1] - threshold
                if len(agent_probabilities) > 1 and agent_probabilities[0][1] - agent_probabilities[1][1] < threshold:
                    result = run_planning_agent([agent_probabilities[x][0] for x in range(len(agent_probabilities)) if agent_probabilities[x][1] > cutoff], message)
                else:
                    result = run_agent(predicted_agent, message)
                
                # Ensure result is JSON-safe
                try:
                    # Wait for the agent to finish running
                    result_content = str(result.raw)
                    yield json.dumps({
                        "type": "result",  
                        "content": result_content
                    }, ensure_ascii=False).strip() + '\n'
                except Exception as e:
                    yield json.dumps({
                        "type": "error",
                        "content": f"Error processing result: {str(e)}"
                    }, ensure_ascii=False).strip() + '\n'
                    
            except Exception as e:
                yield json.dumps({
                    "type": "error",
                    "content": f"Stream error: {str(e)}"
                }, ensure_ascii=False).strip() + '\n'

        return Response(generate(), mimetype='application/x-ndjson')
    except Exception as e:
        return jsonify({"status": "error", "message": str(e)}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001, debug=True)  # Changed port to 5001
```

### mistral_embed.py

```python
import os
from typing import List
import requests

class MistralEmbed:
    def __init__(self, api_key: str = None):
        self.api_key = api_key or os.getenv('MISTRAL_API_KEY')
        if not self.api_key:
            raise ValueError("MISTRAL_API_KEY not found in environment variables")
        
        self.base_url = "https://api.mistral.ai/v1"
        self.headers = {
            "Authorization": f"Bearer {self.api_key}",
            "Content-Type": "application/json"
        }

    def embed_query(self, text: str) -> List[float]:
        """Get embedding for a single query."""
        response = requests.post(
            f"{self.base_url}/embeddings",
            headers=self.headers,
            json={"model": "mistral-embed", "input": text}
        )
        response.raise_for_status()
        return response.json()["data"][0]["embedding"]
```

### routing.py

```python
import torch
import torch.nn.functional as F
from clustering import main



def initialize(clusters, agents):
    cluster_vectors = {i: torch.tensor(clusters[label][-1], dtype=torch.float32, requires_grad=True) 
                      for i, label in enumerate(clusters)}
    # Create a dictionary with random Gaussian vectors for each agent
    agent_vectors = {i: torch.randn(768, requires_grad=True) 
                    for i in range(len(agents))}
    
    return cluster_vectors, agent_vectors

def get_distribution(cluster_vector, agent_vectors, temperature=0.1):
    # Calculate cosine similarities
    similarities = torch.stack([
        F.cosine_similarity(cluster_vector.unsqueeze(0), 
                          agent_vec.unsqueeze(0)) 
        for agent_vec in agent_vectors.values()
    ])
    # Convert to logits/probabilities via softmax
    probs = F.softmax(similarities / temperature, dim=0)
    return probs

def kl_divergence(p, q):
    # Using PyTorch's built-in KL divergence
    return F.kl_div(q.log(), p, reduction='sum')

def learn_embeddings(cluster_vectors, agent_vectors, ground_truth, epochs=100, learning_rate=0.01, temperature=0.1, alpha=0.3):
    """
    ground_truth: dict mapping cluster_id to (agent_indices, probabilities)
                 where probabilities are the target distribution over agents
    Args:
        alpha: Regularization strength for cluster embedding deviation
    """
    # Store original cluster vectors for regularization
    original_cluster_vectors = {
        k: v.clone().detach() 
        for k, v in cluster_vectors.items()
    }
    
    n_agents = len(agent_vectors)
    optimizer = torch.optim.Adam(
        list(cluster_vectors.values()) + list(agent_vectors.values()), 
        lr=learning_rate
    )
    
    for epoch in range(epochs):
        total_loss = 0
        
        # For each cluster
        for cluster_id, cluster_vec in cluster_vectors.items():
            optimizer.zero_grad()
            
            # Get ground truth distribution
            true_agents, true_probs = ground_truth[cluster_id]
            
            # Create full probability distribution (zeros for non-top-4 agents)
            true_distribution = torch.zeros(n_agents)
            for agent_idx, prob in zip(true_agents, true_probs):
                true_distribution[agent_idx] = prob
            
            # Get current predicted distribution
            pred_distribution = get_distribution(cluster_vec, agent_vectors, temperature)
            
            # Calculate KL divergence loss
            kl_loss = kl_divergence(true_distribution, pred_distribution)
            
            # Add regularization term for cluster embedding
            cluster_reg = F.mse_loss(cluster_vec, original_cluster_vectors[cluster_id])
            loss = kl_loss + alpha * cluster_reg
            
            total_loss += loss.item()
            
            # Backward pass and optimization
            loss.backward()
            optimizer.step()
            
            # Normalize vectors after optimization
            with torch.no_grad():
                for vec in agent_vectors.values():
                    vec.div_(vec.norm())
                cluster_vec.div_(cluster_vec.norm())
            
        if epoch % (epochs //10) == 0:
            print(f"Epoch {epoch}, Average Loss: {total_loss/len(cluster_vectors):.4f}")
    
    return cluster_vectors, agent_vectors

def inference(cluster_vector, agent_vectors, temperature=0.1):
    """
    Returns the probability distribution over agents for a given cluster
    """
    with torch.no_grad():
        probs = get_distribution(cluster_vector, agent_vectors, temerature=temperature)
    return probs.numpy()


if __name__ == '__main__':
    clusters = main()
    agents = [i for i in range(3)]
    # Example usage
    cluster_vectors, agent_vectors = initialize(clusters, agents)
    trained_cluster_vectors, trained_agent_vectors = learn_embeddings(
        cluster_vectors, 
        agent_vectors,  
        ground_truth
    )

    # For inference
    probs = inference(trained_cluster_vectors[0], trained_agent_vectors)


```

### clustering.py

```python
from sentence_transformers import SentenceTransformer
from sklearn.cluster import KMeans
from typing import List, Dict
import numpy as np
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt

def embed_sentence(sentences: str | List[str], model_name: str = "bert-base-nli-mean-tokens", batch_size: int = 32):
    """
    Embeds one or more sentences using a BERT-based model from Hugging Face's Sentence-Transformers.
    
    :param sentences: Single sentence or list of sentences to be embedded
    :param model_name: The name of the pre-trained model to use
    :param batch_size: Batch size for processing multiple sentences
    :return: A vector embedding or array of embeddings
    """
    model = SentenceTransformer(model_name)
    embeddings = model.encode(sentences, batch_size=batch_size, show_progress_bar=True)
    return embeddings

def cluster_sentences(sentences: List[str], n_clusters: int = 5, model_name: str = "bert-base-nli-mean-tokens", show_graph: bool = False) -> Dict[int, List[str]]:
    """
    Clusters sentences using their embeddings and K-Means clustering.
    Automatically determines optimal number of clusters using elbow method.
    
    :param sentences: List of sentences to cluster
    :param n_clusters: Maximum number of clusters to create (default: 2)
    :param model_name: The name of the pre-trained model to use
    :param show_graph: If True, displays a 2D visualization of the clusters (default: False)
    :return: Dictionary mapping cluster IDs to lists of sentences
    """
    # Create embeddings for all sentences in one batch
    embeddings = np.array(embed_sentence(sentences, model_name))
    
    # Find optimal number of clusters using elbow method
    inertias = []
    # K = range(1, min(n_clusters + 1, len(sentences)))
    
    # for k in K:
    #     kmeans = KMeans(n_clusters=k, random_state=42)
    #     kmeans.fit(embeddings)
    #     inertias.append(kmeans.inertia_)
    
    # # Calculate the rate of change in inertia
    # elbow_point = 1  # Default to 1 cluster if no clear elbow
    # if len(K) > 2:
    #     changes = np.diff(inertias)
    #     # Find point where the rate of improvement slows down significantly
    #     threshold = np.mean(np.abs(changes)) * 0.5  # Adjust threshold as needed
    #     for i, change in enumerate(changes):
    #         if abs(change) < threshold:
    #             elbow_point = i + 1
    #             break
    
    # optimal_clusters = min(elbow_point, n_clusters)
    optimal_clusters = n_clusters
    # Perform K-means clustering with optimal number of clusters
    kmeans = KMeans(n_clusters=n_clusters, random_state=42, max_iter = 4000, tol = 10e-7)
    cluster_labels = kmeans.fit_predict(embeddings)
    
    # If show_graph is True, create and display the visualization
    if show_graph:
        # Reduce dimensionality to 2D using t-SNE
        perplexity = min(30, len(sentences) - 1)  # Adaptive perplexity
        tsne = TSNE(n_components=2, random_state=42, perplexity=perplexity)
        embeddings_2d = tsne.fit_transform(embeddings)
        
        # Create the scatter plot
        plt.figure(figsize=(10, 6))
        for i in range(optimal_clusters):
            # Plot points for each cluster with different colors
            mask = cluster_labels == i
            plt.scatter(embeddings_2d[mask, 0], embeddings_2d[mask, 1], label=f'Cluster {i}')
        
        plt.title(f'Sentence Clusters Visualization (Optimal clusters: {optimal_clusters})')
        plt.legend()
        plt.show()
    
    # Group sentences by cluster
    clusters = {i: [] for i in range(optimal_clusters)}
    i=0
    for sentence, label in zip(sentences, cluster_labels):
        clusters[label].append([sentence,embeddings[i]])
        i+=1

    for label in range(optimal_clusters):
        mask = cluster_labels == label
        cluster_embeddings = embeddings[mask]
        avg_embedding = np.mean(cluster_embeddings, axis=0)
        clusters[label].append(avg_embedding)
    return clusters

# Example usage
sentence = "This is a sample sentence."
vector = embed_sentence(sentence)
print(vector.shape)  # Output: (768,)

def main():
    test_sentences = [
        "The cat sits on the mat",
        "The cat sits on the bed",
        "The cat sits on the table",
        "Neural networks process data",
        "Neural networks process lots of data",
        "Neural networks process information",
        "The dog runs on the mat"
    ]
    
    clusters = cluster_sentences(test_sentences, show_graph=False)
    return clusters 



```

### run_agents.py

```python
from agents.calendar_agent import prompt_calendar
#from agents.codegen_agent import CodegenTool
from agents.customer_service import prompt_CS
from agents.database_agent import database_agent
from agents.executive_assistant import prompt_EA
from agents.hr import prompt_hr
from agents.legal import legal_prompt
from agents.perplexity import prompt_perplexity
from agents.software_qa import software_prompt
from agents.web_automation import WebAutomationTool
from agents.coding_agent import prompt_coding

def run_agent(agent, prompt):
    if agent=="HR Agent":
        return prompt_hr(prompt)

    if agent=="Code Generation Agent":
        return prompt_coding(prompt)
    
    if agent=="Web Search Agent":
        return prompt_perplexity(prompt)

    if agent=="Customer Service Agent":
        return prompt_CS(prompt)

    if agent=="Database Agent":
        return database_agent(prompt)
    if agent== "Executive Assistant Agent":
        return prompt_EA(prompt)
    if agent=="Legal Agent":
        return legal_prompt(prompt)
    if agent=="Software QA Agent":
        return software_prompt(prompt)
    if agent=="Web Automation Agent":
        return WebAutomationTool

def run_planning_agent(agents, prompt):
    """
    Execute a planning agent that creates and executes a plan based on the given prompt.
    
    Args:
        agents (dict): A dictionary mapping agent names to their function implementations
        prompt (str): The user's input prompt describing the task
        
    Returns:
        dict: A dictionary containing the plan, execution results, and final output
    """
    def create_plan(prompt):
        """Generate a structured plan from the input prompt."""
        planning_prompt = f"""
        Create a step-by-step plan to accomplish: {prompt}
        
        Format each step as:
        1. [Agent]: Action description
        
        Only use available agents: {agents}
        """
        
        # For now, we'll use a simple planning strategy
        # In a real implementation, this could use an LLM or other planning system
        plan = []
        
        # Basic parsing of the prompt to create steps
        words = planning_prompt.lower().split()
        for agent_name in agents:
            if agent_name.lower() in words:
                plan.append(f"{agent_name}: Process input related to {agent_name}")
                
        if not plan:
            # Default to using the first available agent if no specific matches
            first_agent = agents[0]
            plan.append(f"{first_agent}: Process entire input")
            
        return plan

    def execute_plan(plan):
        """Execute each step of the plan using the appropriate agents."""
        results = []
        for step in plan:
            try:
                # Parse the agent name from the step
                agent_name = step.split(':')[0].strip()
                
                # Get the agent function
                if agent_name not in agents:
                    raise ValueError(f"Unknown agent: {agent_name}")
                    
                agent_func = run_agent(agent_name)
                
                # Execute the agent with the original prompt
                # In a more sophisticated implementation, we might parse specific
                # instructions for each agent from the step description
                result = agent_func(agent_name, prompt)
                
                results.append({
                    'step': step,
                    'agent': agent_name,
                    'status': 'success',
                    'output': result
                })
            except Exception as e:
                results.append({
                    'step': step,
                    'agent': agent_name,
                    'status': 'error',
                    'error': str(e)
                })
                
        return results

    def combine_results(results):
        """Combine the results from all executed steps into a final output."""
        successful_outputs = [
            result['output'] 
            for result in results 
            if result['status'] == 'success'
        ]
        
        # In a more sophisticated implementation, this could use an agent to
        # intelligently combine and summarize the results
        return '\n'.join(successful_outputs)

    # Main execution flow
    try:
        # 1. Create the plan
        plan = create_plan(prompt)
        
        # 2. Execute the plan
        execution_results = execute_plan(plan)
        
        # 3. Combine results
        final_output = combine_results(execution_results)
        
        return {
            'status': 'success',
            'plan': plan,
            'execution_results': execution_results,
            'raw': final_output
        }
    except Exception as e:
        return {
            'status': 'error',
            'error': str(e)
        }



```

### conda_environment.yml

```yaml
name: ariadne
channels:
  - conda-forge
  - defaults
dependencies:
  - appnope=0.1.4=pyhd8ed1ab_1
  - asttokens=3.0.0=pyhd8ed1ab_1
  - bzip2=1.0.8=h80987f9_6
  - ca-certificates=2025.1.31=hf0a4a13_0
  - comm=0.2.2=pyhd8ed1ab_1
  - debugpy=1.8.11=py311h313beb8_0
  - decorator=5.1.1=pyhd8ed1ab_1
  - exceptiongroup=1.2.2=pyhd8ed1ab_1
  - expat=2.6.4=h313beb8_0
  - ipykernel=6.29.5=pyh57ce528_0
  - ipython=8.32.0=pyh907856f_0
  - jedi=0.19.2=pyhd8ed1ab_1
  - jupyter_client=8.6.3=pyhd8ed1ab_1
  - jupyter_core=5.7.2=pyh31011fe_1
  - libcxx=14.0.6=h848a8c0_0
  - libffi=3.4.4=hca03da5_1
  - libmpdec=4.0.0=h80987f9_0
  - libsodium=1.0.18=h27ca646_1
  - matplotlib-inline=0.1.7=pyhd8ed1ab_1
  - ncurses=6.4=h313beb8_0
  - nest-asyncio=1.6.0=pyhd8ed1ab_1
  - openssl=3.4.1=h81ee809_0
  - packaging=24.2=pyhd8ed1ab_2
  - parso=0.8.4=pyhd8ed1ab_1
  - pexpect=4.9.0=pyhd8ed1ab_1
  - pickleshare=0.7.5=pyhd8ed1ab_1004
  - pip=25.0=py311hca03da5_0
  - platformdirs=4.3.6=pyhd8ed1ab_1
  - prompt-toolkit=3.0.50=pyha770c72_0
  - psutil=5.9.0=py311h80987f9_1
  - ptyprocess=0.7.0=pyhd8ed1ab_1
  - pure_eval=0.2.3=pyhd8ed1ab_1
  - pygments=2.19.1=pyhd8ed1ab_0
  - python=3.11.11=hb885b13_0
  - python-dateutil=2.9.0.post0=pyhff2d567_1
  - pyzmq=26.2.0=py311h313beb8_0
  - readline=8.2=h1a28f6b_0
  - setuptools=75.8.0=py311hca03da5_0
  - six=1.17.0=pyhd8ed1ab_0
  - sqlite=3.45.3=h80987f9_0
  - stack_data=0.6.3=pyhd8ed1ab_1
  - tk=8.6.14=h6ba3021_0
  - tornado=6.4.2=py311h80987f9_0
  - traitlets=5.14.3=pyhd8ed1ab_1
  - typing_extensions=4.12.2=pyha770c72_1
  - wcwidth=0.2.13=pyhd8ed1ab_1
  - wheel=0.45.1=py311hca03da5_0
  - xz=5.6.4=h80987f9_1
  - zeromq=4.3.5=h313beb8_0
  - zipp=3.21.0=pyhd8ed1ab_1
  - zlib=1.2.13=h18a0788_1
  - pip:
      - aiohappyeyeballs==2.4.6
      - aiohttp==3.11.12
      - aiosignal==1.3.2
      - annotated-types==0.7.0
      - anthropic==0.39.0
      - anyio==4.8.0
      - appdirs==1.4.4
      - asgiref==3.8.1
      - attrs==25.1.0
      - auth0-python==4.8.0
      - backoff==2.2.1
      - bcrypt==4.2.1
      - blinker==1.9.0
      - build==1.2.2.post1
      - cachetools==5.5.1
      - certifi==2025.1.31
      - cffi==1.17.1
      - charset-normalizer==3.4.1
      - chroma-hnswlib==0.7.6
      - chromadb==0.6.3
      - click==8.1.8
      - coloredlogs==15.0.1
      - composio-core==0.7.2
      - composio-crewai==0.7.2
      - composio-langchain==0.7.2
      - crewai==0.102.0
      - cryptography==44.0.1
      - dataclasses-json==0.6.7
      - deprecated==1.2.18
      - distro==1.9.0
      - docstring-parser==0.16
      - durationpy==0.9
      - et-xmlfile==2.0.0
      - executing==2.2.0
      - fastapi==0.115.8
      - filelock==3.17.0
      - flask==3.1.0
      - flask-cors==5.0.0
      - flatbuffers==25.2.10
      - frozenlist==1.5.0
      - fsspec==2025.2.0
      - google-auth==2.38.0
      - googleapis-common-protos==1.67.0
      - greenlet==3.1.1
      - grpcio==1.70.0
      - h11==0.14.0
      - httpcore==1.0.7
      - httptools==0.6.4
      - httpx==0.27.2
      - httpx-sse==0.4.0
      - huggingface-hub==0.28.1
      - humanfriendly==10.0
      - idna==3.10
      - importlib-metadata==8.5.0
      - importlib-resources==6.5.2
      - inflection==0.5.1
      - instructor==1.7.2
      - itsdangerous==2.2.0
      - jinja2==3.1.5
      - jiter==0.8.2
      - joblib==1.4.2
      - json-repair==0.36.1
      - json5==0.10.0
      - jsonpatch==1.33
      - jsonpickle==4.0.1
      - jsonpointer==3.0.0
      - jsonref==1.1.0
      - jsonschema==4.23.0
      - jsonschema-specifications==2024.10.1
      - kubernetes==32.0.0
      - langchain==0.3.18
      - langchain-community==0.3.17
      - langchain-core==0.3.35
      - langchain-openai==0.3.6
      - langchain-text-splitters==0.3.6
      - langchainhub==0.1.21
      - langsmith==0.3.8
      - litellm==1.60.2
      - markdown-it-py==3.0.0
      - markupsafe==3.0.2
      - marshmallow==3.26.1
      - mdurl==0.1.2
      - mmh3==5.1.0
      - monotonic==1.6
      - mpmath==1.3.0
      - multidict==6.1.0
      - mypy-extensions==1.0.0
      - networkx==3.4.2
      - numpy==1.26.4
      - oauthlib==3.2.2
      - onnxruntime==1.20.1
      - openai==1.63.0
      - openpyxl==3.1.5
      - opentelemetry-api==1.30.0
      - opentelemetry-exporter-otlp-proto-common==1.30.0
      - opentelemetry-exporter-otlp-proto-grpc==1.30.0
      - opentelemetry-exporter-otlp-proto-http==1.30.0
      - opentelemetry-instrumentation==0.51b0
      - opentelemetry-instrumentation-asgi==0.51b0
      - opentelemetry-instrumentation-fastapi==0.51b0
      - opentelemetry-proto==1.30.0
      - opentelemetry-sdk==1.30.0
      - opentelemetry-semantic-conventions==0.51b0
      - opentelemetry-util-http==0.51b0
      - orjson==3.10.15
      - overrides==7.7.0
      - pandas==2.2.3
      - paramiko==3.5.1
      - pdfminer-six==20231228
      - pdfplumber==0.11.5
      - pillow==11.1.0
      - playwright==1.50.0
      - posthog==3.13.0
      - propcache==0.2.1
      - protobuf==5.29.3
      - pyasn1==0.6.1
      - pyasn1-modules==0.4.1
      - pycparser==2.22
      - pydantic==2.10.6
      - pydantic-core==2.27.2
      - pydantic-settings==2.7.1
      - pyee==12.1.1
      - pyjwt==2.10.1
      - pynacl==1.5.0
      - pypdfium2==4.30.1
      - pyperclip==1.9.0
      - pypika==0.48.9
      - pyproject-hooks==1.2.0
      - pysher==1.0.8
      - python-dotenv==1.0.1
      - pytz==2025.1
      - pyvis==0.3.2
      - pyyaml==6.0.2
      - referencing==0.36.2
      - regex==2024.11.6
      - requests==2.32.3
      - requests-oauthlib==2.0.0
      - requests-toolbelt==1.0.0
      - rich==13.9.4
      - rpds-py==0.22.3
      - rsa==4.9
      - safetensors==0.5.2
      - scikit-learn==1.6.1
      - scipy==1.15.1
      - scrapybara==2.2.7
      - semver==3.0.4
      - sentence-transformers==3.4.1
      - sentry-sdk==2.21.0
      - shellingham==1.5.4
      - sniffio==1.3.1
      - sqlalchemy==2.0.38
      - starlette==0.45.3
      - sympy==1.13.1
      - tenacity==9.0.0
      - threadpoolctl==3.5
[truncated — 553 more characters]
```

### prompts.py

```python
# This file stores the training updates (a list of prompt-agent pairs)
# and the test prompts for the StreamRouter.

TRAIN_UPDATES = [
    # Math Agent (8)
    ("Calculate the derivative of sin(x) * e^x using symbolic differentiation.", "Math Agent"),
    ("Solve the integral of x^2 * ln(x) dx and simplify the result.", "Math Agent"),
    ("Find the eigenvalues of the matrix [[1,2,3],[0,1,4],[5,6,0]].", "Math Agent"),
    ("Determine the limit of (1 + 1/n)^n as n approaches infinity.", "Math Agent"),
    ("Prove the Pythagorean theorem using geometric methods.", "Math Agent"),
    ("Calculate the volume of a torus using triple integrals.", "Math Agent"),
    ("Find the general solution to the differential equation dy/dx = x*y.", "Math Agent"),
    ("Determine the convergence of the infinite series Σ(1/n^2) from n=1 to ∞.", "Math Agent"),
    
    # Coding Agent (8)
    ("Develop a Python script that scrapes a webpage using BeautifulSoup.", "Coding Agent"),
    ("Write a JavaScript function to debounce user input effectively.", "Coding Agent"),
    ("Refactor legacy PHP code into a modern MVC framework.", "Coding Agent"),
    ("Implement a RESTful API in Node.js with comprehensive error handling.", "Coding Agent"),
    ("Create a Python decorator for caching function results.", "Coding Agent"),
    ("Implement a binary search tree with balancing in Java.", "Coding Agent"),
    ("Design a scalable microservices architecture using Docker.", "Coding Agent"),
    ("Write a React component for handling form validation.", "Coding Agent"),
    
    # HR Agent (8)
    ("Draft an email scheduling a job interview with a promising candidate.", "HR Agent"),
    ("Outline best practices for remote employee engagement and retention.", "HR Agent"),
    ("Describe effective conflict resolution strategies in the workplace.", "HR Agent"),
    ("Propose a comprehensive benefits package for mid-level tech staff.", "HR Agent"),
    ("Create an onboarding plan for new remote employees.", "HR Agent"),
    ("Design a performance review template for software engineers.", "HR Agent"),
    ("Develop guidelines for promoting diversity and inclusion in hiring.", "HR Agent"),
    ("Write a policy for handling workplace harassment complaints.", "HR Agent"),
    
    # Deep Research (8)
    ("Summarize the latest advancements in quantum computing and their implications.", "Deep Research"),
    ("Analyze the impact of climate change on global economic trends with recent studies.", "Deep Research"),
    ("Critically review recent literature on artificial general intelligence.", "Deep Research"),
    ("Examine the sociopolitical effects of cyber warfare in modern nation-states.", "Deep Research"),
    ("Review emerging technologies in renewable energy storage systems.", "Deep Research"),
    ("Analyze recent developments in CRISPR gene editing technology.", "Deep Research"),
    ("Investigate the impact of social media on democratic processes.", "Deep Research"),
    ("Study the effects of microplastics on marine ecosystems.", "Deep Research"),
    
    # Image Gen (8)
    ("Generate an image prompt for a surreal landscape with floating islands.", "Image Gen"),
    ("Describe a futuristic cityscape at sunset with neon lights and flying vehicles.", "Image Gen"),
    ("Create a prompt for an artistic cyberpunk-themed portrait.", "Image Gen"),
    ("Outline a scene featuring an enchanted forest with glowing flora and mythical creatures.", "Image Gen"),
    ("Design a prompt for a steampunk-inspired mechanical dragon.", "Image Gen"),
    ("Create a detailed description for an underwater city scene.", "Image Gen"),
    ("Generate a prompt for a post-apocalyptic urban landscape.", "Image Gen"),
    ("Describe an alien marketplace with exotic creatures and architecture.", "Image Gen"),
    
    # General Chat (8)
    ("What's the weather forecast for this weekend in New York City?", "General"),
    ("Can you recommend some must-visit attractions in Tokyo?", "General"),
    ("How do I write a professional email to reschedule a meeting?", "General"),
    ("What are some good indoor activities for a rainy day?", "General"),
    ("Could you suggest some popular restaurants in San Francisco?", "General"),
    ("What's the best time of year to visit Paris?", "General"),
    ("How should I format a formal business email signature?", "General"),
    ("What are some fun weekend activities to do with family?", "General"),
    
    # GPT o3-mini-high (6)
    ("Take your time to develop a comprehensive strategy for reducing carbon emissions in urban areas.", "GPT o3-mini-high"),
    ("Break down the complex challenge of improving public education outcomes into actionable steps.", "GPT o3-mini-high"),
    ("Think carefully about all aspects of implementing a city-wide composting program and outline a strategy.", "GPT o3-mini-high"),
    ("Develop a methodical approach to analyze and improve supply chain resilience.", "GPT o3-mini-high"),
    ("Take time to consider and break down the challenge of reducing hospital wait times.", "GPT o3-mini-high"),
    ("Think deeply about strategies to increase voter turnout and civic engagement.", "GPT o3-mini-high"),
    ("Carefully analyze and break down approaches to improve mental health services accessibility.", "GPT o3-mini-high"),
    ("Develop a systematic strategy for transitioning a large organization to renewable energy.", "GPT o3-mini-high"),
    
    # Chemistry RAG (8)
    ("Explain the reaction mechanism of esterification between acetic acid and ethanol.", "Chemistry RAG"),
    ("Describe the periodic trends observed among the halogen elements.", "Chemistry RAG"),
    ("Discuss the thermodynamic principles underlying chemical equilibria.", "Chemistry RAG"),
    ("Analyze the molecular structure of caffeine and its pharmacological effects.", "Chemistry RAG"),
    ("Explain the concept of chirality in organic molecules.", "Chemistry RAG"),
    ("Describe the mechanism of photosynthesis in detai
[truncated — 624 more characters]
```

### agents/perplexity.py

```python
from langchain_community.chat_models import ChatPerplexity
from langchain_core.prompts import ChatPromptTemplate
import os

def prompt_perplexity(prompt):
    chat = ChatPerplexity(api_key=os.getenv("pplx_api_key"), temperature=0.7, model="llama-3.1-sonar-small-128k-online")
    system = "You are a helpful assistant."
    human = "{input}"
    prompt_template = ChatPromptTemplate.from_messages([("system", system), ("human", human)])

    chain = prompt_template | chat
    response = chain.invoke({"input": prompt})
    return response.content


```

### agents/hr.py

```python
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI

def prompt_hr(prompt):
    hr_agent = Agent(
        role="Human Resources Agent",
        goal="""You are a human resources agent whose goal is to handle disputes efficiently and correctly.

        Whenever given a scenario, handle and solve it properly like a HR agent would.
        
        """,
        backstory=("You have always loved helping people."
        ),
        verbose=True,
        allow_delegation=False,
        llm=ChatOpenAI(),
    )
    task = Task(
        description="Solve the given issue using your HR skills: " + prompt,
        agent=hr_agent,
        expected_output=""
    )

    my_crew = Crew(agents=[hr_agent], tasks=[task], verbose=True)

    result = my_crew.kickoff()
    return result
```

[36 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]