parent
aebec35d54
commit
a403ed3c3b
@ -0,0 +1,38 @@
|
||||
# Example
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from swarms import Agent, OpenAIChat
|
||||
from swarms.structs.company import Company
|
||||
|
||||
load_dotenv()
|
||||
|
||||
llm = OpenAIChat(
|
||||
openai_api_key=os.getenv("OPENAI_API_KEY"), max_tokens=4000
|
||||
)
|
||||
|
||||
ceo = Agent(llm=llm, ai_name="CEO")
|
||||
dev = Agent(llm=llm, ai_name="Developer")
|
||||
va = Agent(llm=llm, ai_name="VA")
|
||||
|
||||
# Create a company
|
||||
company = Company(
|
||||
org_chart = [[dev, va]],
|
||||
shared_instructions="Do your best",
|
||||
ceo=ceo,
|
||||
)
|
||||
|
||||
# Add agents to the company
|
||||
hr = Agent(llm=llm, name="HR")
|
||||
company.add(hr)
|
||||
|
||||
# Get an agent from the company
|
||||
hr = company.get("CEO")
|
||||
|
||||
# Remove an agent from the company
|
||||
company.remove(hr)
|
||||
|
||||
# Run the company
|
||||
company.run()
|
@ -0,0 +1,70 @@
|
||||
import pytest
|
||||
from swarms.structs.agent import Agent
|
||||
from swarms.structs.company import Company
|
||||
from swarms import OpenAIChat
|
||||
|
||||
# Mock OpenAIChat instance
|
||||
llm = OpenAIChat(openai_api_key="test_key", max_tokens=4000)
|
||||
|
||||
# Mock Agents
|
||||
ceo = Agent(llm=llm, name="CEO")
|
||||
dev = Agent(llm=llm, name="Developer")
|
||||
va = Agent(llm=llm, name="VA")
|
||||
hr = Agent(llm=llm, name="HR")
|
||||
shared_instructions = "Listen to your boss"
|
||||
|
||||
|
||||
def test_add_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
company.add(hr)
|
||||
assert hr in company.agents
|
||||
|
||||
|
||||
def test_get_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
company.add(hr)
|
||||
assert company.get("HR") == hr
|
||||
|
||||
|
||||
def test_remove_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
company.add(hr)
|
||||
company.remove(hr)
|
||||
assert hr not in company.agents
|
||||
|
||||
|
||||
def test_add_existing_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
company.add(hr)
|
||||
with pytest.raises(ValueError):
|
||||
company.add(hr)
|
||||
|
||||
|
||||
def test_get_nonexistent_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
company.get("Nonexistent")
|
||||
|
||||
|
||||
def test_remove_nonexistent_agent():
|
||||
company = Company(
|
||||
org_chart=[[ceo, [dev, va]]],
|
||||
shared_instructions=shared_instructions,
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
company.remove(hr)
|
Loading…
Reference in new issue