Warum Multi-Agent Systems?
Ein einzelner generalistischer Agent kann viel – aber Spezialisierung schlägt Generalisierung
bei komplexen Tasks. Genau wie in einem Softwareteam haben Entwickler verschiedene Rollen:
Das ideale AI Software Team
- 🏗️ Architect Agent: System-Design, Technology Decisions, Architecture Patterns
- ⚙️ Backend Agent: Server Logic, APIs, Database, Business Logic
- 🎨 Frontend Agent: UI Components, User Experience, Styling
- 🧪 QA Agent: Test Generation, Bug Detection, Quality Assurance
- 📚 Documentation Agent: README, API Docs, Comments, Tutorials
- 🚀 DevOps Agent: CI/CD, Deployment, Monitoring, Infrastructure
- 🎯 Coordinator Agent: Task Distribution, Progress Tracking, Decision Making
Jeder Agent ist spezialisiert, hat sein eigenes Prompt Engineering, und seine eigenen Tools.
Der Coordinator orchestriert alle.
Multi-Agent Architektur-Patterns
Pattern 1: Hierarchical (Boss-Worker)
Ein Master-Agent koordiniert mehrere Worker-Agents:
[Coordinator Agent]
|
----------------------------------------
| | | |
[Architect] [Backend] [Frontend] [QA]
Workflow:
- Coordinator empfängt High-Level Task: "Baue E-Commerce Platform"
- Coordinator erstellt Master Plan und delegiert Sub-Tasks
- Architect entwirft System → gibt Blueprint an andere weiter
- Backend + Frontend arbeiten parallel an ihren Teilen
- QA validiert kontinuierlich alle Outputs
- Coordinator integriert alles und validiert Completion
class CoordinatorAgent:
def __init__(self):
self.architect = ArchitectAgent()
self.backend = BackendAgent()
self.frontend = FrontendAgent()
self.qa = QAAgent()
def execute_project(self, project_description):
# Phase 1: Architecture
print("📐 Phase 1: Architecture Design")
architecture = self.architect.design(project_description)
# Phase 2: Parallel Implementation
print("⚙️ Phase 2: Implementation")
backend_task = {
"spec": architecture["backend_spec"],
"apis": architecture["api_contracts"]
}
frontend_task = {
"spec": architecture["frontend_spec"],
"design": architecture["ui_mockups"]
}
# Run in parallel
backend_result = self.backend.implement(backend_task)
frontend_result = self.frontend.implement(frontend_task)
# Phase 3: Quality Assurance
print("🧪 Phase 3: Quality Assurance")
qa_report = self.qa.test_integration(
backend=backend_result,
frontend=frontend_result
)
# Phase 4: Fix Issues
if qa_report.has_issues():
print("🔧 Phase 4: Fixing Issues")
for issue in qa_report.issues:
if issue.component == "backend":
self.backend.fix(issue)
else:
self.frontend.fix(issue)
return {
"architecture": architecture,
"backend": backend_result,
"frontend": frontend_result,
"qa_report": qa_report
}
Pattern 2: Peer-to-Peer (Collaborative)
Agents kommunizieren direkt miteinander ohne zentralen Coordinator:
[Backend Agent] ←→ [Frontend Agent]
↕ ↕
[QA Agent] ←→ [Documentation Agent]
Best für: Kleinere Teams wo enge Collaboration wichtig ist.
Backend und Frontend tauschen direkt API-Specs aus, QA gibt direkt Feedback.
Pattern 3: Pipeline (Sequential)
Output eines Agents wird Input des nächsten:
[Architect] → [Backend] → [Frontend] → [QA] → [DevOps]
Best für: Waterfall-ähnliche Workflows wo klare Abhängigkeiten existieren.
Inter-Agent Communication: Wie reden Agents miteinander?
Methode 1: Shared Memory (Message Queue)
class MessageBus:
def __init__(self):
self.messages = []
def send(self, from_agent, to_agent, message):
self.messages.append({
"from": from_agent,
"to": to_agent,
"content": message,
"timestamp": datetime.now()
})
def receive(self, agent_name):
"""Get all messages for this agent"""
messages = [
msg for msg in self.messages
if msg["to"] == agent_name
]
return messages
# Usage
bus = MessageBus()
# Backend fertig → informiert Frontend
bus.send(
from_agent="backend",
to_agent="frontend",
message={
"type": "api_ready",
"endpoints": ["GET /api/users", "POST /api/orders"],
"base_url": "http://localhost:8000"
}
)
# Frontend liest Message
messages = bus.receive("frontend")
api_info = messages[0]["content"]
Methode 2: Direct LLM Communication
Agents kommunizieren in Natural Language:
# Backend Agent sendet Message
backend_message = """
Hey Frontend Team,
I've completed the User Authentication API:
- POST /api/auth/login → Returns JWT token
- POST /api/auth/register → Creates new user
- GET /api/auth/me → Returns current user profile
The API expects JSON with email/password fields.
JWT token should be sent in Authorization header.
Let me know if you need anything else!
"""
# Frontend Agent verarbeitet die Message
frontend_agent.process_message(backend_message)
# → Agent versteht automatisch die API Specs und baut Frontend
Methode 3: Structured Protocols
Definierte Message Schemas für type-safety:
from pydantic import BaseModel
from typing import List, Literal
class AgentMessage(BaseModel):
sender: str
receiver: str
message_type: Literal["task", "result", "question", "answer"]
payload: dict
class TaskMessage(AgentMessage):
message_type: Literal["task"] = "task"
payload: dict # Contains task specification
class ResultMessage(AgentMessage):
message_type: Literal["result"] = "result"
payload: dict # Contains execution results
success: bool
# Backend sendet strukturierte Message
message = ResultMessage(
sender="backend_agent",
receiver="frontend_agent",
payload={
"api_endpoints": [
{
"method": "POST",
"path": "/api/auth/login",
"request_schema": {...},
"response_schema": {...}
}
]
},
success=True
)
Conflict Resolution: Wenn Agents nicht einig sind
Was passiert wenn Backend und Frontend verschiedene Ansätze für das gleiche Problem vorschlagen?
Strategy 1: Coordinator Decision
def resolve_conflict(proposals):
"""Coordinator evaluiert alle Proposals"""
evaluation_prompt = f"""
Backend schlägt vor: {proposals['backend']}
Frontend schlägt vor: {proposals['frontend']}
Evaluiere beide Ansätze nach:
- Performance
- Maintainability
- User Experience
- Development Time
Wähle den besten Ansatz oder schlage Hybrid vor.
"""
decision = coordinator_llm.decide(evaluation_prompt)
return decision
Strategy 2: Voting Mechanism
Alle Agents voten für einen Ansatz:
proposals = ["REST API", "GraphQL", "gRPC"]
votes = {}
for agent in [backend, frontend, devops, qa]:
vote = agent.vote(proposals, context=project_requirements)
votes[agent.name] = vote
# Majority wins
winner = max(set(votes.values()), key=list(votes.values()).count)
Strategy 3: Debate & Consensus
Agents diskutieren bis Consensus erreicht ist:
def debate_until_consensus(topic, agents, max_rounds=5):
positions = {agent: agent.initial_position(topic) for agent in agents}
for round in range(max_rounds):
# Jeder Agent hört anderen zu
for agent in agents:
other_positions = [
pos for a, pos in positions.items() if a != agent
]
# Agent kann Position ändern
positions[agent] = agent.update_position(
topic, other_positions
)
# Check Consensus
if all_agree(positions.values()):
return positions[agents[0]]
# Fallback: Coordinator entscheidet
return coordinator.break_tie(positions)
Frameworks für Multi-Agent Systems
1. AutoGen (Microsoft)
Conversation-based multi-agent framework:
from autogen import AssistantAgent, UserProxyAgent, GroupChat
# Define Agents
architect = AssistantAgent(
name="Architect",
system_message="You are a software architect...",
llm_config={"model": "gpt-4"}
)
backend_dev = AssistantAgent(
name="Backend_Developer",
system_message="You implement backend services...",
llm_config={"model": "gpt-4"}
)
qa_engineer = AssistantAgent(
name="QA_Engineer",
system_message="You write tests and find bugs...",
llm_config={"model": "gpt-4"}
)
# Create Group Chat
group_chat = GroupChat(
agents=[architect, backend_dev, qa_engineer],
messages=[],
max_round=20
)
manager = UserProxyAgent(
name="Manager",
system_message="Coordinate the team",
code_execution_config={"work_dir": "coding"}
)
# Start conversation
manager.initiate_chat(
group_chat,
message="Build a REST API for a blog platform"
)
2. CrewAI
Role-based agent framework mit Tasks und Tools:
from crewai import Agent, Task, Crew
# Define Agents with Roles
architect = Agent(
role='Software Architect',
goal='Design scalable system architecture',
backstory='Expert in distributed systems...',
verbose=True
)
developer = Agent(
role='Senior Developer',
goal='Implement high-quality code',
backstory='10 years of full-stack experience...',
verbose=True
)
# Define Tasks
design_task = Task(
description='Design the system architecture for...',
agent=architect
)
implement_task = Task(
description='Implement the backend based on architecture',
agent=developer
)
# Create Crew
crew = Crew(
agents=[architect, developer],
tasks=[design_task, implement_task],
verbose=2
)
# Execute
result = crew.kickoff()
3. LangGraph
Graph-based agent orchestration:
from langgraph.graph import StateGraph
from typing import TypedDict
class TeamState(TypedDict):
task: str
architecture: dict
backend_code: str
frontend_code: str
test_results: dict
# Define Workflow Graph
workflow = StateGraph(TeamState)
# Add Nodes (Agents)
workflow.add_node("architect", architect_agent)
workflow.add_node("backend", backend_agent)
workflow.add_node("frontend", frontend_agent)
workflow.add_node("qa", qa_agent)
# Add Edges (Flow)
workflow.add_edge("architect", "backend")
workflow.add_edge("architect", "frontend")
workflow.add_edge("backend", "qa")
workflow.add_edge("frontend", "qa")
# Conditional Edge: If QA fails, go back
workflow.add_conditional_edges(
"qa",
lambda state: "backend" if state["test_results"]["backend_failed"] else "end",
)
# Compile and Run
app = workflow.compile()
result = app.invoke({"task": "Build E-Commerce Platform"})
Real-World Example: Building a Complete App
Schauen wir uns einen kompletten Workflow an:
Project: "Task Management SaaS"
Agents: 6 | Duration: 2 Stunden | Lines of Code: ~5.000
TIMELINE:
[00:00-00:15] ARCHITECT AGENT
→ Analyzes requirements
→ Chooses Tech Stack: Next.js, FastAPI, PostgreSQL, Redis
→ Designs Microservices Architecture
→ Creates API contracts (OpenAPI spec)
→ OUTPUT: Architecture.md, API Specs, DB Schema
[00:15-00:45] PARALLEL DEVELOPMENT
→ BACKEND AGENT:
• Setup FastAPI project
• Implement User Service
• Implement Task Service
• Implement Auth with JWT
• Add Redis caching
• Write Unit Tests
→ FRONTEND AGENT:
• Setup Next.js project
• Create Design System (components)
• Implement Dashboard
• Implement Task Board (Kanban)
• Add Authentication Flow
• Integrate with Backend APIs
[00:45-01:00] QA AGENT
→ Run all unit tests
→ Run integration tests
→ E2E testing with Playwright
→ FOUND ISSUES:
• Backend: Missing pagination on /tasks endpoint
• Frontend: Auth token not refreshed correctly
[01:00-01:15] FIX PHASE
→ Backend Agent fixes pagination
→ Frontend Agent implements token refresh logic
→ QA re-tests: ALL PASS ✅
[01:15-01:30] DOCUMENTATION AGENT
→ Generates README.md
→ Creates API documentation
→ Writes setup instructions
→ Adds code comments
[01:30-02:00] DEVOPS AGENT
→ Creates Dockerfile
→ Setup CI/CD pipeline (GitHub Actions)
→ Configures environment variables
→ Deploys to production (Railway/Vercel)
→ Sets up monitoring (Sentry)
[02:00] ✅ COMPLETE
→ App is live
→ All tests passing
→ Documentation complete
→ Monitoring active
Advanced: Self-Organizing Agent Teams
Das nächste Level: Agents die selbst entscheiden wie das Team strukturiert sein sollte:
class SelfOrganizingTeam:
def __init__(self, coordinator):
self.coordinator = coordinator
self.agents = []
def assemble_team(self, project_description):
"""Coordinator analyzed project und wählt optimales Team"""
analysis = self.coordinator.analyze_project(project_description)
required_skills = analysis["required_skills"]
complexity = analysis["complexity"]
# Dynamically create agents based on needs
if "backend" in required_skills:
self.agents.append(BackendAgent(
specialization=analysis["backend_tech"]
))
if "frontend" in required_skills:
self.agents.append(FrontendAgent(
framework=analysis["frontend_framework"]
))
if complexity > 0.7:
# High complexity → need specialist agents
self.agents.append(DatabaseAgent())
self.agents.append(SecurityAgent())
if analysis["needs_ml"]:
self.agents.append(MLEngineer())
return self.agents
def execute_project(self, project_description):
# Assemble optimal team
team = self.assemble_team(project_description)
# Let agents self-organize
organization = self.coordinator.organize_team(team)
# Execute with optimal structure
return self.coordinator.execute_with_team(
team, organization, project_description
)
Monitoring & Debugging Multi-Agent Systems
Mit mehreren Agents wird Debugging komplexer. Essential Tools:
Observability für Multi-Agent Systems
- Conversation Logs: Alle Agent-to-Agent Messages tracken
- Execution Timeline: Visualisiere wer wann was macht
- Decision Trees: Warum hat Coordinator X an Y delegiert?
- Cost Tracking: Token usage pro Agent
- Performance Metrics: Time per task, success rates
import logging
import json
from datetime import datetime
class AgentMonitor:
def __init__(self):
self.events = []
def log_agent_action(self, agent_name, action, details):
event = {
"timestamp": datetime.now().isoformat(),
"agent": agent_name,
"action": action,
"details": details
}
self.events.append(event)
logging.info(json.dumps(event))
def generate_timeline(self):
"""Visual timeline of agent activities"""
timeline = []
for event in self.events:
timeline.append(
f"[{event['timestamp']}] "
f"{event['agent']}: {event['action']}"
)
return "\n".join(timeline)
def get_agent_stats(self, agent_name):
agent_events = [
e for e in self.events
if e["agent"] == agent_name
]
return {
"total_actions": len(agent_events),
"action_types": Counter([e["action"] for e in agent_events])
}
Key Takeaways
- Multi-Agent = Spezialisierung → bessere Ergebnisse als ein Generalist
- Hierarchical (Boss-Worker) ist die gängigste Architektur
- Inter-Agent Communication: Message Queue, Natural Language, oder Structured
- Conflict Resolution: Coordinator Decision, Voting, oder Debate
- Frameworks: AutoGen (Chat), CrewAI (Roles), LangGraph (Graphs)
- Self-Organizing Teams: Agents wählen optimale Team-Struktur selbst
- Monitoring essentiell: Timeline, Logs, Decision Trees für Debugging
- Real-World: 6 Agents können komplette SaaS App in 2h bauen
Nächste Schritte
Sie verstehen jetzt Multi-Agent Orchestrierung. Im nächsten Kapitel schauen wir uns
die konkreten Tools an: Claude, Codestral, Replit Agent im Detail –
und wie Sie sie optimal einsetzen.