Orchestration: Magentic
Key Points
- Magentic-One pattern: a planner LLM orchestrates a team of specialized agents to accomplish complex tasks.
- Plan → execute → reflect → adjust loop.
- For complex, exploratory tasks like "research and produce a market analysis report".
- Higher cost; higher capability ceiling.
- From Microsoft Research's Magentic-One paper / project.
Concept
[User task: "Research X and write a report"]
│
▼
[Orchestrator (Planner)]
│ plan
│
├─→ [WebSearcher Agent] → results
├─→ [Coder Agent] → analyze data
├─→ [WebViewer Agent] → screenshot pages
└─→ [FileSaver Agent] → save outputs
│
▼
[Orchestrator: reflect on results, adjust plan]
│
▼
[Iterate until done]
Components
- Orchestrator: top-level planner; decides next steps.
- Specialists: WebSearcher, Coder, WebViewer (browser ops), FileSaver, etc.
- Memory: tracks plan + state.
- Termination: orchestrator decides when done.
Code (sketch)
var websearcher = new ChatClientAgent(chat) {
Name = "WebSearcher",
Instructions = "Search the web; return relevant snippets.",
Tools = [AIFunctionFactory.Create(WebSearch)]
};
var coder = new ChatClientAgent(chat) {
Name = "Coder",
Instructions = "Write Python to analyze data; execute via tools.",
Tools = [AIFunctionFactory.Create(ExecutePython)]
};
var viewer = new ChatClientAgent(chat) {
Name = "WebViewer",
Instructions = "Open URLs in browser; describe content.",
Tools = [AIFunctionFactory.Create(OpenUrl), AIFunctionFactory.Create(Screenshot)]
};
var saver = new ChatClientAgent(chat) {
Name = "FileSaver",
Tools = [AIFunctionFactory.Create(WriteFile)]
};
var orchestration = new MagenticOrchestration(
specialists: [websearcher, coder, viewer, saver],
plannerChat: chat,
maxIterations: 20);
var result = await orchestration.InvokeAsync("Research the market for EV charging stations in Europe and write a 3-page report.");
Loop logic
1. Planner: "Initial plan: search → analyze → write."
2. Planner picks next agent + sub-task.
3. Agent runs; returns result.
4. Planner reflects: "Did that work? What next?"
5. If complete → terminate.
6. Else → goto 2.
Use cases
- Deep research reports.
- Coding agents that browse + write + execute + iterate.
- Multi-tool tasks like "find all PRs over 30 days old, summarize, post to Slack".
- OS-level automation (with appropriate guards).
Cost
Highest. Many iterations × many specialist calls. Easy to spend $1-10 per run with frontier models.
Cap with maxIterations and budget.
Streaming
await foreach (var update in orchestration.InvokeStreamingAsync(task))
{
Console.WriteLine($"[{update.Stage}] {update.Text}");
// Stage: "Planning", "Executing:WebSearcher", "Reflecting", etc.
}
UX critical — show plan + each step.
Safety
Magentic agents may execute code, browse, write files. Sandboxing critical.
- Run code in containers.
- Limit file write paths.
- No production data access without approval.
- Human-in-the-loop for high-stakes ops.
When NOT magentic
- Simple tasks (overkill).
- Tight latency (slow).
- Cost-sensitive.
Comparison
| Pattern | Use |
|---|---|
| Sequential | Known steps |
| Concurrent | Parallel perspectives |
| Group chat | Conversational debate |
| Handoff | Routing by domain |
| Magentic | Complex exploratory + execution |
Senior considerations
- Sandbox EVERYTHING: agent can do whatever its tools allow.
- Cap iterations + budget: hard limits.
- Human review for high-stakes outputs.
- Reproducibility: same input may yield different output (LLM stochasticity).
- Eval is hard: complex outputs; LLM-as-judge or human review.
Anti-patterns
- ❌ Unbounded iterations.
- ❌ Production access without sandbox.
- ❌ Magentic for simple tasks.
- ❌ No tracing — debug nightmare.
Cross-references
- Microsoft Magentic-One paper / blog
- MCP Integration — tools as MCP servers
- Workflows vs Agents
- AI Security