diff --git a/README.md b/README.md index 2a5362fe..2b68e274 100644 --- a/README.md +++ b/README.md @@ -1025,6 +1025,58 @@ swarm.run( ``` + +## `ForestSwarm` +The architecture allows for efficient task assignment by selecting the most relevant agent from a set of trees. Tasks are processed asynchronously, with agents selected based on task relevance, calculated by the similarity of system prompts and task keywords. [Learn More with the documentation](https://docs.swarms.world/en/latest/swarms/structs/forest_swarm/) + + +```python +from swarms.structs.tree_swarm import TreeAgent, Tree, ForestSwarm +# Example Usage: + +# Create agents with varying system prompts and dynamically generated distances/keywords +agents_tree1 = [ + TreeAgent( + system_prompt="Stock Analysis Agent", + agent_name="Stock Analysis Agent", + ), + TreeAgent( + system_prompt="Financial Planning Agent", + agent_name="Financial Planning Agent", + ), + TreeAgent( + agent_name="Retirement Strategy Agent", + system_prompt="Retirement Strategy Agent", + ), +] + +agents_tree2 = [ + TreeAgent( + system_prompt="Tax Filing Agent", + agent_name="Tax Filing Agent", + ), + TreeAgent( + system_prompt="Investment Strategy Agent", + agent_name="Investment Strategy Agent", + ), + TreeAgent( + system_prompt="ROTH IRA Agent", agent_name="ROTH IRA Agent" + ), +] + +# Create trees +tree1 = Tree(tree_name="Financial Tree", agents=agents_tree1) +tree2 = Tree(tree_name="Investment Tree", agents=agents_tree2) + +# Create the ForestSwarm +multi_agent_structure = ForestSwarm(trees=[tree1, tree2]) + +# Run a task +task = "Our company is incorporated in delaware, how do we do our taxes for free?" +output = multi_agent_structure.run(task) +print(output) +``` + ---------- ## Onboarding Session