Multi-Agent Architecture with Multimodal Models: A Practical Guide
This article explains why a single all-purpose model often fails in real engineering environments and how a Manager-Worker multi-agent architecture solves the problem. You will learn how to structure task contracts, route work by complexity, run untrusted code in isolated sandboxes, manage long context, and control cost and reliability through observability. The guide also covers common anti-patterns and a phased adoption roadmap.
1. Why One Model for Everything No Longer Works
As multimodal foundation models improve quickly, many teams still look for a single “strongest model” to handle every task end to end. In real engineering environments, this approach runs into three problems:
- Unbalanced cost structure: Low-difficulty work such as requirement clarification, document drafting, and status summaries makes up a large share of daily demand, yet it always hits the most expensive inference tier. Token consumption and latency are inflated for no reason.
- Capability mismatch: A model that is good at natural language communication and context understanding is not necessarily the best choice for complex algorithm derivation, formal proofs, or low-level code implementation, and the reverse also holds.
- Context pollution: Stuffing vague requirements, long documents, code snippets, and error logs into one session causes conflicting instructions and diluted attention, which noticeably degrades output quality.
A more sensible approach borrows the layered design from software engineering: separate the human-facing interface layer from the machine-facing execution layer, assign each to agents with the right specialty, and communicate through a structured protocol.
2. Architecture Overview: A Manager-Worker Two-Tier Model
The overall design has three layers:
- Interaction layer (Manager agent): Multimodal, long context, low latency. It aligns vague requirements, breaks down tasks, orchestrates plans, and summarizes results.
- Execution layer (Worker agent): Runs in an isolated sandbox and handles hard logic, mathematical derivation, complex code generation, and testing.
- Infrastructure layer: Task queue, object storage, container platform, logging, and monitoring with alerting. It provides state persistence and observability.
The key design principle is load on demand: the default path stays lightweight, and the execution layer is spun up only when a request meets the “hard task” criteria. This avoids paying heavy inference costs for simple requests.
User input|v[Manager] Clarify requirements / Decompose tasks / Generate plan|v Structured task ticket (JSON)[Router] Complexity and risk assessment|-- Low complexity --> [Manager] Produces output directly`-- High complexity --> Queue --> [Worker sandbox] Execute --> Artifacts|v[Manager] Accept / Regression check / Report in plain language
3. Task Dispatch: Turning “Vague” into an “Executable Contract”
The most common reason multi-agent systems fail is not a weak model but a task ticket written like a chat message. The execution layer needs clear boundaries. A task ticket should include at least: goal, input references, constraints, acceptance criteria, prohibited actions, and output format.
{"task_id": "T-20240819-001","goal": "Implement a sliding-window rate limiter and add unit tests","inputs": ["oss://bucket/spec/limiter.md"],"constraints": ["Use only the standard library","Concurrency safe","Do not change public interface signatures"],"acceptance": ["All unit tests pass","No counter drift under load testing"],"output": "patch + test_report"}
For routing, use a dual channel of explainable rules plus model scoring: rules first match high-risk keywords (proof, concurrency, encryption, protocol implementation, performance optimization), then the manager model gives a complexity score from 0 to 1, and dispatch happens once the score passes the threshold. The rule channel ensures reproducibility; the model channel ensures generalization.
4. Isolated Execution and Security Controls
Once the execution layer can write files and run commands, treat it as an untrusted environment:
- Least privilege: Mount the code repository read-only, restrict writes to a dedicated working directory, disable network access by default, and preinstall dependencies in the image.
- Resource quotas: Limit CPU, memory, execution time, and concurrency. Terminate and reclaim resources on timeout.
- Artifact validation: Write all artifacts to object storage with a digest hash. The manager checks each acceptance criterion one by one. If validation fails, retry with the failure reason attached, and set an explicit cap on retry attempts.
- End-to-end audit: Send prompts, task tickets, commands, exit codes, and durations to the logging service, and use monitoring and alerting to set thresholds for failure rate and latency percentiles.
5. Context Engineering: Using Long Text Correctly
A million-token context window solves “can it fit” but not “is it used well.” Practical recommendations:
- Layered retrieval: Use keyword or vector retrieval to recall relevant fragments first, then have the manager refine them. Avoid loading an entire corpus directly.
- Rolling summaries: Generate a rolling summary per turn for long sessions, store raw details, and fetch them by reference when needed.
- Multimodal alignment: Convert screenshots, UI images, and architecture diagrams into structured descriptions and annotations before they enter the reasoning chain, reducing visual noise.
- Role isolation: Give the manager and workers separate contexts, exchanging only task tickets and artifacts to prevent cross-contamination of instructions.
6. Observability and Cost Governance
The core metrics to monitor are straightforward: task success rate, first-pass rate, average retry count, end-to-end latency P50/P95, Token cost per task, and sandbox abnormal termination rate. Cost governance has three levers: adjust routing thresholds dynamically by task type; build templates and caches for high-frequency simple requests; and batch long-document processing to reduce repeated parsing.
7. Common Anti-Patterns
- Over-orchestration: Sending simple tasks through the full pipeline, raising both latency and cost.
- Missing contracts: Passing only natural language descriptions, letting the execution layer improvise, and leaving acceptance with nothing to check against.
- No fallback design: Retrying endlessly after failure and amplifying the incident.
- Formalistic acceptance: Checking only whether output exists, not whether it meets the acceptance criteria.
8. Adoption Roadmap
In phase one, run only “Manager plus human execution” and standardize requirement clarification and task tickets. In phase two, introduce the sandbox execution layer and acceptance-based fallback. In phase three, add retrieval, caching, and dynamic routing to close the loop. If you use general capabilities such as the container platform, object storage, message queue, and logging and monitoring on Baidu AI Cloud to carry the infrastructure above, you can focus your effort on designing the protocol and acceptance criteria instead of rebuilding the foundation. The benefit of multi-agent collaboration does not come from having more models; it comes from clear responsibility boundaries, strict communication contracts, and controllable failure paths.
