Merge pull request #905 from ascender1729/GraphWorkflow

[docs][example][workflow]Create example script for graph workflow
pull/906/merge
Kye Gomez 2 weeks ago committed by GitHub
commit d3a28edd77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -60,6 +60,7 @@ Additionally, we have more comprehensive examples available in [The Swarms Cookb
| Concurrent | [Concurrent Swarm](https://github.com/The-Swarm-Corporation/swarms-examples/blob/main/examples/structs/swarms/concurrent_swarm/concurrent_swarm_example.py) | Parallel execution of tasks across multiple agents for improved performance |
| Star | [Star Swarm](https://github.com/The-Swarm-Corporation/swarms-examples/blob/main/examples/structs/swarms/different_architectures/star_swarm.py) | Centralized architecture with a hub agent coordinating peripheral agents |
| Circular | [Circular Swarm](https://github.com/The-Swarm-Corporation/swarms-examples/blob/main/examples/structs/swarms/different_architectures/circular_swarm.py) | Ring topology for cyclic information flow between agents |
| Graph Workflow | [Graph Workflow Basic](https://github.com/kyegomez/swarms/blob/main/examples/structs/graph_workflow_basic.py) | Minimal graph workflow with two agents and one task |
### Experimental Architectures
| Category | Example | Description |

@ -0,0 +1,50 @@
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
def sample_task():
"""Simple callable task."""
print("Running sample task")
return "Task completed"
if __name__ == "__main__":
# Initialize two basic agents
agent1 = Agent(
agent_name="Agent1",
model_name="openai/gpt-4o-mini",
temperature=0.5,
max_tokens=4000,
max_loops=1,
autosave=True,
dashboard=True,
)
agent2 = Agent(
agent_name="Agent2",
model_name="openai/gpt-4o-mini",
temperature=0.5,
max_tokens=4000,
max_loops=1,
autosave=True,
dashboard=True,
)
# Build the workflow graph
wf_graph = GraphWorkflow()
wf_graph.add_node(Node(id="agent1", type=NodeType.AGENT, agent=agent1))
wf_graph.add_node(Node(id="agent2", type=NodeType.AGENT, agent=agent2))
wf_graph.add_node(Node(id="task1", type=NodeType.TASK, callable=sample_task))
wf_graph.add_edge(Edge(source="agent1", target="task1"))
wf_graph.add_edge(Edge(source="agent2", target="task1"))
wf_graph.set_entry_points(["agent1", "agent2"])
wf_graph.set_end_points(["task1"])
# Optional visualization in Mermaid format
print(wf_graph.visualize())
# Execute the graph
results = wf_graph.run()
print("Execution results:", results)
Loading…
Cancel
Save