crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
19.31k stars 2.67k forks source link

[BUG] CrewAI is failing when I use agentops #1307

Open anmol-aidora opened 1 week ago

anmol-aidora commented 1 week ago

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

Screenshot 2024-09-06 at 11 26 03 PM

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

anmol-aidora commented 1 week ago

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.