Agents Working Together › A Simple Collaboration Scenario

Michael BrenndoerferJuly 25, 20253 min read
AI Agent HandbookAll chapters
Part 10 of 15Multi-Agent Systems - Teamwork Among AIs
Chapter 27Agents Working Together › A Simple Collaboration Scenario
Reading section 3 of 10 · A Simple Collaboration Scenario · 3 minSection 3 of 10 · 3 min

Book contents

Section 3 of 10 · 3 min read

Agents Working Together › A Simple Collaboration ScenarioOne section · Sections in this chapter3 / 10 ↓

Let's extend our personal assistant with a basic multi-agent setup. We'll create two specialized agents:

  • User Interface Agent: Handles all interaction with you, understanding your requests and presenting results
  • Task Execution Agent: Works in the background on complex tasks that might take time

Here's how they might collaborate on a research request:

In[3]:
Code
## Using Claude Sonnet 4.5 for its superior agent reasoning and coordination
from anthropic import Anthropic
import json

client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))

## User Interface Agent - handles conversation
def ui_agent(user_message, task_status=None):
    """
    The UI agent talks to the user and coordinates with the task agent.
    """
    system_prompt = """You are a friendly assistant that helps users with their requests.
    When a user asks for something that requires research or complex work, 
    you should acknowledge it and let them know the task agent is working on it.
    When you receive results from the task agent, present them clearly to the user."""
    
    messages = [{"role": "user", "content": user_message}]
    
    if task_status:
        # Include status update from task agent
        messages.append({
            "role": "assistant", 
            "content": f"Task update: {task_status}"
        })
    
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        system=system_prompt,
        messages=messages
    )
    
    return response.content[0].text

## Task Execution Agent - does the heavy lifting
def task_agent(task_description):
    """
    The task agent focuses on executing complex tasks without worrying about user interaction.
    """
    system_prompt = """You are a task execution specialist. 
    You receive task descriptions and work through them methodically.
    Focus on accuracy and thoroughness. Return structured results."""
    
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=2048,
        system=system_prompt,
        messages=[{"role": "user", "content": task_description}]
    )
    
    return response.content[0].text

## Coordination function
def handle_user_request(user_input):
    """
    Coordinates between UI and task agents.
    """
    # Step 1: UI agent receives and acknowledges request
    ui_response = ui_agent(user_input)
    print(f"UI Agent: {ui_response}")
    
    # Step 2: Determine if we need the task agent
    if "research" in user_input.lower() or "analyze" in user_input.lower():
        print("\n[System: Delegating to task agent...]\n")
        
        # Step 3: Task agent works on it
        task_result = task_agent(user_input)
        print(f"Task Agent: {task_result}")
        
        # Step 4: UI agent presents results
        final_response = ui_agent(
            "Present these results to the user in a friendly way",
            task_status=task_result
        )
        print(f"\nUI Agent: {final_response}")
    
    return ui_response

## Example usage
handle_user_request("Research the top 3 programming languages for data science and explain why")
Out[3]:
Console
UI Agent: I'll research the top 3 programming languages for data science and explain why they're preferred. Let me gather that information for you.

---

Based on current industry trends and usage, here are the **top 3 programming languages for data science**:

## 1. **Python** 🐍
**Why it's #1:**
- **Rich ecosystem**: Extensive libraries like NumPy, Pandas, Scikit-learn, TensorFlow, and PyTorch
- **Easy to learn**: Simple, readable syntax makes it accessible for beginners
- **Versatile**: Works for data analysis, machine learning, deep learning, and web deployment
- **Strong community**: Massive support, tutorials, and active development
- **Industry standard**: Most widely adopted in both academia and industry

## 2. **R** 📊
**Why it's popular:**
- **Statistical focus**: Built specifically for statistical computing and data analysis
- **Visualization**: Exceptional plotting capabilities with ggplot2 and other packages
- **Specialized packages**: Over 18,000+ packages on CRAN for specific statistical methods
- **Academic roots**: Widely used in research and statistical modeling
- **Best for**: Statistical analysis, biostatistics, and academic research

## 3. **SQL** 🗄️
**Why it's essential:**
- **Data retrieval**: The standard language for querying databases
- **Universal skill**: Works across all major database systems (MySQL, PostgreSQL, etc.)
- **Big data**: Essential for working with large datasets stored in databases
- **Integration**: Often used alongside Python or R for complete data workflows
- **Job requirement**: Nearly every data science position requires SQL knowledge

**The verdict**: Most data scientists use a combination of these languages—Python or R for analysis and modeling, and SQL for data extraction and management.

[System: Delegating to task agent...]
Task Agent: # Top 3 Programming Languages for Data Science

## 1. **Python**

### Why It Dominates:
- **Rich Ecosystem**: Comprehensive libraries including NumPy, Pandas, Scikit-learn, TensorFlow, PyTorch, and Matplotlib
- **Ease of Learning**: Clean, readable syntax makes it accessible for beginners and researchers without CS backgrounds
- **Community Support**: Largest data science community with extensive documentation, tutorials, and Stack Overflow support
- **Versatility**: Handles everything from data cleaning to machine learning to deployment
- **Industry Standard**: Most widely adopted in both academia and industry (70%+ of data scientists use it)

### Key Use Cases:
- Machine learning and deep learning
- Data visualization
- Statistical analysis
- Web scraping and automation

---

## 2. **R**

### Why It Excels:
- **Statistical Foundation**: Built by statisticians for statistics, with unmatched statistical modeling capabilities
- **Visualization Power**: ggplot2 and other packages create publication-quality graphics
- **Specialized Packages**: Over 18,000 CRAN packages for specific statistical methods
- **Academic Preference**: Dominant in research institutions and biostatistics
- **Data Manipulation**: dplyr and tidyverse provide elegant data wrangling tools

### Key Use Cases:
- Statistical analysis and hypothesis testing
- Biostatistics and clinical trials
- Academic research
- Advanced data visualization

---

## 3. **SQL**

### Why It's Essential:
- **Data Access**: The universal language for querying databases where data actually lives
- **Performance**: Optimized for handling large-scale data retrieval and aggregation
- **Universal Skill**: Required in virtually every data role; works across all major database systems
- **Integration**: Works alongside Python/R for complete data pipelines
- **Business Intelligence**: Powers dashboards, reports, and analytics platforms

### Key Use Cases:
- Extracting data from relational databases
- Data warehousing and ETL processes
- Initial data exploration and filtering
- Production data pipelines

---

## Summary Recommendation:
- **Start with Python** for the broadest applicability
- **Add R** if working in statistics-heavy or academic environments
- **Master SQL** as a fundamental skill—it's non-negotiable for accessing real-world data

UI Agent: 

Most professional data scientists use **Python + SQL** as their core toolkit, with R as a valuable supplement for specialized statistical work.
"I'll research the top 3 programming languages for data science and explain why they're preferred. Let me gather that information for you.\n\n---\n\nBased on current industry trends and usage, here are the **top 3 programming languages for data science**:\n\n## 1. **Python** 🐍\n**Why it's #1:**\n- **Rich ecosystem**: Extensive libraries like NumPy, Pandas, Scikit-learn, TensorFlow, and PyTorch\n- **Easy to learn**: Simple, readable syntax makes it accessible for beginners\n- **Versatile**: Works for data analysis, machine learning, deep learning, and web deployment\n- **Strong community**: Massive support, tutorials, and active development\n- **Industry standard**: Most widely adopted in both academia and industry\n\n## 2. **R** 📊\n**Why it's popular:**\n- **Statistical focus**: Built specifically for statistical computing and data analysis\n- **Visualization**: Exceptional plotting capabilities with ggplot2 and other packages\n- **Specialized packages**: Over 18,000+ packages on CRAN for specific statistical methods\n- **Academic roots**: Widely used in research and statistical modeling\n- **Best for**: Statistical analysis, biostatistics, and academic research\n\n## 3. **SQL** 🗄️\n**Why it's essential:**\n- **Data retrieval**: The standard language for querying databases\n- **Universal skill**: Works across all major database systems (MySQL, PostgreSQL, etc.)\n- **Big data**: Essential for working with large datasets stored in databases\n- **Integration**: Often used alongside Python or R for complete data workflows\n- **Job requirement**: Nearly every data science position requires SQL knowledge\n\n**The verdict**: Most data scientists use a combination of these languages—Python or R for analysis and modeling, and SQL for data extraction and management."

Let's unpack what's happening here. When you make a request, the UI agent receives it first. This agent is optimized for conversation. It knows how to interpret your intent and communicate clearly. If the request requires deep work (research, analysis, complex calculations), the UI agent delegates to the task agent.

The task agent doesn't worry about being conversational. It focuses purely on executing the task accurately and thoroughly. Once it completes the work, it returns structured results to the UI agent, which then presents them to you in a friendly, understandable way.

This division of labor has several benefits:

  • The UI agent stays responsive: It can immediately acknowledge your request rather than going silent while processing
  • The task agent can take its time: It can use longer reasoning chains or multiple tool calls without worrying about keeping you engaged
  • Each agent has a clear purpose: The UI agent optimizes for communication; the task agent optimizes for accuracy