From 0fa467433027ce2656a8acdef7f572beec31ca2f Mon Sep 17 00:00:00 2001 From: ascender1729 Date: Sat, 26 Apr 2025 08:30:33 +0530 Subject: [PATCH] refactor: remove swarm_models dependency from examples and docs --- README.md | 62 +++++++++++++++++++++++++++--------------------------- example.py | 50 +++++++++++++++++++++++++++++++++---------- 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index da6819c3..dfd58bdc 100644 --- a/README.md +++ b/README.md @@ -1271,24 +1271,28 @@ The `run` method returns a dictionary containing the execution results of all no ```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") +# Initialize agents with model_name parameter +agent1 = Agent( + agent_name="Agent1", + model_name="openai/gpt-4o-mini", # Using provider prefix + temperature=0.5, + max_tokens=4000, + max_loops=1, + autosave=True, + dashboard=True, +) -llm = OpenAIChat( - temperature=0.5, openai_api_key=api_key, max_tokens=4000 +agent2 = Agent( + agent_name="Agent2", + model_name="openai/gpt-4o-mini", # Using provider prefix + 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") @@ -1297,9 +1301,8 @@ def sample_task(): 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")) @@ -1308,10 +1311,8 @@ wf_graph.set_end_points(["task1"]) print(wf_graph.visualize()) -# Run the workflow results = wf_graph.run() print("Execution results:", results) - ``` ## `MixtureOfAgents` @@ -2216,21 +2217,20 @@ Documentation is located here at: [docs.swarms.world](https://docs.swarms.world) ----- ## Folder Structure -The swarms package has been meticlously crafted for extreme use-ability and understanding, the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The 3 most important are `structs`, `models`, and `agents`. +The swarms package has been meticulously crafted for extreme usability and understanding,the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The package is split into various modules, with the most important being `structs`, `tools`, and `agents`. ```sh ├── __init__.py -├── agents -├── artifacts -├── memory -├── schemas -├── models -> swarm_models -├── prompts -├── structs -├── telemetry -├── tools -├── utils -└── workers +├── agents/ +├── artifacts/ +├── client/ +├── cli/ +├── prompts/ +├── schemas/ +├── structs/ +├── telemetry/ +├── tools/ +└── utils/ ``` ---- diff --git a/example.py b/example.py index 71005361..20a4495b 100644 --- a/example.py +++ b/example.py @@ -1,17 +1,45 @@ -from swarms.structs.agent import Agent +from swarms import Agent, Edge, GraphWorkflow, Node, NodeType from swarms.prompts.finance_agent_sys_prompt import ( FINANCIAL_AGENT_SYS_PROMPT, ) -# Initialize the agent -agent = Agent( - agent_name="Financial-Analysis-Agent", - agent_description="Personal finance advisor agent", - system_prompt=FINANCIAL_AGENT_SYS_PROMPT, - max_loops=2, - model_name="gpt-4o-mini", - dynamic_temperature_enabled=True, - interactive=False, +# Initialize agents with model_name parameter +agent1 = Agent( + agent_name="Agent1", + model_name="openai/gpt-4o-mini", # Using provider prefix + temperature=0.5, + max_tokens=4000, + max_loops=1, + autosave=True, + dashboard=True, ) -agent.run("Conduct an analysis of the best real undervalued ETFs") +agent2 = Agent( + agent_name="Agent2", + model_name="openai/gpt-4o-mini", # Using provider prefix + temperature=0.5, + max_tokens=4000, + max_loops=1, + autosave=True, + dashboard=True, +) + +def sample_task(): + print("Running sample task") + return "Task completed" + +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"]) + +print(wf_graph.visualize()) + +results = wf_graph.run() +print("Execution results:", results) \ No newline at end of file