[BUG] CrewAI is failing when I use agentops
Description
When I am using agentops, CrewAI Crew.kickoff returns the LLM response to be None, i.e. fails silently.
Steps to Reproduce
import os
from dotenv import load_dotenv
assert load_dotenv()
import agentops
agentops.init(os.environ["AGENTOPS_API_KEY"])
...
crew.kickoff()
Output:
> Entering new CrewAgentExecutor chain...
> Finished chain.
Error parsing JSON: Expecting value: line 1 column 1 (char 0). Attempting to handle partial JSON.
Failed to convert text into JSON, error: 'NoneType' object is not callable. Using raw output instead.
[2024-09-06 17:44:26][DEBUG]: == [Agent Name] Task output: Agent stopped due to iteration limit or time limit.
Expected behavior
If there is an error, it should be notified. It should not fail silently.
Ideally, this should not happen at all, and the kickoff function call should return a proper CrewResponse with LLM completion.
Screenshots/Code snippets
Operating System
Ubuntu 20.04
Python Version
3.12
crewAI Version
0.51.1
crewAI Tools Version
0.12.0
Virtual Environment
Poetry
Evidence
Run this code:
import os
from dotenv import load_dotenv
load_dotenv()
import agentops
agentops.init()
from crewai import Agent, Task, Crew
dummy_agent = Agent(
role="Dummy",
goal="You don't have any goal",
backstory=(
"You are a dummy and you just give one word replies to everything you are asked to do"
),
allow_delegation=False,
verbose=True,
)
dummy_task = Task(
description=(
"The task is to be yourself"
),
expected_output="Give one word answers",
agent=dummy_agent,
)
dummy_crew = Crew(
agents=[dummy_agent,],
tasks=[dummy_task],
memory=False,
verbose=True
)
dummy_crew_output = dummy_crew.kickoff()
Possible Solution
NA
Additional context
NA
Never import agentops before importing crewai classes.
Inside crewai crew.py, agent.py, tool_usage.py, etc, they are importing autogen by checking the variable:
agentops = None
if os.environ.get("AGENTOPS_API_KEY"):
try:
import agentops
except ImportError:
pass
If you import autogen and do autogen.init() before importing any of crewAI's Crew, Agent, Tool class, your agentops variable will reset and the agentops.init() session will be lost. The system then fails silently and you are left scratching your head why your LLM is not responding.
While this is a temporary solution, I have still not figured out how to make sure there is some error message when this happens, and ideally it shouldn't happen at all. So not closing this issue.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.