Code Development Fleet

Learn how to build a code development fleet with multiple specialized agents.

Overview

In this example, we’ll create a fleet for developing a REST API, including:

  • System architecture
  • Code implementation
  • Code review
  • Testing

Setup

First, install required packages:

pip install agentic-fleet python-dotenv fastapi uvicorn

Create a configuration file:

# config.py
from agentic_fleet.core.config import Config

config = Config.from_env()

Create Agents

Create specialized agents for different roles:

from agentic_fleet.agent import CodeAssistant
from agentic_fleet.agent.specialized.code import (
    ArchitectAgent,
    DeveloperAgent,
    ReviewerAgent,
    TesterAgent
)

# System Architect
architect = ArchitectAgent(
    role="architect",
    capabilities=["design", "planning"],
    config={
        "model": "gpt-4",
        "temperature": 0.7
    }
)

# Developer
developer = DeveloperAgent(
    role="developer",
    capabilities=["coding", "debugging"],
    config={
        "model": "gpt-4",
        "temperature": 0.2
    }
)

# Code Reviewer
reviewer = ReviewerAgent(
    role="reviewer",
    capabilities=["review", "best_practices"],
    config={
        "model": "gpt-4",
        "temperature": 0.3
    }
)

# Tester
tester = TesterAgent(
    role="tester",
    capabilities=["testing", "quality"],
    config={
        "model": "gpt-4",
        "temperature": 0.2
    }
)

Create Fleet

Set up the development fleet with a sequential coordination pattern:

from agentic_fleet import FleetChat
from agentic_fleet.fleets.coordination import CoordinationPattern

fleet = FleetChat(
    name="api_development",
    agents={
        "architect": architect,
        "developer": developer,
        "reviewer": reviewer,
        "tester": tester
    },
    coordination_pattern=CoordinationPattern.SEQUENTIAL,
    coordination_config={
        "sequence": [
            "architect",
            "developer",
            "reviewer",
            "tester"
        ]
    }
)

Development Workflow

1. Architecture Design

Start with the architect:

response = await fleet.initiate_chat(
    initiator_id="architect",
    message="""
    Design a REST API for a task management system with:
    - User authentication
    - Task CRUD operations
    - Task assignment
    - Status updates
    """
)

2. Implementation

The developer implements the design:

# Developer receives the design and implements
response = await fleet.send_message(
    "Here's the FastAPI implementation based on the design..."
)

3. Code Review

The reviewer checks the implementation:

# Reviewer checks code quality
response = await fleet.send_message(
    "Reviewing the implementation for best practices..."
)

4. Testing

The tester creates and runs tests:

# Tester creates test cases
response = await fleet.send_message(
    "Creating test suite for the API endpoints..."
)

Complete Example

Here’s a complete example putting it all together:

import asyncio
from agentic_fleet import FleetChat
from agentic_fleet.agent.specialized.code import *

async def develop_api():
    # Create agents
    agents = {
        "architect": ArchitectAgent(role="architect"),
        "developer": DeveloperAgent(role="developer"),
        "reviewer": ReviewerAgent(role="reviewer"),
        "tester": TesterAgent(role="tester")
    }
    
    # Create fleet
    fleet = FleetChat(
        name="api_development",
        agents=agents,
        coordination_pattern=CoordinationPattern.SEQUENTIAL,
        coordination_config={
            "sequence": [
                "architect",
                "developer",
                "reviewer",
                "tester"
            ]
        }
    )
    
    # Start development
    response = await fleet.initiate_chat(
        initiator_id="architect",
        message="Design a task management API"
    )
    
    # Development continues automatically through the sequence
    while not fleet.is_complete():
        await asyncio.sleep(1)
    
    return fleet.get_artifacts()

# Run development
artifacts = asyncio.run(develop_api())

Best Practices

  1. Agent Configuration

    • Use appropriate temperature for each role
    • Set specific capabilities
    • Add memory for context
  2. Coordination

    • Use sequential for structured development
    • Add conditions for quality gates
    • Monitor agent states
  3. Error Handling

    • Add retry logic
    • Validate outputs
    • Log important events
  4. Testing

    • Unit tests for components
    • Integration tests for flow
    • Performance testing

Next Steps

  1. Advanced Coordination
  2. Custom Agents
  3. Testing Strategies
  4. Production Deployment