Documentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
Overview
swarms.structs.ma_blocks is a tiny set of helper functions for composing multi-agent workflows without instantiating a full swarm class. Three functions:
| Function | What it does |
|---|---|
aggregate | Run a list of agents concurrently on the same task, then synthesize via an aggregator agent |
run_agent | Run a single agent with argument validation and error wrapping |
find_agent_by_name | Look up an agent by .name in a list |
ConcurrentWorkflow(...).run(...).
Installation
aggregate()
Run every worker on the same task concurrently, then hand the combined transcript to an aggregator agent for synthesis.Agents (or any callables matching the
Agent interface) to run on the task.Task passed to every worker.
Output format passed to
history_output_formatter.Model used by the synthesizing aggregator agent.
ValueError if task is None, workers is None, or workers is not a list of callables.
Behavior:
- All workers run concurrently via
run_agents_concurrently. - Each worker’s result is added to a shared
Conversation, keyed byworker.agent_name. - A new
Aggregatoragent runs withAGGREGATOR_SYSTEM_PROMPTand produces a ~3,000-word synthesis of the worker outputs. - The aggregator’s response is appended to the conversation.
- The full conversation is returned formatted per
type.
run_agent()
Run a single agent on a task with type-checking and error wrapping. Thin convenience overagent.run(task).
Must be an instance of
swarms.structs.agent.Agent.Task passed to the agent.
Accepted but not currently consumed beyond the call — present for API parity with
aggregate.| Exception | Condition |
|---|---|
ValueError | agent or task is None |
TypeError | agent is not an Agent instance |
RuntimeError | Any exception raised by agent.run() is wrapped and re-raised |
agent.run(task) returns.
find_agent_by_name()
Linear search for an agent by its.name attribute.
Non-empty list of agent-like objects.
Name to match against
agent.name (note: .name, not .agent_name).| Exception | Condition |
|---|---|
ValueError | agents is empty, agent_name is empty/whitespace, or no match found |
TypeError | agent_name is not a string |
RuntimeError | Any inner exception is wrapped and re-raised |
Usage Examples
Aggregate Concurrent Analyses
Safe Single-Agent Run
Look Up an Agent by Name
find_agent_by_name matches against the .name attribute, not .agent_name. Set .name explicitly when you intend to look agents up this way.