AGENTOPS FIX

pull/546/head
Nicolas Nahas 9 months ago
parent 0e7dc3557a
commit b2f8721f85

@ -109,7 +109,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
@ -172,7 +171,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -88,7 +88,6 @@ Swarm Agent is a powerful autonomous agent framework designed to connect Languag
| `device` | A string representing the device on which the agent should run. |
| `custom_planning_prompt` | A string representing a custom prompt for planning. |
| `memory_chunk_size` | An integer representing the maximum size of memory chunks for long-term memory retrieval. |
| `agent_ops_on` | A boolean indicating whether agent operations should be enabled. |
### `Agent` Methods

@ -35,7 +35,6 @@ agent = Agent(
context_length=200000,
# tool_schema=
# tools
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -34,7 +34,6 @@ fiancial_analyst = Agent(
# context_length=1000,
# tool_schema = dict
context_length=160000,
# agent_ops_on=True,
interactive=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
@ -68,7 +67,6 @@ fiancial_director = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -1,26 +1,91 @@
from swarms import Agent, OpenAIChat
"""
* WORKING
What this script does:
Simple agent run to test AgentOps (https://www.agentops.ai/)
Requirements:
1. Create an account on https://www.agentops.ai/ and run pip install agentops
2. Add the folowing API key(s) in your .env file:
- OPENAI_API_KEY
- AGENTOPS_API_KEY
3. Go to your agentops dashboard to observe your activity
"""
################ Adding project root to PYTHONPATH ################################
# If you are running playground examples in the project files directly, use this:
import sys
import os
sys.path.insert(0, os.getcwd())
################ Adding project root to PYTHONPATH ################################
from swarms import Agent, OpenAIChat, AgentRearrange
import agentops
# Initialize agentops
agentops.start_session()
# Initialize the agent
agent = Agent(
agent_name="Accounting Agent",
system_prompt="Generate a financial report for the company's quarterly earnings.",
agent_name="Treasurer",
system_prompt="Give your opinion on the cash management.",
agent_description=(
"Generate a financial report for the company's quarterly earnings."
"responsible for managing an organization's financial assets and liquidity. They oversee cash management, "
"investment strategies, and financial risk. Key duties include monitoring cash flow, managing bank relationships, "
"ensuring sufficient funds for operations, and optimizing returns on short-term investments. Treasurers also often "
"handle debt management and may be involved in capital raising activities."
),
llm=OpenAIChat(),
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
interactive=False,
state_save_file_type="json",
saved_state_path="accounting_agent.json",
agent_ops_on=True,
)
# Run the Agent on a task
agent.run(
"Generate a financial report for the company's quarterly earnings!"
agent2 = Agent(
agent_name="CFO",
system_prompt="Give your opinion on the financial performance of the company.",
agent_description=(
"the top financial executive in an organization, overseeing all financial operations and strategy. Their role is broader than a treasurer's and includes:\n"
"Financial planning and analysis\n"
"Accounting and financial reporting\n"
"Budgeting and forecasting\n"
"Strategic financial decision-making\n"
"Compliance and risk management\n"
"Investor relations (in public companies)\n"
"Overseeing the finance and accounting departments"
),
llm=OpenAIChat(),
max_loops=1,
streaming_on=True,
verbose=True,
)
swarm = AgentRearrange(
agents=[agent, agent2],
flow="Treasurer -> CFO",
)
results = swarm.run("Date,Revenue,Expenses,Profit,Cash_Flow,Inventory,Customer_Acquisition_Cost,Customer_Retention_Rate,Marketing_Spend,R&D_Spend,Debt,Assets\n"
"2023-01-01,1000000,800000,200000,150000,500000,100,0.85,50000,100000,2000000,5000000\n"
"2023-02-01,1050000,820000,230000,180000,520000,95,0.87,55000,110000,1950000,5100000\n"
"2023-03-01,1100000,850000,250000,200000,530000,90,0.88,60000,120000,1900000,5200000\n"
"2023-04-01,1200000,900000,300000,250000,550000,85,0.90,70000,130000,1850000,5400000\n"
"2023-05-01,1300000,950000,350000,300000,580000,80,0.92,80000,140000,1800000,5600000\n"
"2023-06-01,1400000,1000000,400000,350000,600000,75,0.93,90000,150000,1750000,5800000\n"
"2023-07-01,1450000,1050000,400000,320000,620000,78,0.91,95000,160000,1700000,5900000\n"
"2023-08-01,1500000,1100000,400000,300000,650000,80,0.90,100000,170000,1650000,6000000\n"
"2023-09-01,1550000,1150000,400000,280000,680000,82,0.89,105000,180000,1600000,6100000\n"
"2023-10-01,1600000,1200000,400000,260000,700000,85,0.88,110000,190000,1550000,6200000\n"
"2023-11-01,1650000,1250000,400000,240000,720000,88,0.87,115000,200000,1500000,6300000\n"
"2023-12-01,1700000,1300000,400000,220000,750000,90,0.86,120000,210000,1450000,6400000\n"
"2024-01-01,1500000,1200000,300000,180000,780000,95,0.84,100000,180000,1500000,6300000\n"
"2024-02-01,1550000,1220000,330000,200000,760000,92,0.85,105000,185000,1480000,6350000\n"
"2024-03-01,1600000,1240000,360000,220000,740000,89,0.86,110000,190000,1460000,6400000\n"
"2024-04-01,1650000,1260000,390000,240000,720000,86,0.87,115000,195000,1440000,6450000\n"
"2024-05-01,1700000,1280000,420000,260000,700000,83,0.88,120000,200000,1420000,6500000\n"
"2024-06-01,1750000,1300000,450000,280000,680000,80,0.89,125000,205000,1400000,6550000"
)

@ -45,7 +45,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -114,7 +114,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -40,7 +40,6 @@ agent = Agent(
# tool_schema = dict
context_length=200000,
interactive=True,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -34,7 +34,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -39,7 +39,6 @@ agent = Agent(
context_length=200000,
# tool_schema=
# tools
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -31,8 +31,7 @@ receipt_analyzer_agent = Agent(
# # docs=
# # docs_folder="docs",
retry_attempts=3,
# tool_schema = dict
# agent_ops_on=True,
# tool_schema = dict,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
# multi_modal=True
)
@ -63,8 +62,7 @@ analyst_agent = Agent(
# # docs=
# # docs_folder="docs",
retry_attempts=3,
# tool_schema = dict
# agent_ops_on=True,
# tool_schema = dict,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
# multi_modal=True,
)

@ -32,7 +32,6 @@ hallucinator = Agent(
# context_length=1000,
# tool_schema = dict
context_length=1000,
# agent_ops_on=True,
# tree_of_thoughts=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
@ -213,7 +212,6 @@ agent_evaluator = Agent(
user_name="Human",
# tool_schema = dict
context_length=1000,
# agent_ops_on=True,
# tree_of_thoughts=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -158,7 +158,6 @@ agent = Agent(
# context_length=1000,
# tool_schema = dict
context_length=1000,
# agent_ops_on=True,
interactive=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)

@ -302,7 +302,6 @@ director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the accountants",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -314,7 +313,6 @@ accountant1 = Agent(
agent_name="Accountant1",
system_prompt="Prepares financial statements",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -326,7 +324,6 @@ accountant2 = Agent(
agent_name="Accountant2",
system_prompt="Audits financial records",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -338,7 +335,6 @@ balance_sheet_analyzer = Agent(
agent_name="BalanceSheetAnalyzer",
system_prompt="Analyzes balance sheets",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -349,7 +345,6 @@ income_statement_analyzer = Agent(
agent_name="IncomeStatementAnalyzer",
system_prompt="Analyzes income statements",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -360,7 +355,6 @@ cash_flow_analyzer = Agent(
agent_name="CashFlowAnalyzer",
system_prompt="Analyzes cash flow statements",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -371,7 +365,6 @@ financial_ratio_calculator = Agent(
agent_name="FinancialRatioCalculator",
system_prompt="Calculates financial ratios",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -382,7 +375,6 @@ tax_preparer = Agent(
agent_name="TaxPreparer",
system_prompt="Prepares tax returns",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -393,7 +385,6 @@ payroll_processor = Agent(
agent_name="PayrollProcessor",
system_prompt="Processes payroll",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -404,7 +395,6 @@ inventory_manager = Agent(
agent_name="InventoryManager",
system_prompt="Manages inventory",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",
@ -415,7 +405,6 @@ budget_planner = Agent(
agent_name="BudgetPlanner",
system_prompt="Plans budgets",
llm=llm,
agent_ops_on=True,
max_loops=1,
dashboard=False,
state_save_file_type="json",

@ -653,7 +653,6 @@ revenue_maximalist_agent = Agent(
dashboard=False,
state_save_file_type="json",
saved_state_path="revenue_maximalist_analyst.json",
# agent_ops_on=True,
# # long_term_memory=memory,
# context_length=10000,
)
@ -666,7 +665,6 @@ cost_control_agent = Agent(
dashboard=False,
state_save_file_type="json",
saved_state_path="operational_efficiency.json",
# agent_ops_on=True,
# # long_term_memory=memory,
)
@ -678,7 +676,6 @@ investment_analyst_agent = Agent(
dashboard=False,
state_save_file_type="json",
saved_state_path="strategic_investment_analyst.json",
# agent_ops_on=True,
# # long_term_memory=memory,
)
@ -690,7 +687,6 @@ sales_marketing_agent = Agent(
dashboard=False,
state_save_file_type="json",
saved_state_path="sales_marketing_agent.json",
# agent_ops_on=True,
# # long_term_memory=memory,
# context_length=8192,
)

@ -84,7 +84,6 @@ class AgentSchema(BaseModel):
device: Optional[str] = Field(default=None)
custom_planning_prompt: Optional[str] = Field(default=None)
memory_chunk_size: Optional[int] = Field(default=2000, ge=0)
agent_ops_on: Optional[bool] = Field(default=False)
log_directory: Optional[str] = Field(default=None)
project_path: Optional[str] = Field(default=None)
tool_system_prompt: Optional[str] = Field(default="tool_sop_prompt()")

@ -257,7 +257,6 @@ class Agent(BaseStructure):
device: str = None,
custom_planning_prompt: str = None,
memory_chunk_size: int = 2000,
agent_ops_on: bool = False,
log_directory: str = None,
project_path: str = None,
tool_system_prompt: str = tool_sop_prompt(),
@ -348,7 +347,6 @@ class Agent(BaseStructure):
self.rules = rules
self.custom_tools_prompt = custom_tools_prompt
self.memory_chunk_size = memory_chunk_size
self.agent_ops_on = agent_ops_on
self.log_directory = log_directory
self.project_path = project_path
self.tool_system_prompt = tool_system_prompt
@ -473,10 +471,6 @@ class Agent(BaseStructure):
if exists(self.sop):
self.short_memory.add(role=self.user_name, content=self.sop)
# If agent_ops is on => activate agentops
if agent_ops_on is True:
self.activate_agentops()
def set_system_prompt(self, system_prompt: str):
"""Set the system prompt"""
self.system_prompt = system_prompt
@ -883,8 +877,6 @@ class Agent(BaseStructure):
# print(f"Response after output model: {response}")
# print(response)
if self.agent_ops_on is True:
self.check_end_session_agentops()
# final_response = " ".join(all_responses)
all_responses = [response for response in all_responses if response is not None]
@ -1601,20 +1593,6 @@ class Agent(BaseStructure):
)
)
def check_end_session_agentops(self):
if self.agent_ops_on is True:
try:
from swarms.utils.agent_ops_check import (
end_session_agentops,
)
# Try ending the session
return end_session_agentops()
except ImportError:
logger.error(
"Could not import agentops, try installing agentops: $ pip3 install agentops"
)
def convert_tool_into_openai_schema(self):
logger.info("Converting tools into OpenAI function calling schema")
@ -1955,25 +1933,6 @@ class Agent(BaseStructure):
"Error parsing and executing function call"
) from error
def activate_agentops(self):
if self.agent_ops_on is True:
try:
from swarms.utils.agent_ops_check import (
try_import_agentops,
)
# Try importing agent ops
logger.info(
"Agent Ops Initializing, ensure that you have the agentops API key and the pip package installed."
)
try_import_agentops()
logger.info("Agentops successfully activated!")
except ImportError:
logger.error(
"Could not import agentops, try installing agentops: $ pip3 install agentops"
)
def handle_multiple_base_models(self) -> None:
try:
# If a list of tool schemas is provided

@ -89,7 +89,6 @@ class BaseSwarm(ABC):
speaker_selection_func: Optional[Callable] = None,
rules: Optional[str] = None,
collective_memory_system: Optional[BaseVectorDatabase] = False,
agent_ops_on: bool = False,
*args,
**kwargs,
):
@ -111,7 +110,6 @@ class BaseSwarm(ABC):
self.speaker_selection_func = speaker_selection_func
self.rules = rules
self.collective_memory_system = collective_memory_system
self.agent_ops_on = agent_ops_on
logger.info("Reliability checks activated.")
# Ensure that agents is exists
@ -161,11 +159,6 @@ class BaseSwarm(ABC):
self.stopping_condition_args = stopping_condition_args
self.stopping_condition = stopping_condition
# If agentops is enabled, try to import agentops
if agentops_on is True:
for agent in self.agents:
agent.agent_ops_on = True
# Handle speaker selection function
if speaker_selection_func is not None:
if not callable(speaker_selection_func):
@ -174,11 +167,6 @@ class BaseSwarm(ABC):
)
self.speaker_selection_func = speaker_selection_func
# Add the check for all the agents to see if agent ops is on!
if agent_ops_on is True:
for agent in self.agents:
agent.agent_ops_on = True
# Agents dictionary with agent name as key and agent object as value
self.agents_dict = {
agent.agent_name: agent for agent in self.agents
@ -694,9 +682,6 @@ class BaseSwarm(ABC):
def __contains__(self, value):
return value in self.agents
def __eq__(self, other):
return self.__dict__ == other.__dict__
def agent_error_handling_check(self):
try:
if self.agents is None:

@ -1,28 +0,0 @@
from swarms.utils.loguru_logger import logger
import os
from dotenv import load_dotenv
def try_import_agentops(*args, **kwargs):
try:
load_dotenv()
logger.info("Trying to import agentops")
import agentops
agentops.init(os.getenv("AGENTOPS_API_KEY"), *args, **kwargs)
return "agentops imported successfully."
except ImportError:
logger.error("Could not import agentops")
def end_session_agentops():
try:
logger.info("Trying to end session")
import agentops
agentops.end_session("Success")
return "Session ended successfully."
except ImportError:
logger.error("Could not import agentops")
return "Could not end session."
Loading…
Cancel
Save