Skip to main content

ADR-006: A2A Agent Generation Refactoring

Status

ACCEPTEDImplemented

Context

The original mcp_codegen.py module had grown to over 1300 lines and was handling both MCP server generation and A2A (Agent-to-Agent) agent generation. This violated the single responsibility principle and made the codebase harder to maintain and test.

Problems Identified:

  1. Mixed Concerns: MCP server and A2A agent generation logic were intertwined
  2. Large File Size: 1315+ lines in a single module
  3. Testing Complexity: A2A generation couldn't be tested independently of MCP dependencies
  4. Integration Gaps: Missing integration with CNOE tooling (Agent Chat CLI)
  5. Development Workflow: Lack of standardized environment setup and testing procedures

User Request:

"move this to a2a_agent_codegen.py" + "Use https://github.com/cnoe-io/agent-chat-cli to test it, add it to the docs/docs in the setup guides"

Decision

We will refactor the A2A agent generation functionality into a separate module and create comprehensive documentation for testing with Agent Chat CLI.

Implementation Strategy:

  1. Extract A2A Generation Logic:

    • Move generate_a2a_agent() and _generate_a2a_agent_files() from mcp_codegen.py
    • Create new A2AAgentGenerator class in a2a_agent_codegen.py
    • Maintain backward compatibility in CLI interface
  2. Enhance Development Workflow:

    • Add .env template and setup automation
    • Create standardized Makefile targets
    • Improve development experience with make dev shortcut
  3. Comprehensive Documentation:

    • Create detailed testing guide with Agent Chat CLI integration
    • Add setup guides structure
    • Include architecture diagrams and troubleshooting
  4. CNOE Integration:

    • Full integration with Agent Chat CLI
    • Testing workflows and examples
    • Performance monitoring and debugging procedures

Consequences

Positive:

  1. ✅ Separation of Concerns: Clean boundary between MCP and A2A generation
  2. ✅ Better Maintainability: Each component can evolve independently
  3. ✅ Improved Testability: A2A generation has isolated test coverage
  4. ✅ Enhanced Documentation: 400+ lines of comprehensive testing guides
  5. ✅ Professional Workflow: Standardized .env setup and make targets
  6. ✅ CNOE Integration: Seamless integration with existing CNOE tooling

Architecture Changes:

Before (Monolithic):

mcp_codegen.py (1315 lines)
├── MCP server generation
├── A2A agent generation ← Mixed concerns
└── CLI integration

After (Separated):

mcp_codegen.py (1200 lines)
├── MCP server generation only

a2a_agent_codegen.py (300+ lines) ← NEW
├── A2AAgentGenerator class
├── Focused A2A agent generation
└── Clean, maintainable code

docs/docs/setup-guides/
├── index.md
└── testing-with-agent-chat-cli.md ← NEW

Complete Workflow Example:

  1. Generate A2A Agent:
uv run python -m openapi_mcp_codegen generate-a2a-agent \
--spec-file examples/argo-workflows/argo-openapi-enhanced-compliant.json \
--agent-name "argo_workflows" \
--mcp-server-url "http://localhost:3000"
  1. Setup Environment:
cd agent_argo_workflows
make dev # Creates .venv, .env, installs deps, formats code
  1. Start Agent:
make run-a2a       # Starts A2A agent on localhost:8000
  1. Test with Agent Chat CLI:
git clone https://github.com/cnoe-io/agent-chat-cli.git
cd agent-chat-cli
uv sync
uv run python -m agent_chat_cli a2a --host localhost --port 8000

Metrics:

  • Lines of Code Moved: ~150 lines from mcp_codegen.py to a2a_agent_codegen.py
  • New Documentation: 400+ lines in comprehensive testing guide
  • New Features: .env generation, make targets, dry-run support
  • Integration Points: Full Agent Chat CLI integration with examples
  • Test Coverage: Multiple testing scenarios and debugging procedures

Risk Mitigation:

  • Backward Compatibility: All existing CLI commands continue to work unchanged
  • Incremental Migration: Changes can be rolled back without breaking existing workflows
  • Comprehensive Testing: Multiple testing scenarios documented and validated

Implementation Status

COMPLETED

All requested functionality has been implemented:

  • ✅ A2A agent generation moved to separate file (a2a_agent_codegen.py)
  • ✅ Agent Chat CLI integration documented in docs/docs/setup-guides/
  • ✅ Setup guides added with comprehensive testing procedures
  • ✅ Enhanced with professional development workflow (.env, Makefile targets)
  • ✅ Complete testing and troubleshooting documentation

The refactoring successfully achieves better code organization, improved maintainability, and seamless integration with CNOE tooling ecosystem.