Group specialist agents into trees and send each task to the one agent whose system prompt matches it
A ForestSwarm holds trees of agents. Each Tree groups the agents for one domain, such as tax or investing. When a task comes in, the forest walks its trees in order and hands the task to the first agent that matches it. No model makes the choice: matching uses keywords taken from each agent’s system prompt, then the embedding similarity between the task and that prompt. One agent answers each task.ForestSwarm, Tree and TreeAgent are not exported from the top-level swarms package. Import them from swarms.structs.tree_swarm.Reference: ForestSwarm.
How an agent is picked
Step
What happens
Build a TreeAgent
It embeds its system prompt once and keeps the five most frequent words of the prompt as keywords. One-letter words and common stop words are dropped.
Build a Tree
It gives each agent a distance to the agent listed before it, then sorts its agents by that distance.
Run a task
The forest checks its trees in the order you gave, and each tree’s agents in sorted order. An agent matches when one of its keywords appears as a word in the task. If none does, the task is embedded and the agent matches when the cosine similarity is 0.7 or more.
Answer
The first agent that matches runs the task on a fresh conversation, and its output is returned.
1. Build a forest and run a task
Each specialist is a TreeAgent: a regular Agent with an embedding model for its system prompt. Put the domain words you want to match at the start of the prompt and repeat the most important one. The keywords are the five most frequent words, and ties go to the word that comes first.
from swarms.structs.tree_swarm import ForestSwarm, Tree, TreeAgentdef specialist(name: str, system_prompt: str) -> TreeAgent: """Build a one-loop tree agent that embeds its prompt with text-embedding-3-small.""" return TreeAgent( agent_name=name, system_prompt=system_prompt, model_name="gpt-5.4-mini", embedding_model_name="text-embedding-3-small", max_loops=1, )tax_tree = Tree( tree_name="Tax", agents=[ specialist( "Corporate-Tax-Advisor", "Corporate tax advisor. Corporate tax filing, Delaware " "corporations, deductions, quarterly estimated tax.", ), specialist( "Personal-Tax-Advisor", "Personal tax advisor. Income tax returns, tax credits, " "filing status, refunds for individuals.", ), ],)investing_tree = Tree( tree_name="Investing", agents=[ specialist( "Stock-Analyst", "Stock analyst. Stocks, earnings, valuation, sectors, market trends.", ), specialist( "Retirement-Planner", "Retirement planner. Retirement savings, 401k, Roth IRA, " "pension, withdrawal plans.", ), ],)forest = ForestSwarm( name="Finance-Forest", description="Routes finance questions to one specialist", trees=[tax_tree, investing_tree],)answer = forest.run( "How should a small Delaware corporation plan its quarterly estimated tax payments?")print(answer)
The task contains tax and delaware, two of the Corporate-Tax-Advisor’s keywords, so that agent answers.
The default embedding model is text-embedding-ada-002. In our tests it scored unrelated text above 0.7, so the first agent in the first tree matched almost every task, including a question about stocks and one about retirement accounts. text-embedding-3-small scores unrelated text far lower, so routing follows the keywords and the embedding check passes only on a close match. Set embedding_model_name on every agent.
2. Check the routing before you run
find_relevant_tree() and Tree.find_relevant_agent() run the same matching as run() without calling the language model. Use them to test your system prompts. They do call the embedding model for any agent whose keywords miss.
for tree in forest.trees: for agent in tree.agents: print(tree.tree_name, agent.agent_name, agent.relevant_keywords)tasks = [ "Should I move my 401k into a Roth IRA before I retire?", "Which sectors drove the latest earnings season?", "What is a good recipe for banana bread?",]for task in tasks: tree = forest.find_relevant_tree(task) agent = tree.find_relevant_agent(task) if tree else None print(task) print(" tree:", tree.tree_name if tree else None) print(" agent:", agent.agent_name if agent else None)
The keywords print as, for example, ['retirement', 'planner', 'savings', '401k', 'roth']. The first task goes to Retirement-Planner through 401k and roth, and the second to Stock-Analyst through earnings. Nothing matches the banana bread question, so both lookups return None.
3. Run several tasks
batched_run() calls run() once per task and returns the results in task order.
results = forest.batched_run(tasks)for task, result in zip(tasks, results): print(f"=== {task}\n{result[:300]}\n")
The banana bread task returns the string "No relevant agent found to handle this task." instead of an answer.
batched_run() also accepts max_workers to run tasks in threads. Leave it unset when two tasks can reach the same agent. A TreeAgent has one conversation, and in our test two tasks that ran at the same time on the same agent came back with the same answer.
Reading the output
One answer per task.run() returns the selected agent’s output, shaped by that agent’s output_type (the Agent default is "str-all-except-first"). The agent is reset before each task, so the output covers only this task.
No match.run() returns "No relevant agent found to handle this task."
Errors.run() never raises. If routing or the agent fails, it returns None. Pass verbose=True to the forest to see the error in the log.
No shared history. The forest’s conversation is not updated by run(). Keep your own record of which agent answered, using find_relevant_tree() as in step 2.
Token usage.forest.usage sums the provider token usage of every agent in every tree.
Tips
Order matters. The first match wins and agents are not ranked against each other. Put the most specific trees first.
Keep keywords specific. A keyword such as advisor or planner matches any task that uses the word. Name agents and write prompts so the frequent words are domain terms.
Building costs one embedding call per agent. Build the forest once and reuse it.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"swarms","colors":{"primary":"#DC2626","light":"#FFFFFF","dark":"#000000"},"logo":{"light":"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/light.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=e3d664b8b8f6928c836776b54704d076","dark":"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/dark.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=d1f710292b2b40794b44a3168a6b09dc"},"favicon":"https://mintcdn.com/kyegomez-swarms-97/UEClO9jJGrigmMUe/logo.svg?fit=max\u0026auto=format\u0026n=UEClO9jJGrigmMUe\u0026q=85\u0026s=07dcb5f5b9bca5ec8fd6475dcc9b5484","navbar":{"primary":{"type":"github","href":"https://github.com/kyegomez/swarms"}},"footer":{"socials":{"twitter":"https://twitter.com/swarms_corp","github":"https://github.com/kyegomez/swarms","website":"https://swarms.ai","linkedin":"https://www.linkedin.com/company/the-swarm-corporation","discord":"https://discord.gg/EamjgSaEQf","youtube":"https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ","medium":"https://medium.com/@kyeg"}},"contextual":{"options":["copy","view","chatgpt","claude","cursor","vscode"],"display":"header"},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"kyegomez-swarms-97","hasAudioNarration":false,"actualSubdomain":"kyegomez-swarms-97","customDomains":["docs.swarms.world"],"gitSource":{"type":"github","owner":"the-swarm-corporation","repo":"swarms-framework-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6b10944331e27df1bf18503c","clientVersion":"0.0.4416","searchFilterCounts":[{"language":"default","tag":"Examples","count":145},{"language":"default","tag":"API Reference","count":63},{"language":"default","tag":"Documentation","count":60},{"language":"default","tag":"Multi-Agent Harnesses","count":37},{"language":"default","tag":"Multi-Agent Examples","count":34},{"language":"default","tag":"Comms Channels","count":17},{"language":"default","tag":"RouteHub","count":17},{"language":"default","tag":"MCP Tool Integrations","count":15},{"language":"default","tag":"Model Providers","count":14},{"language":"default","tag":"Community","count":13}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"auth-vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":false},"customCss":[]}
{"page":{"pagePath":"examples/multi-agent/forest-swarm-example","slug":"/examples/multi-agent/forest-swarm-example","pageMetadata":{"title":"ForestSwarm Guide","description":"Group specialist agents into trees and send each task to the one agent whose system prompt matches it","icon":"tree","href":"/examples/multi-agent/forest-swarm-example"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`A `,_jsx(_components.code,{children:`ForestSwarm`}),` holds trees of agents. Each `,_jsx(_components.code,{children:`Tree`}),` groups the agents for one domain, such as tax or investing. When a task comes in, the forest walks its trees in order and hands the task to the first agent that matches it. No model makes the choice: matching uses keywords taken from each agent’s system prompt, then the embedding similarity between the task and that prompt. One agent answers each task.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ForestSwarm`}),`, `,_jsx(_components.code,{children:`Tree`}),` and `,_jsx(_components.code,{children:`TreeAgent`}),` are not exported from the top-level `,_jsx(_components.code,{children:`swarms`}),` package. Import them from `,_jsx(_components.code,{children:`swarms.structs.tree_swarm`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`Reference: `,_jsx(_components.a,{href:`/api/forest-swarm`,children:`ForestSwarm`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`how-an-agent-is-picked`,children:`How an agent is picked`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Step`}),_jsx(_components.th,{children:`What happens`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsxs(_components.td,{children:[`Build a `,_jsx(_components.code,{children:`TreeAgent`})]}),_jsx(_components.td,{children:`It embeds its system prompt once and keeps the five most frequent words of the prompt as keywords. One-letter words and common stop words are dropped.`})]}),_jsxs(_components.tr,{children:[_jsxs(_components.td,{children:[`Build a `,_jsx(_components.code,{children:`Tree`})]}),_jsx(_components.td,{children:`It gives each agent a distance to the agent listed before it, then sorts its agents by that distance.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Run a task`}),_jsx(_components.td,{children:`The forest checks its trees in the order you gave, and each tree’s agents in sorted order. An agent matches when one of its keywords appears as a word in the task. If none does, the task is embedded and the agent matches when the cosine similarity is 0.7 or more.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Answer`}),_jsx(_components.td,{children:`The first agent that matches runs the task on a fresh conversation, and its output is returned.`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`1-build-a-forest-and-run-a-task`,children:`1. Build a forest and run a task`}),`\n`,_jsxs(_components.p,{children:[`Each specialist is a `,_jsx(_components.code,{children:`TreeAgent`}),`: a regular `,_jsx(_components.code,{children:`Agent`}),` with an embedding model for its system prompt. Put the domain words you want to match at the start of the prompt and repeat the most important one. The keywords are the five most frequent words, and ties go to the word that comes first.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`55`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`55`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` swarms.structs.tree_swarm `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ForestSwarm, Tree, TreeAgent`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` specialist`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`system_prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> TreeAgent:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"\"Build a one-loop tree agent that embeds its prompt with text-embedding-3-small.\"\"\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TreeAgent(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` agent_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`name,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` system_prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`system_prompt,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-5.4-mini\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` embedding_model_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text-embedding-3-small\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_loops`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tax_tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Tree(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tree_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Tax\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` agents`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` specialist(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Corporate-Tax-Advisor\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Corporate tax advisor. Corporate tax filing, Delaware \"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"corporations, deductions, quarterly estimated tax.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` specialist(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Personal-Tax-Advisor\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Personal tax advisor. Income tax returns, tax credits, \"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"filing status, refunds for individuals.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`investing_tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Tree(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tree_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Investing\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` agents`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` specialist(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Stock-Analyst\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Stock analyst. Stocks, earnings, valuation, sectors, market trends.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` specialist(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Retirement-Planner\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Retirement planner. Retirement savings, 401k, Roth IRA, \"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"pension, withdrawal plans.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`forest `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ForestSwarm(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Finance-Forest\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` description`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Routes finance questions to one specialist\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` trees`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[tax_tree, investing_tree],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`answer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` forest.run(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"How should a small Delaware corporation plan its quarterly estimated tax payments?\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(answer)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The task contains `,_jsx(_components.code,{children:`tax`}),` and `,_jsx(_components.code,{children:`delaware`}),`, two of the Corporate-Tax-Advisor’s keywords, so that agent answers.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`The default embedding model is `,_jsx(_components.code,{children:`text-embedding-ada-002`}),`. In our tests it scored unrelated text above 0.7, so the first agent in the first tree matched almost every task, including a question about stocks and one about retirement accounts. `,_jsx(_components.code,{children:`text-embedding-3-small`}),` scores unrelated text far lower, so routing follows the keywords and the embedding check passes only on a close match. Set `,_jsx(_components.code,{children:`embedding_model_name`}),` on every agent.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`2-check-the-routing-before-you-run`,children:`2. Check the routing before you run`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`find_relevant_tree()`}),` and `,_jsx(_components.code,{children:`Tree.find_relevant_agent()`}),` run the same matching as `,_jsx(_components.code,{children:`run()`}),` without calling the language model. Use them to test your system prompts. They do call the embedding model for any agent whose keywords miss.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` forest.trees:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree.agents:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(tree.tree_name, agent.agent_name, agent.relevant_keywords)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tasks `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Should I move my 401k into a Roth IRA before I retire?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Which sectors drove the latest earnings season?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"What is a good recipe for banana bread?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` task `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tasks:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` forest.find_relevant_tree(task)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree.find_relevant_agent(task) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(task)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\" tree:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, tree.tree_name `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tree `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\" agent:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, agent.agent_name `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The keywords print as, for example, `,_jsx(_components.code,{children:`['retirement', 'planner', 'savings', '401k', 'roth']`}),`. The first task goes to Retirement-Planner through `,_jsx(_components.code,{children:`401k`}),` and `,_jsx(_components.code,{children:`roth`}),`, and the second to Stock-Analyst through `,_jsx(_components.code,{children:`earnings`}),`. Nothing matches the banana bread question, so both lookups return `,_jsx(_components.code,{children:`None`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`3-run-several-tasks`,children:`3. Run several tasks`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`batched_run()`}),` calls `,_jsx(_components.code,{children:`run()`}),` once per task and returns the results in task order.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`results `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` forest.batched_run(tasks)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` task, result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` zip`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(tasks, results):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"=== `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`task`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result[:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`300`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The banana bread task returns the string `,_jsx(_components.code,{children:`\"No relevant agent found to handle this task.\"`}),` instead of an answer.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`batched_run()`}),` also accepts `,_jsx(_components.code,{children:`max_workers`}),` to run tasks in threads. Leave it unset when two tasks can reach the same agent. A `,_jsx(_components.code,{children:`TreeAgent`}),` has one conversation, and in our test two tasks that ran at the same time on the same agent came back with the same answer.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`reading-the-output`,children:`Reading the output`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`One answer per task.`}),` `,_jsx(_components.code,{children:`run()`}),` returns the selected agent’s output, shaped by that agent’s `,_jsx(_components.code,{children:`output_type`}),` (the `,_jsx(_components.code,{children:`Agent`}),` default is `,_jsx(_components.code,{children:`\"str-all-except-first\"`}),`). The agent is reset before each task, so the output covers only this task.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`No match.`}),` `,_jsx(_components.code,{children:`run()`}),` returns `,_jsx(_components.code,{children:`\"No relevant agent found to handle this task.\"`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Errors.`}),` `,_jsx(_components.code,{children:`run()`}),` never raises. If routing or the agent fails, it returns `,_jsx(_components.code,{children:`None`}),`. Pass `,_jsx(_components.code,{children:`verbose=True`}),` to the forest to see the error in the log.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`No shared history.`}),` The forest’s `,_jsx(_components.code,{children:`conversation`}),` is not updated by `,_jsx(_components.code,{children:`run()`}),`. Keep your own record of which agent answered, using `,_jsx(_components.code,{children:`find_relevant_tree()`}),` as in step 2.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Token usage.`}),` `,_jsx(_components.code,{children:`forest.usage`}),` sums the provider token usage of every agent in every tree.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`tips`,children:`Tips`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Order matters.`}),` The first match wins and agents are not ranked against each other. Put the most specific trees first.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Keep keywords specific.`}),` A keyword such as `,_jsx(_components.code,{children:`advisor`}),` or `,_jsx(_components.code,{children:`planner`}),` matches any task that uses the word. Name agents and write prompts so the frequent words are domain terms.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Building costs one embedding call per agent.`}),` Build the forest once and reuse it.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps`,children:`Next steps`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/api/forest-swarm`,children:`ForestSwarm reference`})}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/examples/swarm-router-example`,children:`SwarmRouter guide`}),` for routing with a model instead of keywords`]}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://github.com/kyegomez/swarms/tree/master/examples/multi_agent/forest_swarm_examples`,children:`Runnable scripts`})}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"ForestSwarm Guide","description":"Group specialist agents into trees and send each task to the one agent whose system prompt matches it","icon":"tree","href":"/examples/multi-agent/forest-swarm-example"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How an agent is picked","slug":"how-an-agent-is-picked","depth":2,"children":[]},{"title":"1. Build a forest and run a task","slug":"1-build-a-forest-and-run-a-task","depth":2,"children":[]},{"title":"2. Check the routing before you run","slug":"2-check-the-routing-before-you-run","depth":2,"children":[]},{"title":"3. Run several tasks","slug":"3-run-several-tasks","depth":2,"children":[]},{"title":"Reading the output","slug":"reading-the-output","depth":2,"children":[]},{"title":"Tips","slug":"tips","depth":2,"children":[]},{"title":"Next steps","slug":"next-steps","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"kyegomez-swarms-97","siteName":"swarms","title":"ForestSwarm Guide - swarms","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-12-02T21:57:28.191Z","originalFileLocation":"examples/multi-agent/forest-swarm-example.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\">\u003cmeta data-mint-head name=\"application-name\" content=\"swarms\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"ForestSwarm Guide - swarms\">\u003cmeta data-mint-head property=\"og:description\" content=\"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"swarms\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://kyegomez-swarms-97.mintlify.site/_mintlify/api/og/v2?division=Multi-Agent+Examples\u0026amp;title=ForestSwarm+Guide\u0026amp;description=Group+specialist+agents+into+trees+and+send+each+task+to+the+one+agent+whose+system+prompt+matches+it\u0026amp;theme=ba8c70c5ea28f09121ef6c53\u0026amp;signature=36c9c177d61666e91d86e969d920578f64ef05d1920e36f7e5fdee0eb13a9e33\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"ForestSwarm Guide - swarms\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://kyegomez-swarms-97.mintlify.site/_mintlify/api/og/v2?division=Multi-Agent+Examples\u0026amp;title=ForestSwarm+Guide\u0026amp;description=Group+specialist+agents+into+trees+and+send+each+task+to+the+one+agent+whose+system+prompt+matches+it\u0026amp;theme=ba8c70c5ea28f09121ef6c53\u0026amp;signature=36c9c177d61666e91d86e969d920578f64ef05d1920e36f7e5fdee0eb13a9e33\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"swarms\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#DC2626\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/examples/multi-agent/forest-swarm-example.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.swarms.world/#organization\",\"name\":\"swarms\",\"url\":\"https://docs.swarms.world\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/light.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=e3d664b8b8f6928c836776b54704d076\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.swarms.world#website\",\"name\":\"swarms\",\"url\":\"https://docs.swarms.world\",\"publisher\":{\"@id\":\"https://docs.swarms.world/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example#webpage\",\"url\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example\",\"name\":\"ForestSwarm Guide\",\"description\":\"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\",\"dateModified\":\"2026-12-02T21:57:28.191Z\",\"isPartOf\":{\"@id\":\"https://docs.swarms.world#website\"},\"breadcrumb\":{\"@id\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Multi-Agent Examples\",\"item\":\"https://docs.swarms.world/examples/overviews/multi-agent-overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ForestSwarm Guide\",\"item\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example#article\",\"headline\":\"ForestSwarm Guide\",\"name\":\"ForestSwarm Guide\",\"description\":\"Group specialist agents into trees and send each task to the one agent whose system prompt matches it\",\"url\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example\",\"mainEntityOfPage\":{\"@id\":\"https://docs.swarms.world/examples/multi-agent/forest-swarm-example#webpage\"},\"dateModified\":\"2026-12-02T21:57:28.191Z\",\"publisher\":{\"@id\":\"https://docs.swarms.world/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.swarms.world#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"swarms\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"swarms\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/examples/multi-agent/forest-swarm-example.md","siteName":"swarms","nav":{"global":null,"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":"/introduction"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api/agent"}]},{"tab":"RouteHub","pages":[{"title":"RouteHub","href":"/routehub/overview"}]},{"tab":"Swarms API","pages":[{"title":"Swarms API","href":"/swarms-api/overview"}]},{"tab":"Examples","groups":[{"group":"Index","pages":[{"title":"Overview","icon":"table-list","href":"/examples/overview"},{"title":"Examples Index","icon":"book","href":"/examples/overviews/examples-index"},{"title":"Swarms Cookbook","icon":"book-open","href":"/examples/overviews/cookbook"},{"title":"Community Resources","icon":"users","href":"/examples/overviews/community-resources"}]},{"group":"Basic Examples","pages":[{"title":"Basic Examples Overview","icon":"graduation-cap","href":"/examples/overviews/basic-overview"},{"title":"Basic Agent","icon":"robot","href":"/examples/basic-agent"},{"title":"Agent with Tools","icon":"wrench","href":"/examples/agent-with-tools"},{"title":"Dynamic Tool Usage","icon":"magnifying-glass-arrow-right","href":"/examples/tools/dynamic-tool-usage"},{"title":"Vision Agent","icon":"eye","href":"/examples/vision-agent"},{"title":"Streaming Responses","icon":"tower-broadcast","href":"/examples/streaming"},{"title":"Agent Streaming","icon":"bolt","href":"/examples/agent-streaming-example"}]},{"group":"Model Providers","pages":[{"title":"Building Agents with Anthropic","icon":"anthropic","href":"/examples/model-providers/anthropic"},{"title":"Building Agents with OpenAI","icon":"openai","href":"/examples/model-providers/openai"},{"title":"Building Agents with Gemini","icon":"google","href":"/examples/model-providers/gemini"},{"title":"Gemini Decision Model","icon":"google","href":"/examples/model-providers/gemini-decision-model"},{"title":"Claude Fable 5","icon":"sparkles","href":"/examples/model-providers/claude-fable-5"},{"title":"Building Agents with Groq","icon":"bolt","href":"/examples/model-providers/groq"},{"title":"Building Agents with Cerebras","icon":"gauge-high","href":"/examples/model-providers/cerebras"},{"title":"Building Agents with DeepSeek","icon":"brain","href":"/examples/model-providers/deepseek"},{"title":"Building Agents with xAI (Grok)","icon":"x","href":"/examples/model-providers/xai"},{"title":"Building Agents with Ollama","icon":"house","href":"/examples/model-providers/ollama"},{"title":"Building Agents with vLLM","icon":"server","href":"/examples/model-providers/vllm"},{"title":"Building Agents with OpenRouter","icon":"route","href":"/examples/model-providers/openrouter"},{"title":"OpenRouter Tutorial: Single Agents, Group Chat \u0026 Concurrent Workflows","icon":"route","href":"/examples/model-providers/openrouter-tutorial"},{"title":"Building Agents with Azure OpenAI","icon":"microsoft","href":"/examples/model-providers/azure-openai"}]},{"group":"Single Agent","pages":[{"title":"RAG Examples Overview","icon":"database","href":"/examples/overviews/rag-overview"},{"title":"Agent Streaming","icon":"wave-pulse","href":"/examples/agents/agent-streaming"},{"title":"Advanced Research","icon":"flask","href":"/examples/agents/advanced-research"},{"title":"Autonomous Looper with Bash","icon":"terminal","href":"/examples/agents/autonomous-looper-bash"},{"title":"Autonomous Looper with Tools","icon":"screwdriver-wrench","href":"/examples/agents/autonomous-looper-tools"},{"title":"Persistent Memory","icon":"database","href":"/examples/agents/persistent-memory"},{"title":"Context Compression","icon":"compress","href":"/examples/agents/context-compression"},{"title":"Prompt Caching","icon":"database","href":"/examples/agents/prompt-caching"}]},{"group":"Tree of Thoughts","pages":[{"title":"Number theory with a BFS beam","icon":"calculator","href":"/examples/tree-of-thoughts/number-theory-counting"},{"title":"Fermi estimate with sampling and votes","icon":"bolt","href":"/examples/tree-of-thoughts/fermi-estimation"},{"title":"Knights and knaves with DFS","icon":"chess-knight","href":"/examples/tree-of-thoughts/knights-and-knaves"}]},{"group":"Multi-Agent Examples","pages":[{"title":"Multi-Agent Architectures Overview","icon":"sitemap","href":"/examples/overviews/multi-agent-overview"},{"title":"Sequential Workflow Example","href":"/examples/sequential-workflow-example"},{"title":"Sequential Workflow Streaming","icon":"arrow-right-arrow-left","href":"/examples/sequential-workflow-streaming-example"},{"title":"Concurrent Workflow Example","href":"/examples/concurrent-workflow-example"},{"title":"Mixture of Agents (MoA) Example","href":"/examples/mixture-of-agents-example"},{"title":"Hierarchical Swarm Example","href":"/examples/hierarchical-swarm-example"},{"title":"Group Chat Example","href":"/examples/group-chat-example"},{"title":"Swarm Router Example","href":"/examples/swarm-router-example"},{"title":"Advisor Swarm Example","href":"/examples/multi-agent/advisor-swarm-example"},{"title":"Debate Swarm Quickstart","icon":"comments","href":"/examples/multi-agent/debate-quickstart"},{"title":"PhasedFanOutWorkflow Examples","icon":"sitemap","href":"/examples/multi-agent/phased-fan-out-workflow-example"},{"title":"AgentRearrange Guide","icon":"shuffle","href":"/examples/multi-agent/agent-rearrange-example"},{"title":"AgentRouter Guide","icon":"route","href":"/examples/multi-agent/agent-router-example"},{"title":"AutoSwarmBuilder Guide","icon":"wand-magic-sparkles","href":"/examples/multi-agent/auto-swarm-builder-example"},{"title":"BatchedGridWorkflow Guide","icon":"grid","href":"/examples/multi-agent/batched-grid-workflow-example"},{"title":"CouncilAsAJudge Guide","icon":"gavel","href":"/examples/multi-agent/council-as-a-judge-example"},{"title":"ExpertPanelDiscussion Guide","description":"Run a moderated panel where experts answer the moderator in turn, and the moderator sums up and asks the next question each round","icon":"microphone","href":"/examples/multi-agent/expert-panel-discussion-example"},{"title":"ForestSwarm Guide","icon":"tree","href":"/examples/multi-agent/forest-swarm-example"},{"title":"GraphWorkflow Guide","description":"Build a dependency graph of agents: fan out to parallel specialists, fan back in to one writer, check the graph, follow each node with callbacks, and refine over several loops","icon":"diagram-project","href":"/examples/multi-agent/graph-workflow-example"},{"title":"HeavySwarm Guide","icon":"weight-hanging","href":"/examples/multi-agent/heavy-swarm-example"},{"title":"LLMCouncil Guide","icon":"users","href":"/examples/multi-agent/llm-council-example"},{"title":"MajorityVoting Guide","icon":"check-double","href":"/examples/multi-agent/majority-voting-example"},{"title":"ModelRouter Guide","icon":"route","href":"/examples/multi-agent/model-router-example"},{"title":"MultiAgentRouter Guide","icon":"route","href":"/examples/multi-agent/multi-agent-router-example"},{"title":"OneOnOneDebate Guide","icon":"comments","href":"/examples/multi-agent/one-on-one-debate-example"},{"title":"PlannerGeneratorEvaluator Guide","icon":"arrows-spin","href":"/examples/multi-agent/planner-generator-evaluator-example"},{"title":"PlannerWorkerSwarm Guide","icon":"helmet-safety","href":"/examples/multi-agent/planner-worker-swarm-example"},{"title":"RoundRobinSwarm Guide","icon":"rotate","href":"/examples/multi-agent/round-robin-swarm-example"},{"title":"SelfMoASeq Guide","icon":"layer-group","href":"/examples/multi-agent/self-moa-seq-example"},{"title":"SelfOrganizingSwarm Guide","icon":"circle-nodes","href":"/examples/multi-agent/self-organizing-swarm-example"},{"title":"SocialAlgorithms Guide","icon":"people-arrows","href":"/examples/multi-agent/social-algorithms-example"},{"title":"SpreadSheetSwarm Guide","icon":"table","href":"/examples/multi-agent/spreadsheet-swarm-example"},{"title":"SubagentRegistry Guide","icon":"code-branch","href":"/examples/multi-agent/subagent-registry-example"},{"title":"Social Swarm Patterns","icon":"diagram-project","href":"/examples/social-swarm-patterns"}]},{"group":"Comms Channels","pages":[{"title":"Comms Channels","icon":"tower-broadcast","href":"/examples/channels/overview"},{"title":"FileChannel Quickstart","icon":"file-lines","href":"/examples/channels/file-channel"},{"title":"QueueChannel Quickstart","icon":"list-ol","href":"/examples/channels/queue-channel"},{"title":"SqliteChannel Quickstart","icon":"database","href":"/examples/channels/sqlite-channel"},{"title":"HttpChannel Quickstart","icon":"globe","href":"/examples/channels/http-channel"},{"title":"SmtpChannel Quickstart","icon":"envelope","href":"/examples/channels/smtp-channel"},{"title":"AgentMailChannel Quickstart","icon":"envelopes-bulk","href":"/examples/channels/agentmail-channel"},{"title":"MessageBoard Guide","icon":"comments","href":"/examples/channels/message-board"},{"title":"Channels with Every Structure","icon":"diagram-project","href":"/examples/channels/multi-agent-structures"}]},{"group":"Auto Agent Builder","pages":[{"title":"Auto Agent Builder Quickstart","icon":"wand-magic-sparkles","href":"/examples/auto-agent-builder/quickstart"},{"title":"Dynamic Support Triage","icon":"headset","href":"/examples/auto-agent-builder/triage"},{"title":"Reproducible Rosters","icon":"lock","href":"/examples/auto-agent-builder/reproducible"}]},{"group":"Scheduled Agents","pages":[{"title":"CronJob Quickstart","icon":"clock","href":"/examples/cron-job/quickstart"},{"title":"Multiple Agents on Different Schedules","icon":"layer-group","href":"/examples/cron-job/multiple-agents"},{"title":"Failure Handling and Monitoring","icon":"shield-halved","href":"/examples/cron-job/resilience"}]},{"group":"Applications","pages":[{"title":"Applications Overview","icon":"rectangle-list","href":"/examples/overviews/applications-overview"},{"title":"Apps Overview","icon":"grid","href":"/examples/overviews/apps-overview"},{"title":"Paper Implementations","icon":"scroll","href":"/examples/overviews/paper-implementations"},{"title":"Templates \u0026 Applications","icon":"layer-group","href":"/examples/overviews/templates"},{"title":"Marketing Team Swarm","icon":"bullhorn","href":"/examples/applications/marketing-team"},{"title":"Hiring Swarm","icon":"user-tie","href":"/examples/applications/hiring-swarm"},{"title":"Job Finding Swarm","icon":"briefcase","href":"/examples/applications/job-finding"},{"title":"M\u0026A Swarm","icon":"handshake","href":"/examples/applications/ma-swarm"},{"title":"Real Estate Swarm","icon":"house","href":"/examples/applications/realestate-swarm"},{"title":"Smart Database Swarm","icon":"database","href":"/examples/applications/smart-database"}]},{"group":"Research","pages":[{"title":"Can AI Agents Agree?","icon":"people-arrows","href":"/examples/research/can_agents_agree"},{"title":"Open Agent Bazaar","icon":"store","href":"/examples/research/open_agent_bazaar"}]},{"group":"Technical Analysis","pages":[{"title":"GroupChat Internals: A Technical Analysis","icon":"diagram-project","href":"/examples/groupchat_insight"}]},{"group":"Use Cases","pages":[{"title":"Research Team Swarm","icon":"microscope","href":"/examples/use-cases/research-team"},{"title":"Content Creation Pipeline","icon":"pen-nib","href":"/examples/use-cases/content-creation"},{"title":"Data Analysis Swarm","icon":"chart-line","href":"/examples/use-cases/data-analysis"}]},{"group":"Finance","pages":[{"title":"Gold ETF Research","icon":"coins","href":"/examples/applications/gold-etf-research"},{"title":"Financial Analysis System","icon":"chart-pie","href":"/examples/use-cases/financial-analysis"},{"title":"Agentic Trading with Gemini","icon":"robot","href":"/examples/finance/agentic-trading-gemini"},{"title":"Prediction Markets: Polymarket","icon":"scale-balanced","href":"/examples/finance/prediction-markets-polymarket"},{"title":"Prediction Markets: Kalshi","icon":"scale-balanced","href":"/examples/finance/prediction-markets-kalshi"}]},{"group":"Voice Agents","pages":[{"title":"Voice Agents Overview","icon":"microphone","href":"/examples/voice-agents/overview"},{"title":"Basic Speech Agent","icon":"volume-high","href":"/examples/voice-agents/agent-speech"},{"title":"Streaming Voice Agent","icon":"tower-broadcast","href":"/examples/voice-agents/agent-with-streaming-speech"},{"title":"Autonomous Voice Agent","icon":"robot","href":"/examples/voice-agents/autonomous-agent-with-speech"},{"title":"Voice Debate","icon":"comments","href":"/examples/voice-agents/debate-with-speech"},{"title":"Hierarchical Speech Swarm","icon":"sitemap","href":"/examples/voice-agents/hierarchical-speech-swarm"}]},{"group":"Integrations","pages":[{"title":"Tools \u0026 Integrations Overview","icon":"puzzle-piece","href":"/examples/overviews/tools-overview"},{"title":"Web Search with Exa","icon":"magnifying-glass","href":"/examples/integrations/exa-search"},{"title":"Browser Use","icon":"globe","href":"/examples/integrations/browser-use"},{"title":"MCP Server and Client","icon":"plug","href":"/examples/integrations/mcp-datastax"},{"title":"x402 Discovery Query","icon":"satellite-dish","href":"/examples/integrations/x402-discovery"},{"title":"x402 Payment Integration","icon":"credit-card","href":"/examples/integrations/x402-payment"},{"title":"Firecrawl Tool","icon":"fire","href":"/examples/integrations/firecrawl"},{"title":"Web Scraper Agents","icon":"spider","href":"/examples/integrations/web-scraper-agents"}]},{"group":"MCP Tool Integrations","pages":[{"title":"MCP examples overview","icon":"plug","href":"/examples/mcp/overview"},{"title":"DeepWiki: repo Q\u0026A","icon":"book","href":"/examples/mcp/deepwiki-repo-qa"},{"title":"GitMCP: one-repo docs bot","icon":"github","href":"/examples/mcp/gitmcp-repo-docs"},{"title":"Microsoft Learn: grounded answers","icon":"microsoft","href":"/examples/mcp/microsoft-learn-docs"},{"title":"Exa: live web search","icon":"magnifying-glass","href":"/examples/mcp/exa-web-search"},{"title":"Firecrawl: scrape pages to markdown","icon":"fire","href":"/examples/mcp/firecrawl-web-scraping"},{"title":"Hugging Face: find models","icon":"face-smile","href":"/examples/mcp/huggingface-model-search"},{"title":"Semgrep: security review","icon":"shield-halved","href":"/examples/mcp/semgrep-security-scan"},{"title":"Several servers at once","icon":"layer-group","href":"/examples/mcp/multi-server-agent"},{"title":"Serve an agent over MCP","icon":"rocket","href":"/examples/mcp/mcp-deployer-serve-agent"},{"title":"Serve a team of agents from one MCP server","icon":"users","href":"/examples/mcp/mcp-deployer-serve-team"},{"title":"MCP in a multi-agent workflow","icon":"diagram-project","href":"/examples/mcp/sequential-workflow"},{"title":"Dynamic tool loading","icon":"bolt","href":"/examples/mcp/dynamic-tool-loading"},{"title":"Authentication patterns","icon":"key","href":"/examples/mcp/authentication"},{"title":"Build your own MCP server","icon":"server","href":"/examples/mcp/local-server"}]},{"group":"Deployment","pages":[{"title":"Deployment Solutions Overview","icon":"cloud-arrow-up","href":"/examples/deployment-overview"},{"title":"A2A Quickstart","icon":"arrows-left-right","href":"/examples/a2a-quickstart"},{"title":"FastAPI Agent API","icon":"server","href":"/examples/fastapi-agent-api"},{"title":"Google Cloud Run","icon":"cloud","href":"/examples/cloud-run"},{"title":"Cloudflare Workers","icon":"cloudflare","href":"/examples/cloudflare-workers"},{"title":"Phala TEE Deployment","icon":"shield-halved","href":"/examples/phala-deploy"}]},{"group":"CLI","pages":[{"title":"CLI Guides Overview","icon":"terminal","href":"/examples/overviews/cli-overview"},{"title":"CLI Quickstart Tutorial","icon":"rocket","href":"/examples/cli/quickstart-tutorial"},{"title":"Chat Command","icon":"message","href":"/examples/cli/chat-command"},{"title":"Multi-Agent CLI Quickstart","icon":"rocket","href":"/examples/cli/multi-agent-quickstart"}]}]},{"tab":"Community","pages":[{"title":"Community","href":"/community/contributing"}]}]},"basePath":"","title":"ForestSwarm Guide - swarms","deploymentId":"dpl_Bzhd2vEuuXmvNaTmqBBYbeBj3epG","buildId":"dpl_Bzhd2vEuuXmvNaTmqBBYbeBj3epG","dynamics":[],"chunks":[]}