Skip to content

Commit

Permalink
AgentOps ENG-525: Decouple CrewAI and AgentOps (#1033)
Browse files Browse the repository at this point in the history
* Make AgentOps import optional upon AGENTOPS_API_KEY
    being set

Co-authored-by: João Moura <joaomdmoura@gmail.com>
  • Loading branch information
tiovikram and joaomdmoura authored Aug 10, 2024
1 parent f1ad137 commit dbce944
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
19 changes: 13 additions & 6 deletions src/crewai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@
from crewai.utilities.token_counter_callback import TokenCalcHandler
from crewai.utilities.training_handler import CrewTrainingHandler

agentops = None
try:
import agentops # type: ignore # Name "agentops" already defined on line 21
from agentops import track_agent
except ImportError:

def mock_agent_ops_provider():
def track_agent():
def noop(f):
return f

return noop
return track_agent

agentops = None

if os.environ.get("AGENTOPS_API_KEY"):
try:
import agentops # type: ignore # Name "agentops" already defined on line 21
from agentops import track_agent
except ImportError:
track_agent = mock_agent_ops_provider()
else:
track_agent = mock_agent_ops_provider()


@track_agent()
Expand Down
12 changes: 8 additions & 4 deletions src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
from concurrent.futures import Future
from hashlib import md5
import os
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

from langchain_core.callbacks import BaseCallbackHandler
Expand Down Expand Up @@ -47,10 +48,13 @@
from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandler
from crewai.utilities.training_handler import CrewTrainingHandler

try:
import agentops
except ImportError:
agentops = None

agentops = None
if os.environ.get("AGENTOPS_API_KEY"):
try:
import agentops
except ImportError:
pass

if TYPE_CHECKING:
from crewai.pipeline.pipeline import Pipeline
Expand Down
11 changes: 7 additions & 4 deletions src/crewai/tools/tool_usage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
from difflib import SequenceMatcher
import os
from textwrap import dedent
from typing import Any, List, Union

Expand All @@ -11,10 +12,12 @@
from crewai.tools.tool_calling import InstructorToolCalling, ToolCalling
from crewai.utilities import I18N, Converter, ConverterError, Printer

try:
import agentops
except ImportError:
agentops = None
agentops = None
if os.environ.get("AGENTOPS_API_KEY"):
try:
import agentops
except ImportError:
pass

OPENAI_BIGGER_MODELS = ["gpt-4o"]

Expand Down
20 changes: 14 additions & 6 deletions src/crewai/utilities/evaluators/task_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import List

from langchain_openai import ChatOpenAI
Expand All @@ -6,16 +7,23 @@
from crewai.utilities import Converter
from crewai.utilities.pydantic_schema_parser import PydanticSchemaParser

agentops = None
try:
from agentops import track_agent
except ImportError:

def track_agent(name):
def mock_agent_ops_provider():
def track_agent():
def noop(f):
return f

return noop
return track_agent

agentops = None

if os.environ.get("AGENTOPS_API_KEY"):
try:
from agentops import track_agent
except ImportError:
track_agent = mock_agent_ops_provider()
else:
track_agent = mock_agent_ops_provider()


class Entity(BaseModel):
Expand Down

0 comments on commit dbce944

Please sign in to comment.