Skip to content

Commit

Permalink
feat: add setting for AgentOps (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Aug 7, 2024
1 parent 83afebb commit f7b0d00
Show file tree
Hide file tree
Showing 20 changed files with 777 additions and 415 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
placeholder: E.g., 0.1.6.0
placeholder: E.g., 0.1.6.1
validations:
required: true

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ conda create --name camel python=3.9
conda activate camel
# Clone github repo
git clone -b v0.1.6.0 https://github.com/camel-ai/camel.git
git clone -b v0.1.6.1 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
2 changes: 1 addition & 1 deletion camel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========

__version__ = '0.1.6.0'
__version__ = '0.1.6.1'

__all__ = [
'__version__',
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
from camel.terminators import ResponseTerminator
from camel.toolkits import OpenAIFunction

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


class FunctionCallingRecord(BaseModel):
r"""Historical records of functions called in the conversation.
Expand Down Expand Up @@ -92,6 +103,7 @@ def as_dict(self) -> dict[str, Any]:
return self.model_dump()


@track_agent(name="ChatAgent")
class ChatAgent(BaseAgent):
r"""Class for managing conversations of CAMEL Chat Agents.
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/critic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@
from camel.responses import ChatAgentResponse
from camel.utils import get_first_int, print_text_animated

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="CriticAgent")
class CriticAgent(ChatAgent):
r"""A class for the critic agent that assists in selecting an option.
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/deductive_reasoner_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@
from camel.prompts import TextPrompt
from camel.types import RoleType

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="DeductiveReasonerAgent")
class DeductiveReasonerAgent(ChatAgent):
r"""An agent responsible for deductive reasoning. Model of deductive
reasoning:
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/embodied_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@
from camel.responses import ChatAgentResponse
from camel.utils import print_text_animated

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="EmbodiedAgent")
class EmbodiedAgent(ChatAgent):
r"""Class for managing conversations of CAMEL Embodied Agents.
Expand Down
13 changes: 13 additions & 0 deletions camel/agents/knowledge_graph_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
)
from camel.types import RoleType

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


text_prompt = """
You are tasked with extracting nodes and relationships from given content and
structures them into Node and Relationship objects. Here's the outline of what
Expand Down Expand Up @@ -97,6 +109,7 @@
"""


@track_agent(name="KnowledgeGraphAgent")
class KnowledgeGraphAgent(ChatAgent):
r"""An agent that can extract node and relationship information for
different entities from given `Element` content.
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/role_assignment_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@
from camel.prompts import TextPrompt
from camel.types import RoleType

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="RoleAssignmentAgent")
class RoleAssignmentAgent(ChatAgent):
r"""An agent that generates role names based on the task prompt.
Expand Down
12 changes: 12 additions & 0 deletions camel/agents/search_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@
from camel.types import RoleType
from camel.utils import create_chunks

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="SearchAgent")
class SearchAgent(ChatAgent):
r"""An agent that summarizes text based on a query and evaluates the
relevance of an answer.
Expand Down
15 changes: 15 additions & 0 deletions camel/agents/task_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@
from camel.types import RoleType, TaskType
from camel.utils import get_task_list

# AgentOps decorator setting
try:
from agentops import track_agent
except ImportError:

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

return noop


@track_agent(name="TaskSpecifyAgent")
class TaskSpecifyAgent(ChatAgent):
r"""An agent that specifies a given task prompt by prompting the user to
provide more details.
Expand Down Expand Up @@ -115,6 +127,7 @@ def run(
return TextPrompt(specified_task_msg.content)


@track_agent(name="TaskPlannerAgent")
class TaskPlannerAgent(ChatAgent):
r"""An agent that helps divide a task into subtasks based on the input
task prompt.
Expand Down Expand Up @@ -184,6 +197,7 @@ def run(
return TextPrompt(sub_tasks_msg.content)


@track_agent(name="TaskCreationAgent")
class TaskCreationAgent(ChatAgent):
r"""An agent that helps create new tasks based on the objective
and last completed task. Compared to :obj:`TaskPlannerAgent`,
Expand Down Expand Up @@ -298,6 +312,7 @@ def run(
return get_task_list(sub_tasks_msg.content)


@track_agent(name="TaskPrioritizationAgent")
class TaskPrioritizationAgent(ChatAgent):
r"""An agent that helps re-prioritize the task list and
returns numbered prioritized list. Modified from
Expand Down
4 changes: 3 additions & 1 deletion camel/toolkits/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

from typing import List

from camel.utils import AgentOpsMeta

from .openai_function import OpenAIFunction


class BaseToolkit:
class BaseToolkit(metaclass=AgentOpsMeta):
def get_tools(self) -> List[OpenAIFunction]:
raise NotImplementedError("Subclasses must implement this method.")
3 changes: 1 addition & 2 deletions camel/toolkits/open_api_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import requests

from camel.toolkits import OpenAIFunction, openapi_security_config
from camel.toolkits.base import BaseToolkit
from camel.types import OpenAPIName


class OpenAPIToolkit(BaseToolkit):
class OpenAPIToolkit:
r"""A class representing a toolkit for interacting with OpenAPI APIs.
This class provides methods for interacting with APIs based on OpenAPI
Expand Down
4 changes: 4 additions & 0 deletions camel/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========

from .commons import (
AgentOpsMeta,
agentops_decorator,
api_keys_required,
check_server_running,
create_chunks,
Expand Down Expand Up @@ -70,4 +72,6 @@
'get_pydantic_object_schema',
'func_string_to_callable',
'json_to_function_code',
'agentops_decorator',
'AgentOpsMeta',
]
47 changes: 47 additions & 0 deletions camel/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,50 @@ def is_docker_running() -> bool:
return result.returncode == 0
except (subprocess.CalledProcessError, FileNotFoundError):
return False


try:
from agentops import ToolEvent, record
except ImportError:
ToolEvent = None


def agentops_decorator(func):
r"""Decorator that records the execution of a function if ToolEvent is
available.
Parameters:
func (callable): The function to be decorated.
Returns:
callable: The wrapped function which records its execution details.
"""

@wraps(func)
def wrapper(*args, **kwargs):
if ToolEvent:
tool_event = ToolEvent(name=func.__name__, params=kwargs)
result = func(*args, **kwargs)
tool_event.returns = result
record(tool_event)
return result
return func(*args, **kwargs)

return wrapper


class AgentOpsMeta(type):
r"""Metaclass that automatically decorates all callable attributes with
the agentops_decorator,
except for the 'get_tools' method.
Methods:
__new__(cls, name, bases, dct):
Creates a new class with decorated methods.
"""

def __new__(cls, name, bases, dct):
for attr, value in dct.items():
if callable(value) and attr != 'get_tools':
dct[attr] = agentops_decorator(value)
return super(AgentOpsMeta, cls).__new__(cls, name, bases, dct)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
project = 'CAMEL'
copyright = '2023, CAMEL-AI.org'
author = 'CAMEL-AI.org'
release = '0.1.6.0'
release = '0.1.6.1'

html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
Expand Down
2 changes: 1 addition & 1 deletion docs/get_started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
git clone -b v0.1.6.0 https://github.com/camel-ai/camel.git
git clone -b v0.1.6.1 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
Loading

0 comments on commit f7b0d00

Please sign in to comment.