Skip to content

Complete DevOps Pipeline Orchestration with Apply Patch & Shell Tools#

Open In Colab Open on GitHub

This notebook demonstrates a complete end-to-end DevOps pipeline orchestration using AG2’s support for OpenAI’s built-in apply_patch and shell tools. The system creates projects from scratch, develops code, tests, fixes issues, sets up CI/CD, builds, and deploys applications.

Overview#

This orchestration showcases:

  • Apply Patch Tool: For structured file operations (create, update, delete files)
  • Shell Tool: For executing commands (tests, builds, deployments, validation)

Use Case: Full Lifecycle DevOps Pipeline#

From project creation β†’ coding β†’ testing β†’ fixing β†’ CI/CD setup β†’ deployment β†’ validation

Orchestration Flow#

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         USER REQUEST                                    β”‚
β”‚              "Create a complete web application"                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              🎯 PIPELINE ORCHESTRATOR                                   β”‚
β”‚  β€’ Analyzes request                                                     β”‚
β”‚  β€’ Routes to appropriate agent                                          β”‚
β”‚  β€’ Coordinates workflow                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              πŸ—οΈ PROJECT CREATOR                                         β”‚
β”‚  Uses APPLY_PATCH tool:                                                 β”‚
β”‚  β€’ Create project structure                                             β”‚
β”‚  β€’ Initialize config files                                              β”‚
β”‚  β€’ Set up directories                                                   β”‚
β”‚  β€’ Create initial templates                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              πŸ’» CODE DEVELOPER                                          β”‚
β”‚  Uses APPLY_PATCH tool:                                                 β”‚
β”‚  β€’ Write application code                                               β”‚
β”‚  β€’ Implement features                                                   β”‚
β”‚  β€’ Create modules and classes                                           β”‚
β”‚  β€’ Write unit tests                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              πŸ” CODE QUALITY ANALYZER                                   β”‚
β”‚  Uses SHELL tool:                                                       β”‚
β”‚  β€’ Run test suites (pytest, unittest)                                   β”‚
β”‚  β€’ Run linters (pylint, flake8)                                         β”‚
β”‚  β€’ Check git status                                                     β”‚
β”‚  β€’ Analyze code coverage                                                β”‚
β”‚  β€’ Check build status                                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                   β”‚
           Issues Found?        All Checks Pass?
                    β”‚                   β”‚
                    β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      πŸ”§ CODE FIXER        β”‚  β”‚   βš™οΈ CONFIGURATION MANAGER   β”‚
β”‚  Uses APPLY_PATCH tool:   β”‚  β”‚  Uses APPLY_PATCH tool:      β”‚
β”‚  β€’ Fix bugs               β”‚  β”‚  β€’ Create CI/CD configs      β”‚
β”‚  β€’ Resolve linting errors β”‚  β”‚  β€’ Update environment files  β”‚
β”‚  β€’ Refactor code          β”‚  β”‚  β€’ Create Docker configs     β”‚
β”‚  β€’ Add missing tests      β”‚  β”‚  β€’ Update deployment scripts β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚                   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              πŸš€ BUILD & DEPLOY AGENT                                    β”‚
β”‚  Uses SHELL tool:                                                       β”‚
β”‚  β€’ Install dependencies                                                 β”‚
β”‚  β€’ Build applications                                                   β”‚
β”‚  β€’ Run deployment scripts                                               β”‚
β”‚  β€’ Push to repositories                                                 β”‚
β”‚  β€’ Manage containers                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              βœ… DEPLOYMENT VALIDATOR                                    β”‚
β”‚  Uses SHELL tool:                                                       β”‚
β”‚  β€’ Run health checks                                                    β”‚
β”‚  β€’ Execute smoke tests                                                  β”‚
β”‚  β€’ Check service status                                                 β”‚
β”‚  β€’ Verify endpoints                                                     β”‚
β”‚  β€’ Monitor resource usage                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                   β”‚
            All Checks Pass?      Issues Found?
                    β”‚                   β”‚
                    β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   🎯 PIPELINE ORCHESTRATORβ”‚  β”‚  Route back to CODE FIXER    β”‚
β”‚      Report SUCCESS       β”‚  β”‚  or CONFIG MANAGER           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         USER RECEIVES REPORT                            β”‚
β”‚              Complete pipeline status and results                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Agent Responsibilities#

1. 🎯 Pipeline Orchestrator#

  • Role: Central coordinator
  • Responsibilities:
    • Analyze user requests
    • Route tasks to appropriate agents
    • Monitor pipeline progress
    • Report final results
  • Tools Used: None (coordination only)

2. πŸ—οΈ Project Creator#

  • Role: Initialize new projects
  • Responsibilities:
    • Create project structure
    • Generate initial files (README, .gitignore, LICENSE)
    • Set up configuration files
    • Create directory structure
  • Tools Used: APPLY_PATCH (file creation)

3. πŸ’» Code Developer#

  • Role: Write application code
  • Responsibilities:
    • Implement features
    • Create modules and classes
    • Add business logic
    • Write unit tests
  • Tools Used: APPLY_PATCH (code writing)

4. πŸ” Code Quality Analyzer#

  • Role: Test and analyze code quality
  • Responsibilities:
    • Run test suites
    • Execute linters
    • Check code coverage
    • Validate build status
  • Tools Used: SHELL (command execution)

5. πŸ”§ Code Fixer#

  • Role: Fix code issues
  • Responsibilities:
    • Fix bugs
    • Resolve linting errors
    • Refactor code
    • Add missing tests
  • Tools Used: APPLY_PATCH (code modifications)

6. βš™οΈ Configuration Manager#

  • Role: Manage configurations
  • Responsibilities:
    • Create CI/CD configs
    • Update environment files
    • Create Docker configs
    • Update deployment scripts
  • Tools Used: APPLY_PATCH (config file operations)

7. πŸš€ Build & Deploy Agent#

  • Role: Build and deploy applications
  • Responsibilities:
    • Install dependencies
    • Build applications
    • Run deployment scripts
    • Manage containers
  • Tools Used: SHELL (build and deployment commands)

8. βœ… Deployment Validator#

  • Role: Validate deployments
  • Responsibilities:
    • Run health checks
    • Execute smoke tests
    • Check service status
    • Verify endpoints
  • Tools Used: SHELL (validation commands)

Installation and Setup#

# Install required packages
# !pip install ag2[openai] python-dotenv

Import Dependencies#

import os

from dotenv import load_dotenv

from autogen import ConversableAgent, LLMConfig, UserProxyAgent
from autogen.agentchat import initiate_group_chat
from autogen.agentchat.group.patterns.auto import AutoPattern

load_dotenv()

Configure LLM with Built-in Tools#

We configure the LLM to use both apply_patch_async and shell tools:

  • apply_patch_async: For structured file operations (create, update, delete)
  • shell: For executing shell commands (tests, builds, deployments)
  • workspace_dir: Directory where all operations will be performed
# Configure LLM with both built-in tools
llm_config = LLMConfig(
    config_list={
        "api_type": "responses",
        "model": "gpt-5.1",
        "api_key": os.getenv("OPENAI_API_KEY"),
        "built_in_tools": ["apply_patch_async", "shell"],
        "workspace_dir": "./project_dir",
    },
)

Agent Definitions#

Agent 1: Pipeline Orchestrator#

The orchestrator acts as the central coordinator, analyzing requests and routing to appropriate agents.

orchestrator = ConversableAgent(
    name="pipeline_orchestrator",
    system_message="""🎯 You are the Pipeline Orchestrator. Your role is to:
    β€’ Analyze user requests and determine the workflow path
    β€’ Route tasks to appropriate specialized agents
    β€’ Monitor pipeline progress and coordinate handoffs
    β€’ Report final results to the user
    Workflow Decision Logic:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ 1. New project request? β†’ Route to project_creator      β”‚
    β”‚ 2. Code development? β†’ Route to code_developer          β”‚
    β”‚ 3. Code analysis needed? β†’ Route to code_quality_analyzerβ”‚
    β”‚ 4. Configuration updates? β†’ Route to config_manager     β”‚
    β”‚ 5. Build/deploy request? β†’ Route to build_deploy_agent  β”‚
    β”‚ 6. Validation needed? β†’ Route to deployment_validator   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    Always provide clear routing decisions with reasoning.""",
    llm_config=llm_config,
)

Agent 2: Project Creator#

Uses APPLY_PATCH tool to create project structure and initial files.

project_creator = ConversableAgent(
    name="project_creator",
    system_message="""πŸ—οΈ You are the Project Creator. Your role is to:
    Use the APPLY_PATCH tool to:
    βœ“ Create project structure and directories
    βœ“ Generate initial files (README.md, .gitignore, LICENSE)
    βœ“ Set up configuration files (package.json, requirements.txt, pom.xml)
    βœ“ Create initial source code templates
    βœ“ Set up test directory structure
    Project Creation Checklist:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ β–‘ Project directory structure created?       β”‚
    β”‚ β–‘ Configuration files initialized?           β”‚
    β”‚ β–‘ Initial source code files created?         β”‚
    β”‚ β–‘ Test directory structure set up?           β”‚
    β”‚ β–‘ Documentation files added?                 β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    After project creation:
    β†’ Route to code_developer for implementation
    Create clean, well-structured project foundations.""",
    llm_config=llm_config,
)

Agent 3: Code Developer#

Uses APPLY_PATCH tool to write application code and implement features.

code_developer = ConversableAgent(
    name="code_developer",
    system_message="""πŸ’» You are the Code Developer. Your role is to:
    Use the APPLY_PATCH tool to:
    βœ“ Write application code and implement features
    βœ“ Create modules, classes, and functions
    βœ“ Add business logic and algorithms
    βœ“ Implement API endpoints and routes
    βœ“ Write unit tests for new code
    Development Guidelines:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ 1. Follow best practices and coding standardsβ”‚
    β”‚ 2. Write clean, maintainable code            β”‚
    β”‚ 3. Include proper error handling             β”‚
    β”‚ 4. Add comprehensive unit tests              β”‚
    β”‚ 5. Document complex logic                    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

    After development:
    β†’ Route to code_quality_analyzer for testing and validation
    Write production-ready code with tests!""",
    llm_config=llm_config,
)

Agent 4: Code Quality Analyzer#

Uses SHELL tool to run tests, linters, and analyze code quality.

code_analyzer = ConversableAgent(
    name="code_quality_analyzer",
    system_message="""πŸ” You are the Code Quality Analyzer. Your role is to:
    Use the SHELL tool to:
    βœ“ Run test suites: pytest, unittest, npm test, mvn test
    βœ“ Run linters: pylint, flake8, black --check, eslint, prettier
    βœ“ Check git status: git status, git diff, git log
    βœ“ Analyze code coverage: coverage report, pytest --cov
    βœ“ Check build status: npm run build, mvn compile
    Analysis Checklist:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ β–‘ All tests passing?                         β”‚
    β”‚ β–‘ No linting errors?                         β”‚
    β”‚ β–‘ Code coverage acceptable?                  β”‚
    β”‚ β–‘ No merge conflicts?                        β”‚
    β”‚ β–‘ Build successful?                          β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    Routing Rules:
    β€’ Issues found β†’ Route to code_fixer
    β€’ All checks pass β†’ Route to config_manager for CI/CD setup
    Provide detailed analysis reports with specific issues identified.""",
    llm_config=llm_config,
)

Agent 5: Code Fixer#

Uses APPLY_PATCH tool to fix bugs and resolve issues found during analysis.

code_fixer = ConversableAgent(
    name="code_fixer",
    system_message="""πŸ”§ You are the Code Fixer. Your role is to:
    Use the APPLY_PATCH tool to:
    βœ“ Fix bugs identified by tests
    βœ“ Resolve linting errors
    βœ“ Refactor code for better quality
    βœ“ Add missing tests
    βœ“ Update documentation
    Fixing Guidelines:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ 1. Fix one issue at a time                   β”‚
    β”‚ 2. Use precise diffs (unified diff format)   β”‚
    β”‚ 3. Maintain code style consistency           β”‚
    β”‚ 4. Add tests for new fixes                   β”‚
    β”‚ 5. Update related documentation              β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    After applying fixes:
    β†’ Always route back to code_quality_analyzer for re-validation
    Never skip validation after fixes!""",
    llm_config=llm_config,
)

Agent 6: Configuration Manager#

Uses APPLY_PATCH tool to create and update CI/CD configurations, Docker files, and deployment scripts.

config_manager = ConversableAgent(
    name="config_manager",
    system_message="""βš™οΈ You are the Configuration Manager. Your role is to:
    Use the APPLY_PATCH tool to:
    βœ“ Create/update CI/CD configurations (.github/workflows/*.yml, .gitlab-ci.yml)
    βœ“ Create/update environment files (.env, .env.example, config.yaml)
    βœ“ Create/update deployment scripts (deploy.sh, docker-compose.yml)
    βœ“ Update build configurations (package.json, pom.xml, requirements.txt)
    βœ“ Create Dockerfile and containerization configs
    Configuration Types:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ β€’ CI/CD Pipeline Configs                     β”‚
    β”‚ β€’ Environment Variables                      β”‚
    β”‚ β€’ Docker & Container Configs                 β”‚
    β”‚ β€’ Build & Dependency Files                   β”‚
    β”‚ β€’ Deployment Scripts                         β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    After updating configs:
    β†’ Route to build_deploy_agent for execution
    Always validate config syntax before routing!""",
    llm_config=llm_config,
)

Agent 7: Build & Deploy Agent#

Uses SHELL tool to install dependencies, build applications, and deploy services.

build_deploy_agent = ConversableAgent(
    name="build_deploy_agent",
    system_message="""πŸš€ You are the Build & Deploy Agent. Your role is to:
    Use the SHELL tool to:
    βœ“ Install dependencies: npm install, pip install -r requirements.txt, mvn install
    βœ“ Build applications: npm run build, mvn package, docker build
    βœ“ Run deployment scripts: ./deploy.sh, kubectl apply
    βœ“ Push to repositories: git push, docker push
    βœ“ Manage containers: docker-compose up, docker run
    βœ“ Start services: systemctl start, pm2 start
    Build & Deploy Checklist:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ β–‘ Dependencies installed correctly?          β”‚
    β”‚ β–‘ Build completed successfully?              β”‚
    β”‚ β–‘ Docker images built and tagged?            β”‚
    β”‚ β–‘ Deployment scripts executed?               β”‚
    β”‚ β–‘ Services started successfully?             β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    After deployment:
    β†’ Route to deployment_validator for verification
    Report build/deploy status with timestamps and logs.""",
    llm_config=llm_config,
)

Agent 8: Deployment Validator#

Uses SHELL tool to validate deployments by running health checks and smoke tests.

deployment_validator = ConversableAgent(
    name="deployment_validator",
    system_message="""βœ… You are the Deployment Validator. Your role is to:
    Use the SHELL tool to:
    βœ“ Run health checks: curl http://endpoint/health, wget --spider
    βœ“ Execute smoke tests: npm run smoke-test, pytest tests/smoke
    βœ“ Check service status: docker ps, kubectl get pods, systemctl status
    βœ“ Verify endpoints: curl API endpoints, check logs
    βœ“ Monitor resource usage: top, htop, docker stats
    Validation Checklist:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ β–‘ Health endpoints responding?               β”‚
    β”‚ β–‘ Smoke tests passing?                       β”‚
    β”‚ β–‘ Services running correctly?                β”‚
    β”‚ β–‘ No critical errors in logs?                β”‚
    β”‚ β–‘ Performance metrics acceptable?            β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    After validation:
    β€’ All checks pass β†’ Route to pipeline_orchestrator (SUCCESS)
    β€’ Issues found β†’ Route to code_fixer or config_manager (FAILURE)
    Provide detailed validation reports with metrics.""",
    llm_config=llm_config,
)

User Agent Configuration#

user = UserProxyAgent(
    name="user", human_input_mode="TERMINATE", code_execution_config={"work_dir": "coding", "use_docker": False}
)

Orchestration Pattern Setup#

We use AutoPattern which allows the LLM to intelligently select the next speaker based on conversation context. This provides more dynamic and adaptive conversation flow compared to DefaultPattern.

pattern = AutoPattern(
    initial_agent=orchestrator,
    agents=[
        orchestrator,
        project_creator,
        code_developer,
        code_analyzer,
        code_fixer,
        config_manager,
        build_deploy_agent,
        deployment_validator,
    ],
    user_agent=user,
    group_manager_args={"llm_config": llm_config},
)

Execute the Pipeline#

This example creates a complete REST API for a task management system from scratch, going through the entire development lifecycle.

result, context, last_agent = initiate_group_chat(
    pattern=pattern,
    messages="""πŸš€ Create a complete web application from scratch use apply patch and shell tools:
    Project: Build a REST API for a task management system
    Requirements:
    1. Create project structure (Python FastAPI application)
    2. Implement core features:
       - Task CRUD operations
       - User authentication
       - Task filtering and search
    3. Write comprehensive unit tests
    4. Set up CI/CD pipeline (GitHub Actions)
    5. Create Docker configuration
    6. Build and deploy the application
    7. Validate deployment
    Start from project creation and go through the complete development lifecycle.""",
    max_rounds=30,
)

Tool Usage Summary#

Apply Patch Tool Usage#

Agent Use Case Operations
Project Creator Create project structure create_file for directories, config files, templates
Code Developer Write application code create_file, update_file for source code and tests
Code Fixer Fix bugs and issues update_file with unified diffs to fix code
Configuration Manager Manage configs create_file, update_file for CI/CD, Docker, env files

,

Agent Use Case Commands
Code Quality Analyzer Test and analyze pytest, pylint, flake8, git status, coverage
Build & Deploy Agent Build and deploy pip install, npm build, docker build, docker-compose up
Deployment Validator Validate deployment curl, pytest tests/smoke, docker ps, systemctl status

Shell Tool Usage#

Key Benefits#

  1. Structured File Operations: Apply patch tool ensures precise, controlled file modifications
  2. Command Execution: Shell tool enables testing, building, and deployment automation
  3. Complete Lifecycle: From project creation to deployment validation
  4. Iterative Improvement: Automatic routing back to fixers when issues are found
  5. Production Ready: Real-world DevOps workflow implementation

Next Steps#

  • Customize agent system messages for your specific use case
  • Adjust workspace directory and paths
  • Modify handoff conditions for different workflows
  • Add more specialized agents as needed
  • Integrate with external tools and services