Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agentops integration #487

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion python/composio/tools/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import base64
import binascii
from functools import wraps
import hashlib
import importlib
import itertools
import json
import os
import time
import typing as t
from importlib.util import find_spec

import typing_extensions as te
from pydantic import BaseModel
Expand Down Expand Up @@ -46,7 +49,7 @@
from composio.tools.local import load_local_tools
from composio.tools.local.handler import LocalClient
from composio.utils.enums import get_enum_key
from composio.utils.logging import LogLevel, WithLogger
from composio.utils.logging import LogLevel, WithLogger, get_logger
from composio.utils.url import get_api_url_base


Expand All @@ -69,6 +72,30 @@ class ProcessorsType(te.TypedDict):
"""Response processors."""


def _check_agentops() -> bool:
"""Check if AgentOps is installed and initialized."""
logger = get_logger()
logger.info("Checking if AgentOps is installed and initialized")
if find_spec("agentops") is None:
logger.info("AgentOps is not installed")
return False
logger.info("AgentOps is installed")
import agentops
logger.info("AgentOps is initialized")
return agentops.get_api_key() is not None

def _record_action_if_available(func: t.Callable) -> t.Callable:
@wraps(func)
def wrapper(self, *args, **kwargs):
if _check_agentops():
import agentops
action_name = str(kwargs.get('action', 'unknown_action'))
return agentops.record_action(action_name)(func)(self, *args, **kwargs)
else:
return func(self, *args, **kwargs)
return wrapper


class ComposioToolSet(WithLogger):
"""Composio toolset."""

Expand Down Expand Up @@ -486,6 +513,7 @@ def _process_respone(self, action: Action, response: t.Dict) -> t.Dict:
type_="post",
)

@_record_action_if_available
def execute_action(
self,
action: ActionType,
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/crew_ai/crewai_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from langchain_openai import ChatOpenAI

from composio_crewai import App, ComposioToolSet
import agentops

agentops.init()


# Load environment variables from .env
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/langchain/langchain_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
from langchain import hub # type: ignore
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_openai import ChatOpenAI
import agentops


# Load environment variables from .env
dotenv.load_dotenv()

agentops.init()

# Pull relevant agent model.
prompt = hub.pull("hwchase17/openai-functions-agent")

Expand Down
Loading