A multi-agent orchestration manager that routes messages between agents
in an automated workflow, with support for termination conditions and
dynamic agent selection.
This class coordinates the execution of multiple agents in a round-based
loop. It starts with an initial message sent to the first agent, then uses
an internal `agent_manager` to determine the next agent to route the
response to. The process continues until:
- The termination function returns True, or
- The maximum number of rounds is reached.
Attributes:
auto_agent (Agent): An internal controller agent responsible for
deciding which agent should handle the next step.
first_agent (Agent): The first agent to receive the initial message.
termination_fn (Callable): Optional function to determine when the
workflow should stop.
max_round (int): Maximum number of message-passing iterations allowed.
agents (dict[str, Agent]): Dictionary of available agents, keyed by
agent name.
init_msg (Message): The initial message passed to the first agent.
termination_word (str): Optional keyword used by `termination_fn` to
detect completion.
Args:
init_message (str): The initial request or instruction from the user.
agents (List[Agent]): The list of agents participating in the workflow.
first_agent (Agent): The starting agent for message routing.
max_round (int, optional): Maximum number of routing rounds. Defaults to 3.
termination_fn (Callable, optional): A function to check if the process
should terminate early. Defaults to None.
termination_word (str, optional): Keyword used in termination checks.
Defaults to None.
Methods:
start(message: str = None) -> Message:
Executes the multi-agent workflow starting from either the
`init_message` or a provided `message`.
The process:
- Sends the message to the current agent.
- Evaluates termination conditions after each response.
- Uses `auto_agent` to determine the next agent in the sequence.
- Stops when the termination function returns True or the
maximum round count is reached.
Returns the final `Message` from the last executed agent.