diff --git a/README.md b/README.md index 179b5aac..2064c281 100644 --- a/README.md +++ b/README.md @@ -634,6 +634,77 @@ Swarm architectures leverage these communication patterns to ensure that agents +## Swarms API + +We recently launched our enterprise-grade Swarms API. This API allows you to create, manage, and execute swarms from your own application. + +#### Steps: + +1. Create a Swarms API key [HERE](https://swarms.world) +2. Upload your key to the `.env` file like so: `SWARMS_API_KEY=` +3. Use the following code to create and execute a swarm: +4. Read our docs for more information for deeper customization [HERE](https://docs.swarms.world/en/latest/swarms_cloud/swarms_api/) + + +```python +import json +from swarms.structs.swarms_api import ( + SwarmsAPIClient, + SwarmRequest, + AgentInput, +) +import os + +agents = [ + AgentInput( + agent_name="Medical Researcher", + description="Conducts medical research and analysis", + system_prompt="You are a medical researcher specializing in clinical studies.", + max_loops=1, + model_name="gpt-4o", + role="worker", + ), + AgentInput( + agent_name="Medical Diagnostician", + description="Provides medical diagnoses based on symptoms and test results", + system_prompt="You are a medical diagnostician with expertise in identifying diseases.", + max_loops=1, + model_name="gpt-4o", + role="worker", + ), + AgentInput( + agent_name="Pharmaceutical Expert", + description="Advises on pharmaceutical treatments and drug interactions", + system_prompt="You are a pharmaceutical expert knowledgeable about medications and their effects.", + max_loops=1, + model_name="gpt-4o", + role="worker", + ), +] + +swarm_request = SwarmRequest( + name="Medical Swarm", + description="A swarm for medical research and diagnostics", + agents=agents, + max_loops=1, + swarm_type="ConcurrentWorkflow", + output_type="str", + return_history=True, + task="What is the cause of the common cold?", +) + +client = SwarmsAPIClient( + api_key=os.getenv("SWARMS_API_KEY"), format_type="json" +) + +response = client.run(swarm_request) + +print(json.dumps(response, indent=4)) + + +``` + + ### `SequentialWorkflow` Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops. diff --git a/swarms_api_client.py b/swarms_api_examples/swarms_api_client.py similarity index 100% rename from swarms_api_client.py rename to swarms_api_examples/swarms_api_client.py diff --git a/swarms_api_example.py b/swarms_api_examples/swarms_api_example.py similarity index 89% rename from swarms_api_example.py rename to swarms_api_examples/swarms_api_example.py index c23d9b88..2df3112b 100644 --- a/swarms_api_example.py +++ b/swarms_api_examples/swarms_api_example.py @@ -43,7 +43,7 @@ def run_single_swarm(): }, ], "max_loops": 1, - "swarm_type": "HiearchicalSwarm", + "swarm_type": "SequentialWorkflow", "task": "What are the best etfs and index funds for ai and tech?", "output_type": "dict", # "return_history": True, @@ -71,11 +71,11 @@ def get_logs(): if __name__ == "__main__": - # result = run_single_swarm() - # print("Swarm Result:") - # print(result) - - logs = get_logs() - logs = json.dumps(logs, indent=4) - print("Logs:") - print(logs) + result = run_single_swarm() + print("Swarm Result:") + print(result) + + # logs = get_logs() + # logs = json.dumps(logs, indent=4) + # print("Logs:") + # print(logs)