Building an Adaptive Multi-Agent Orchestration Engine with Dynamic Routing and Workflow Management
- 4 minutes ago
- 8 min read

Purpose
In Assignment 1, you built the individual building blocks of a multi-agent system. In this assignment, you move beyond isolated concepts and design a complete, production-oriented orchestration engine that can dynamically configure agent pipelines, select routing strategies based on system state, handle errors gracefully, and adapt to different workflow requirements at runtime.
This assignment is closer to how multi-agent systems are actually designed in production environments.
Connection to Course Learning Outcomes (CLOs):
CLO | Description | How This Assignment Addresses It |
CLO-5 | Manage conversation context | Dynamic context management with validation and transformation |
CLO-6 | Formalize A2A communication | Extended protocol with error handling and status fields |
CLO-7 | Build integrated systems | Full orchestration engine with workflow definition and execution |
CLO-8 | Apply system design thinking | Architecture choices, extensibility, error recovery |
Learning Objectives
By completing this assignment, you will be able to:
Architect a modular multi-agent engine with cleanly separated concerns: strategy, detection, control, and evaluation (Bloom’s: Create)
Design an adaptive routing system that selects strategies dynamically based on agent pool state, message properties, or workflow requirements (Bloom’s: Design)
Construct a workflow definition system that declaratively specifies agent pipelines and their execution order (Bloom’s: Create)
Evaluate your engine across multiple workflow scenarios, comparing performance, reliability, and extensibility (Bloom’s: Evaluate)
Analyze failure modes and implement recovery mechanisms (retry, fallback, dead-letter) for robust agent systems (Bloom’s: Analyze)
Justify system-level design decisions with reference to distributed systems principles (Bloom’s: Evaluate)
Task Description
Duration: 7–10 days from assignment release
Type: Individual Assignment
Difficulty Level: Advanced
Task 1 — Implement Core Agent Infrastructure (15 Marks)
Build a robust, production-quality agent framework.
Implement the following classes
A2AMessage — Full 5-field protocol envelope with to_json() and from_json() methods
Agent (base class) — With name, capabilities, can_handle(), receive(), delegate(), and a process() method that returns an optional next message
Router — Dictionary-based registry with O(1) lookup by agent name
Requirements
Each class must be modular and reusable (separate concerns)
Add docstrings explaining behavior and assumptions for every class and method
All agents must write to a shared trace log list
process() must return Optional[A2AMessage] — return a message to chain, or None to terminate
Task 2 — Workflow Detection & Classification (15 Marks)
Create a system that classifies incoming requests and selects the appropriate workflow.
Implement
def detect_workflow_type(msg: A2AMessage) -> str:
...
It should classify input messages into workflow categories such as:
Workflow Type | Detection Criteria | Suggested Pipeline |
Simple Query | Single intent, no context | Direct route to single agent |
Multi-Step Pipeline | Context contains workflow_steps | Sequential agent chain |
Fan-Out/Gather | Intent indicates parallel tasks | All-match routing → aggregation |
Review Required | Context contains requires_review: True | Main pipeline + Reviewer agent |
Hints for detection
Check for specific context keys
Analyze intent naming patterns
Check the number of registered agents with matching capabilities
Examine content complexity (length, keywords)
You are free to design your own classification logic.
Task 3 — Adaptive Strategy Selection Engine (20 Marks)
Create an orchestration controller:
def execute_workflow(msg: A2AMessage, router: Router) -> list:
...
This function should: 1. Detect workflow type using Task 2’s classifier 2. Select the appropriate orchestration strategy:
Direct dispatch for simple queries
Sequential chaining for multi-step pipelines (with max_hops safeguard)
Fan-out/gather for parallel tasks (broadcast to all capable agents, aggregate results)
Pipeline with review for quality-checked workflows 3. Execute the workflow and return the full list of messages produced 4. Write all events to the shared trace log
Requirements
The controller must be strategy-agnostic — adding a new strategy should require minimal code changes
Implement at least 3 distinct orchestration strategies
Include a fallback mechanism for unclassifiable workflows
Task 4 — Error Handling & Recovery (15 Marks)
Extend your system with robust error handling.
Implement
Retry mechanism: If an agent fails (simulated with a random failure flag), retry up to N times
Fallback agents: If the primary agent fails after retries, route to a fallback agent with the same capability
Dead-letter queue: Messages that cannot be processed after all recovery attempts are saved to a dead-letter list with failure reasons
Graceful degradation: If a non-critical agent is unavailable, the pipeline continues with a warning rather than crashing
Output format for dead-letter entries:
{ "message": {...}, # The A2AMessage dict "failure_reason": "...", # Why it failed "retry_attempts": 3, # How many times we tried "timestamp": "..." # When it was dead-lettered }Task 5 — Evaluation Framework (10 Marks)
Design a simple evaluation system:
def evaluate_workflow_execution(trace_log: list, messages: list) -> dict: ...Evaluate based on:
Completion rate: Did all expected steps execute?
Message chain length: How many hops occurred vs. expected?
Context integrity: Were all required context keys preserved throughout the pipeline?
Error rate: How many retries/failures occurred?
Trace completeness: Does the trace log capture every event?
Return a structured evaluation report as a dictionary.
Task 6 — Comparative Experiment (25 Marks)
Run your orchestration engine on at least 3 different workflow scenarios:
Simple workflow: A single query that routes directly to one agent (e.g., “search_flights”)
Complex pipeline: A 4+ agent sequential pipeline (e.g., Plan → Research → Write → Review)
Error recovery scenario: A pipeline where one agent is configured to fail, triggering retry and fallback logic
For each scenario, report:
Number of messages generated
Number of hops
Context size at each step
Trace log output (formatted)
Evaluation metrics from Task 5
Whether the scenario completed successfully
Comparison Table Example
Metric | Simple | Complex Pipeline | Error Recovery |
Messages Generated | ? | ? | ? |
Total Hops | ? | ? | ? |
Retries | 0 | 0 | ? |
Dead-Lettered | 0 | 0 | ? |
Completion Rate | 100% | 100% | ?% |
Bonus (Optional — up to +10 Marks)
+3 Marks: Implement a workflow visualiser that prints an ASCII or graphical diagram of agent interactions from the trace log
+3 Marks: Add agent health monitoring — track success rate per agent and automatically remove unhealthy agents from the routing pool
+4 Marks: Implement parallel fan-out execution using Python’s concurrent.futures for agents that can run simultaneously
Difficulty & Scope
Level | Description |
Basic (50–64%) | Core infrastructure (Task 1) and at least 2 orchestration strategies (Task 3) implemented. Workflows run but limited analysis. |
Proficient (65–79%) | All tasks completed. Workflow detection (Task 2) classifies correctly. Error handling (Task 4) includes retries. Comparative experiment (Task 6) shows clear data. Report justifies design choices. |
Advanced (80–100%) | Exceptional modularity. Strategy pattern used for orchestration. Error recovery includes all mechanisms (retry, fallback, dead-letter). Evaluation framework produces detailed metrics. Report discusses production considerations and includes architecture diagrams. |
Marking Rubric
Criteria | Weight | Description |
Core Agent Infrastructure | 15% | A2AMessage, Agent, Router — modular, documented, correct |
Workflow Detection Logic | 15% | Classification logic, extensibility, accuracy |
Adaptive Orchestration Engine | 20% | 3+ strategies, controller logic, strategy selection |
Error Handling & Recovery | 15% | Retry, fallback, dead-letter, graceful degradation |
Evaluation Framework | 10% | Metrics, structured output, meaningful evaluation |
Comparative Experiment & Analysis | 15% | 3 scenarios, comparison table, insights, surprising results |
Code Quality & Modularity | 5% | File structure, docstrings, PEP 8, separation of concerns |
Report Quality | 5% | Writing clarity, design justification, architecture description |
Total | 100% |
Formatting & Structural Requirements
Element | Requirement |
Code | Clean, modular Python code in a Jupyter Notebook (.ipynb) OR a structured Python package |
If using a package, structure: | See below |
<YourName>_A2A_Assignment2/
│
├── agents/
│ ├── base.py (Agent base class)
│ ├── planner.py (PlannerAgent)
│ ├── researcher.py (ResearcherAgent)
│ ├── writer.py (WriterAgent)
│ └── reviewer.py (ReviewerAgent)
│
├── engine/
│ ├── router.py (Router class)
│ ├── orchestrator.py (Workflow orchestrator)
│ ├── detector.py (Workflow type detector)
│ └── error_handler.py (Retry, fallback, dead-letter logic)
│
├── protocol/
│ └── message.py (A2AMessage class)
│
├── evaluation/
│ └── evaluator.py (Evaluation framework)
│
├── main.py (Entry point — runs all 3 scenarios)
├── report.pdf (Report document)
└── outputs/
├── trace_logs/
└── evaluation_results/
Report | 1500–2000 words, PDF or DOCX |
Font | Times New Roman or Calibri, 12pt body, 14pt headings |
Spacing | 1.5 line spacing |
Margins | 2.54 cm (1 inch) all sides |
Citation Style | IEEE format |
Permitted Resources & Academic Integrity Policy
Same policy as Assignment 1 (see Section 7 above).
Additional notes for Assignment 2:
You may reuse and extend your code from Assignment 1
Using design patterns (Strategy, Factory, Observer) is encouraged and will be assessed positively
If you use a structured Python package (instead of a notebook), include a README.md explaining how to run your code
Declaration Statement: Same as Assignment 1 — must be included in your report.
Step-by-Step Submission Instructions on Moodle
Log in to Moodle using your student credentials
Navigate to “Agent-to-Agent (A2A)” course
Click on “Assignment 2: Adaptive Multi-Agent Orchestration Engine”
Prepare your submission as a single ZIP file:
<YourName>_A2A_Assignment2.zip
│
├── notebook.ipynb OR <package_folder>/
├── report.pdf
├── outputs/
│ ├── trace_logs/
│ └── evaluation_results/
└── README.md (if using package structure)
File Naming Convention: Lastname_Firstname_A2A_Assignment2.zip
Upload via “Add submission” → “Upload a file”
Accepted formats: .zip only (maximum 25 MB)
Click “Save changes” then “Submit assignment” to finalise
Save the confirmation email as proof
Deadline: As specified by the instructor (typically 7–10 days from release).
Late Submission Policy
Late By | Penalty |
Up to 24 hours | 10% deduction |
24–48 hours | 20% deduction |
Beyond 48 hours | Not accepted |
Support & Communication Guidelines
Channel | Details |
Office Hours | Tuesdays & Thursdays, 2:00 PM – 4:00 PM |
Forum | Post to “Assignment 2 Discussion Forum” on Moodle |
Use [A2A-A2] in the subject line for Assignment 2 queries | |
Peer Collaboration | Discuss approaches freely. Do NOT share code or reports. |
Frequently Asked Questions (FAQ)
Q1: Can I reuse my Agent and Message classes from Assignment 1?
A: Yes, you are expected to build upon your Assignment 1 code. Refactor and improve it as needed.
Q2: How should I simulate agent failures for the error handling task?
A: The simplest approach is a failure_probability attribute on agents. In process(), use random.random() < self.failure_probability to simulate random failures. Set it to 0.0 for reliable agents and 0.3–0.5 for unreliable ones.
Q3: What does “strategy-agnostic” mean for the orchestration controller?
A: Your controller should not contain hardcoded if-elif blocks for each strategy. Instead, use a dictionary mapping workflow types to strategy functions, or use the Strategy design pattern. Adding a new strategy should mean writing one new function and registering it — not changing existing code.
Q4: Is a Jupyter Notebook or a Python package preferred?
A: Either is acceptable. A notebook is simpler for submission and grading. A package demonstrates more advanced software engineering skills. Choose based on your comfort level and the complexity of your system.
Q5: How many agents should my system have?
A: At minimum 4 specialist agents plus a Router and Orchestrator. You may add more for richer workflow scenarios. Quality of agent logic matters more than quantity.
Q6: What if my workflow detection incorrectly classifies a message?
A: This is expected and should be handled gracefully. Implement a default/fallback classification. Discuss classification accuracy in your report — what signals helped, what was ambiguous.
Q7: Do I need to implement actual business logic (e.g., real flight search)?
A: No. Use mock data (hardcoded flight lists, simulated results). The focus is on the A2A infrastructure, not on the domain logic.
Q8: How should I format my trace log?
A: Export as JSON. Each entry should include: agent_name, event_type (receive/delegate/process/error), intent, timestamp, and relevant message details. See Chapter 7 for reference.
Instructor Note
This assignment is intentionally open-ended. In real-world multi-agent systems, orchestration is not a function — it is a design decision.
Your goal is to think like a system architect, not just a coder. We are looking for:
Clean separation of concerns
Thoughtful error handling
Evidence-based comparison of strategies
Production-minded design thinking
There is no single correct architecture. Justify your choices.
Call to Action
Ready to transform your business with AI-powered intelligence that accelerates insights, enhances decision-making, and unlocks the full value of your data?
Codersarts is here to help you turn complex data workflows into efficient, scalable, and evidence-driven AI systems that empower teams to make smarter, faster, and more confident decisions.
Whether you’re a startup looking to build AI-driven products, an enterprise aiming to optimize operations through data science, or a research organization advancing innovation with intelligent data solutions, we bring the expertise and experience needed to design, develop, and deploy impactful AI systems that drive measurable business outcomes.
Get Started Today
Schedule an AI & Data Science Consultation:
Book a 30-minute discovery call with our AI strategists and data science experts to discuss your challenges, identify high-impact opportunities, and explore how intelligent AI solutions can transform your workflows and performance.
Request a Custom AI Demo:
Experience AI in action with a personalized demonstration built around your business use cases, datasets, operational environment, and decision workflows — showcasing practical value and real-world impact.
Email: contact@codersarts.com
Transform your organization from data accumulation to intelligent decision enablement — accelerating insight generation, improving operational efficiency, and strengthening competitive advantage.
Partner with Codersarts to build scalable AI solutions including RAG systems, predictive analytics platforms, intelligent automation tools, recommendation engines, and custom machine learning models that empower your teams to deliver exceptional results.
Contact us today and take the first step toward next-generation AI and data science capabilities that grow with your business ambitions.

Comments