pull/595/head
Your Name 3 months ago
parent 2b01f83cb0
commit 1f5476d3a1

@ -72,6 +72,23 @@ Refer to our documentation for production grade implementation details.
$ pip3 install -U swarms
```
## Onboarding
Now that you have downloaded swarms with `pip3 install -U swarms`, we get access to the `CLI`. Get Onboarded with CLI Now with:
```bash
swarms onboarding
```
You can also run this command for help:
```bash
swarms help
```
For more documentation on the CLI [CLICK HERE](https://docs.swarms.world/en/latest/swarms/cli/main/)
---
# Usage Examples 🤖

@ -1,7 +1,6 @@
agents:
- agent_name: "Financial-Analysis-Agent"
model:
openai_api_key: "your_openai_api_key"
model_name: "gpt-4o-mini"
temperature: 0.1
max_tokens: 2000
@ -17,10 +16,11 @@ agents:
context_length: 200000
return_step_meta: false
output_type: "str" # Can be "json" or any other format
task: "What are the benefits of working with BlackRock"
- agent_name: "Stock-Analysis-Agent"
model:
openai_api_key: "your_openai_api_key"
model_name: "gpt-4o-mini"
temperature: 0.2
max_tokens: 1500
@ -36,3 +36,4 @@ agents:
context_length: 150000
return_step_meta: true
output_type: "str"
task: "What is a roth IRA"

@ -1,24 +1,19 @@
from loguru import logger
from dotenv import load_dotenv
from swarms import create_agents_from_yaml
from swarms.agents.create_agents_from_yaml import create_agents_from_yaml
# Load environment variables
load_dotenv()
# Path to your YAML file
yaml_file = "agents_config.yaml"
yaml_file = "agents.yaml"
try:
# Create agents and run tasks (using 'both' to return agents and task results)
agents, task_results = create_agents_from_yaml(
yaml_file, return_type="both"
task_results = create_agents_from_yaml(
yaml_file, return_type="tasks"
)
# Print the results of the tasks
for result in task_results:
print(
f"Agent: {result['agent_name']} | Task: {result['task']} | Output: {result.get('output', 'Error encountered')}"
)
logger.info(f"Results from agents: {task_results}")
except Exception as e:
logger.error(f"An error occurred: {e}")

@ -147,8 +147,8 @@ nav:
# - Build Custom Agents: "swarms/structs/diy_your_own_agent.md"
- Agent Architecture: "swarms/framework/agents_explained.md"
- Complete Agent API: "swarms/structs/agent.md"
- Integrating External Agents from Griptape, Langchain, etc: "swarms/agents/external_party_agents.md"
- Create and Run Agents from YAML: "swarms/agents/create_agents_yaml.md"
- Integrating External Agents from Griptape, Langchain, etc: "swarms/agents/external_party_agents.md"
- Tools:
- Overview: "swarms/tools/main.md"
- What are tools?: "swarms/tools/build_tool.md"

@ -1,4 +1,4 @@
# `create_agents_from_yaml`
# Building Agents from a YAML File
The `create_agents_from_yaml` function enables the dynamic creation and execution of agents based on configurations defined in a YAML file. This function is designed to support enterprise use-cases, offering flexibility, reliability, and scalability for various agent-based workflows.
@ -63,7 +63,7 @@ agents:
model_name: "gpt-4o-mini"
temperature: 0.1
max_tokens: 2000
system_prompt: "financial_agent_sys_prompt"
system_prompt: "Your full system prompt here"
max_loops: 1
autosave: true
dashboard: false
@ -82,7 +82,7 @@ agents:
model_name: "gpt-4o-mini"
temperature: 0.2
max_tokens: 1500
system_prompt: "stock_agent_sys_prompt"
system_prompt: "Your full system prompt here"
max_loops: 2
autosave: true
dashboard: false

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "5.7.1"
version = "5.7.7"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]

@ -58,16 +58,7 @@ def create_agents_from_yaml(
logger.info(f"Creating agent: {agent_config['agent_name']}")
# Get the OpenAI API key from environment or YAML config
api_key = os.getenv("OPENAI_API_KEY") or agent_config[
"model"
].get("openai_api_key")
if not api_key:
logger.error(
f"API key is missing for agent: {agent_config['agent_name']}"
)
raise ValueError(
f"API key is missing for agent: {agent_config['agent_name']}"
)
api_key = os.getenv("OPENAI_API_KEY") or agent_config["model"]["openai_api_key"]
# Create an instance of OpenAIChat model
model = OpenAIChat(
@ -87,31 +78,11 @@ def create_agents_from_yaml(
raise ValueError(
f"System prompt is missing for agent: {agent_config['agent_name']}"
)
# Dynamically choose the system prompt based on the agent config
try:
system_prompt = globals().get(
agent_config["system_prompt"]
)
if not system_prompt:
logger.error(
f"System prompt {agent_config['system_prompt']} not found."
)
raise ValueError(
f"System prompt {agent_config['system_prompt']} not found."
)
except KeyError:
logger.error(
f"System prompt {agent_config['system_prompt']} is not valid."
)
raise ValueError(
f"System prompt {agent_config['system_prompt']} is not valid."
)
# Initialize the agent using the configuration
agent = Agent(
agent_name=agent_config["agent_name"],
system_prompt=system_prompt,
system_prompt=agent_config["system_prompt"],
llm=model,
max_loops=agent_config.get("max_loops", 1),
autosave=agent_config.get("autosave", True),
@ -178,19 +149,3 @@ def create_agents_from_yaml(
logger.error(f"Invalid return_type: {return_type}")
raise ValueError(f"Invalid return_type: {return_type}")
# # Usage example
# yaml_file = 'agents_config.yaml'
# try:
# # Auto-create agents from the YAML file and return both agents and task results
# agents, task_results = create_agents_from_yaml(yaml_file, return_type="tasks")
# # Example: Print task results
# for result in task_results:
# print(f"Agent: {result['agent_name']} | Task: {result['task']} | Output: {result.get('output', 'Error encountered')}")
# except FileNotFoundError as e:
# logger.error(f"Error: {e}")
# except ValueError as e:
# logger.error(f"Error: {e}")

@ -41,7 +41,7 @@ def show_help():
[bold white]get-api-key[/bold white] : Retrieves your API key from the platform
[bold white]check-login[/bold white] : Checks if you're logged in and starts the cache
[bold white]read-docs[/bold white] : Redirects you to swarms cloud documentation!
[bold white]run-agents[/bold white] : Run your Agents from your agents.yaml
[bold white]run-agents[/bold white] : Run your Agents from your specified yaml file. Specify the yaml file with path the `--yaml-file` arg. Example: `--yaml-file agents.yaml`
For more details, visit: https://docs.swarms.world
"""
@ -107,12 +107,21 @@ def main():
# Adding arguments for different commands
parser.add_argument(
"command",
choices=["onboarding", "help", "get-api-key", "check-login"],
choices=["onboarding", "help", "get-api-key", "check-login", "run-agents"],
help="Command to run",
)
parser.add_argument(
"--yaml-file",
type=str,
default="agents.yaml",
help="Specify the YAML file for running agents",
)
args = parser.parse_args()
# Debug print to verify the command
print(f"Command received: {args.command}")
show_ascii_art()
# Determine which command to run
@ -124,17 +133,14 @@ def main():
get_api_key()
elif args.command == "check-login":
check_login()
elif args.command == "read-docs":
redirect_to_docs()
elif args.command == "run-agents":
create_agents_from_yaml(
yaml_file="agents.yaml", return_type="tasks"
yaml_file=args.yaml_file, return_type="tasks"
)
else:
console.print(
"[bold red]Unknown command! Type 'help' for usage.[/bold red]"
)
if __name__ == "__main__":
main()

@ -81,14 +81,14 @@ class OnboardingProcess:
combined_data = {**self.user_data, **self.system_data}
log_agent_data(combined_data)
# threading.Thread(target=log_agent_data(combined_data)).start()
with open(self.auto_save_path, "w") as f:
json.dump(combined_data, f, indent=4)
# logger.info(
# "User and system data successfully saved to {}",
# self.auto_save_path,
# )
with open(self.cache_save_path, "w") as f:
json.dump(combined_data, f, indent=4)
# with open(self.auto_save_path, "w") as f:
# json.dump(combined_data, f, indent=4)
# # logger.info(
# # "User and system data successfully saved to {}",
# # self.auto_save_path,
# # )
# with open(self.cache_save_path, "w") as f:
# json.dump(combined_data, f, indent=4)
# logger.info(
# "User and system data successfully cached in {}",
# self.cache_save_path,
@ -138,6 +138,8 @@ class OnboardingProcess:
)
self.user_data[key] = response.strip()
self.save_data()
return response
except ValueError as e:
logger.warning(e)
self.ask_input(prompt, key)
@ -150,7 +152,7 @@ class OnboardingProcess:
def collect_user_info(self) -> None:
"""
Initiates the onboarding process by collecting the user's full name, first name, email,
Swarms API key, and system data.
Swarms API key, and system data. Additionally, it reminds the user to set their WORKSPACE_DIR environment variable.
"""
logger.info("Initiating swarms cloud onboarding process...")
self.ask_input(
@ -168,6 +170,13 @@ class OnboardingProcess:
"Enter your Swarms API key (or type 'quit' to exit): Get this in your swarms dashboard: https://swarms.world/platform/api-keys ",
"swarms_api_key",
)
workspace = self.ask_input(
"Enter your WORKSPACE_DIR: This is where logs, errors, and agent configurations will be stored (or type 'quit' to exit). Remember to set this as an environment variable: https://docs.swarms.world/en/latest/swarms/install/quickstart/ || ",
"workspace_dir",
)
os.environ["WORKSPACE_DIR"] = workspace
logger.info("Important: Please ensure you have set your WORKSPACE_DIR environment variable as per the instructions provided.")
logger.info("Additionally, remember to add your API keys for your respective models in your .env file.")
logger.success("Onboarding process completed successfully!")
def run(self) -> None:

Loading…
Cancel
Save