Orchestration pattern/magentic - #18
Conversation
…ase' into orchestration-pattern/magentic
bgunnar5
left a comment
There was a problem hiding this comment.
This magentic pattern will be really cool to try out.
I notice that the strategy classes and the Orchestrator are weirdly intertwined and having to make lots of calls to each other in a circular manner. This is a bit difficult to keep track of and I'm wondering if a refactor of this code would help. Maybe some things could even just be moved to the BaseStrategy class to help with this? I'm not sure what's best.
|
|
||
| Now that your agents are connected, you're free to start entering prompts into the chat box! | ||
|
|
||
| If your configuration uses `magentic` orchestration, the Gradio interface still shows the active specialist agents in the table. The hidden Magentic manager is not displayed as a participant, and only the final assistant answer is streamed back into the chat UI. |
There was a problem hiding this comment.
so users will only see the final agent's response, they won't see anything in between? Is this common for the magentic setup? It feels like having a trace of work between all agents would be useful
| ### How Agent Configuration Works | ||
|
|
||
| When MADA starts, it reads the agent configuration and loads each agent by executing the specified server path Python file. The functions decorated with `@mcp.tool` within these scripts become the MCP tools that MADA can call during a session. Agents communicate within a group chat, and the [planning agent](#the-planning-agent) coordinates which helper agent should handle each user request. | ||
| When MADA starts, it reads the agent configuration and creates the selected specialist agents. Each specialist can connect to named MCP servers from the `mcp_servers` block, or use the legacy `server_path` setting for a directly launched stdio MCP server. MADA then runs the configured orchestration mode: `agent-as-tool` exposes specialists as tools to a visible planning agent, while `magentic` coordinates specialists in a peer group chat through a hidden manager. |
There was a problem hiding this comment.
when discussing different orchestration modes, I think we should make this a bulleted list so that it can easily be extended
There was a problem hiding this comment.
Went ahead and updated the doc structure
|
|
||
| ```python | ||
| --8<-- "src/mada/core/orchestrator.py:200:203" | ||
| --8<-- "src/mada/core/orchestrator.py:549:552" |
There was a problem hiding this comment.
I initially implemented this as a source file reference but now I'm wondering if we should just copy/paste the base instructions here seeing as the orchestrator file likely has the most updates out of any file in this codebase.
|
|
||
| ```python | ||
| --8<-- "src/mada/core/orchestrator.py:212:216" | ||
| --8<-- "src/mada/core/orchestrator.py:561:565" |
There was a problem hiding this comment.
+1 to previous comment about code reference
| ## What is MADA? | ||
|
|
||
| MADA is a framework designed to facilitate collaboration between multiple specialized agents within a unified system. Built on top of the autogen framework, MADA orchestrates a [planning agent](./configuration.md#the-planning-agent) that interprets user input and delegates tasks to relevant helper agents. These agents communicate within a group chat environment, enabling dynamic problem-solving and task execution. MADA provides an intuitive interface for users to interact with the agent group, either through the command-line interface or a Gradio-based web interface, streamlining complex workflows and enhancing automation capabilities. | ||
| MADA is a framework designed to facilitate collaboration between multiple specialized agents within a unified system. Built on the Agent Framework, MADA supports an `agent-as-tool` mode where a [planning agent](./configuration.md#the-planning-agent) delegates tasks to relevant specialists, and a `magentic` mode where specialists participate in a peer group chat coordinated by a hidden manager. MADA provides CLI, Gradio, and OpenAI-compatible interfaces for interacting with the configured agent team. |
There was a problem hiding this comment.
Since this is a high-level overview, maybe we should just mention that MADA supports different orchestration modes, link to the orchestration configuration docs, and generalize this paragraph a bit more. This will scale better than having to expand on this each time we add a new orchestration mode.
| MADA begins by reading your [configuration](./configuration.md), which specifies the [model](./configuration.md#model-configuration), the [agents](./configuration.md#agent-configuration), and the optional [orchestration mode](./configuration.md#optional-orchestration-configuration). If you are using the [Gradio run mode](./usage/index.md#gradio-mode-overview), you can also provide [interface](./configuration.md#optional-gradio-interface-configuration) settings for customizing the Gradio web application UI. | ||
|
|
||
| After the group chat is established, MADA waits for user input. When a prompt is received, a [planning agent](./configuration.md#the-planning-agent)—added to the group chat automatically—interprets the input and selects the appropriate helper agent to handle the request using an mcp tool call. The helper agent’s response is streamed back to the user through the chosen interface. This interactive process continues until the session ends, either after 10 messages or when the user enters "TERMINATE". | ||
| After orchestration is initialized, MADA waits for user input. In `agent-as-tool` mode, the planning agent selects the appropriate specialist by calling that specialist as a tool. In `magentic` mode, the hidden manager coordinates a fresh peer workflow and returns the final synthesized answer. Responses are streamed back through the chosen interface. |
There was a problem hiding this comment.
+1 to my generalization comment
| DEFAULT_ORCHESTRATION_MODE = "agent-as-tool" | ||
| SUPPORTED_ORCHESTRATION_MODES = frozenset({DEFAULT_ORCHESTRATION_MODE}) | ||
| SUPPORTED_ORCHESTRATION_MODES = frozenset( | ||
| { | ||
| DEFAULT_ORCHESTRATION_MODE, | ||
| "magentic", | ||
| } | ||
| ) |
There was a problem hiding this comment.
depending on how well this works, we should consider switching the default to be magentic. Since we know agent-as-tool works already this is fine for now though
| return value | ||
|
|
||
|
|
||
| class MagenticOrchestrationStrategy(AgentAsToolOrchestrationStrategy): |
There was a problem hiding this comment.
should we be inheriting from AgentAsTool or the BaseStrategy?
There was a problem hiding this comment.
Refactored much more code into the base strategy, so there is no more nested dependency, as intended.
class MagenticOrchestrationStrategy(BaseOrchestrationStrategy):
| ) | ||
|
|
||
| return MagenticBuilder( | ||
| participants=orchestrator.specialist_agents, |
There was a problem hiding this comment.
will this specialist list already be filtered based on the user's orchestration block settings in their config file by the time we get here?
Magentic is a peer-workflow orchestration mode.
In agent-as-tool, MADA creates a visible PlanningAgent, exposes specialists as tools, and keeps a reusable planner session. In magentic, MADA creates the configured specialist agents as peers, then creates a hidden manager agent that coordinates a fresh Magentic workflow for each request. The hidden manager is not listed as a participant and its planning/progress chatter is filtered so users receive the final assistant answer.
To enable it in a workflow config, set the top-level orchestration.mode: