diff --git a/docs/swarms/structs/graph_workflow.md b/docs/swarms/structs/graph_workflow.md index cfa70f81..d1154056 100644 --- a/docs/swarms/structs/graph_workflow.md +++ b/docs/swarms/structs/graph_workflow.md @@ -134,45 +134,44 @@ print("Execution results:", results) Below is a comprehensive example demonstrating the creation and execution of a workflow graph: ```python - -import os - -from dotenv import load_dotenv - - from swarms import Agent, Edge, GraphWorkflow, Node, NodeType -from swarm_models import OpenAIChat - -load_dotenv() - -api_key = os.environ.get("OPENAI_API_KEY") - -llm = OpenAIChat( - temperature=0.5, openai_api_key=api_key, max_tokens=4000 +# Initialize two agents with GPT-4o-mini model and desired parameters +agent1 = Agent( + model_name="gpt-4o-mini", + temperature=0.5, + max_tokens=4000, + max_loops=1, + autosave=True, + dashboard=True, +) +agent2 = Agent( + model_name="gpt-4o-mini", + temperature=0.5, + max_tokens=4000, + max_loops=1, + autosave=True, + dashboard=True, ) -agent1 = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True) -agent2 = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True) def sample_task(): print("Running sample task") return "Task completed" +# Build 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_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"]) +# Visualize and run print(wf_graph.visualize()) - -# Run the workflow results = wf_graph.run() print("Execution results:", results)