From 448d63c1154d576244cbe330aee2f9f3dc52cbed Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Wed, 12 Jun 2024 15:25:31 -0700 Subject: [PATCH 1/2] autogen docs (#251) --- README.md | 6 +++ docs/v1/integrations/autogen.mdx | 81 ++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9aa2d6e8..a945d783 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,12 @@ pip install git+https://github.com/AgentOps-AI/crewAI.git@main - [AgentOps integration example](https://docs.agentops.ai/v1/integrations/crewai) - [Official CrewAI documentation](https://docs.crewai.com/how-to/AgentOps-Observability) +### AutoGen 🤖 +With only two lines of code, add full observability and monitoring to Autogen agents. Set an `AGENTOPS_API_KEY` in your environment and call `agentops.init()` + +- [Autogen Observability Example](https://microsoft.github.io/autogen/docs/notebooks/agentchat_agentops) +- [Autogen - AgentOps Documentation](https://microsoft.github.io/autogen/docs/ecosystem/agentops) + ### Langchain 🦜🔗 AgentOps works seamlessly with applications built using Langchain. To use the handler, install Langchain as an optional dependency: diff --git a/docs/v1/integrations/autogen.mdx b/docs/v1/integrations/autogen.mdx index 058ea617..04922bfc 100644 --- a/docs/v1/integrations/autogen.mdx +++ b/docs/v1/integrations/autogen.mdx @@ -3,6 +3,81 @@ title: Autogen description: "AgentOps provides first class support for Autogen" --- - -Documentation for this integration is coming soon. - \ No newline at end of file +AgentOps and Autogen teamed up to make monitoring Autogen agents dead simple. + +Autogen has comprehensive [documentation](https://microsoft.github.io/autogen/docs) available as well as a great [quickstart](https://microsoft.github.io/autogen/docs/Getting-Started). + +## Adding AgentOps to Autogen agents + + + + + ```bash pip + pip install agentops + ``` + ```bash poetry + poetry add agentops + ``` + + + [Give us a star](https://github.com/AgentOps-AI/agentops) on GitHub while you're at it (you may be our 1,000th 😊) + + + + + ```bash pip + pip install pyautogen + ``` + ```bash poetry + poetry add pyautogen + ``` + + + + 1. Before setting up anything in Autogen, call `agentops.init()` + 2. At the end of your agent run, call `agentops.end_session("Success")` + + ```python python + import agentops + + # Beginning of program (i.e. main.py, __init__.py) + # IMPORTANT: Must be before using any autogen setup + agentops.init() + ... + # End of program (e.g. main.py) + agentops.end_session("Success") # Success|Fail|Indeterminate + ``` + + + Instantiating the AgentOps client will automatically instrument Autogen, meaning you will be able to see all + of your sessions on the AgentOps Dashboard along with the full LLM chat histories, cost, token counts, etc. + + + For more features see our [Usage](/v1/usage) section. + + + + Retrieve an API Key from your Settings > [Projects & API Keys](https://app.agentops.ai/settings/projects) page. + + + + + API keys are tied to individual projects.

+ A Default Project has been created for you, so just click Copy API Key +
+ Set this API Key in your [environment variables](/v1/usage/environment-variables) + ```python .env + AGENTOPS_API_KEY= + ``` +
+ + Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Autogen Agent! 🕵️ + + After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard + +
{/* Intentionally blank div for newline */} + + + + + \ No newline at end of file From 961ba21d4213d9dc496e51526110f460b993c625 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Thu, 13 Jun 2024 12:53:09 -0700 Subject: [PATCH 2/2] agentops functions dont work without first calling init (#255) * block without init * handle no tokens better * fixed wrapper * add decorators * bump version * init on start session --- agentops/__init__.py | 36 +++++++++++++++++++++++++++++++++++- agentops/client.py | 2 +- pyproject.toml | 2 +- tests/test_session.py | 1 - 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index 2edf10f8..1335f6a9 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -1,4 +1,5 @@ # agentops/__init__.py +import functools import os import logging from typing import Optional, List, Union @@ -18,6 +19,23 @@ except ModuleNotFoundError: pass +is_initialized = False + + +def noop(*args, **kwargs): + return + + +def check_init(child_function): + @functools.wraps(child_function) + def wrapper(*args, **kwargs): + if is_initialized: + return child_function(*args, **kwargs) + else: + return noop(*args, **kwargs) + + return wrapper + def init( api_key: Optional[str] = None, @@ -79,6 +97,9 @@ def init( skip_auto_end_session=skip_auto_end_session, ) + global is_initialized + is_initialized = True + return inherited_session_id or c.current_session_id @@ -118,9 +139,19 @@ def start_session( e.g. ["test_run"]. config: (Configuration, optional): Client configuration object """ - return Client().start_session(tags, config, inherited_session_id) + + try: + sess_result = Client().start_session(tags, config, inherited_session_id) + + global is_initialized + is_initialized = True + + return sess_result + except Exception: + pass +@check_init def record(event: Union[Event, ErrorEvent]): """ Record an event with the AgentOps service. @@ -131,6 +162,7 @@ def record(event: Union[Event, ErrorEvent]): Client().record(event) +@check_init def add_tags(tags: List[str]): """ Append to session tags at runtime. @@ -141,6 +173,7 @@ def add_tags(tags: List[str]): Client().add_tags(tags) +@check_init def set_tags(tags: List[str]): """ Replace session tags at runtime. @@ -169,5 +202,6 @@ def stop_instrumenting(): Client().stop_instrumenting() +@check_init def create_agent(name: str, agent_id: Optional[str] = None): return Client().create_agent(name=name, agent_id=agent_id) diff --git a/agentops/client.py b/agentops/client.py index 57f9cb60..7108e393 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -418,7 +418,7 @@ def end_session( self._session.end_session(end_state, end_state_reason) token_cost = self._worker.end_session(self._session) - if token_cost == "unknown": + if token_cost is None or token_cost == "unknown": logger.info("Could not determine cost of run.") else: token_cost_d = Decimal(token_cost) diff --git a/pyproject.toml b/pyproject.toml index 8ea93afc..4324f5c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "agentops" -version = "0.2.2" +version = "0.2.3" authors = [ { name="Alex Reibman", email="areibman@gmail.com" }, { name="Shawn Qiu", email="siyangqiu@gmail.com" }, diff --git a/tests/test_session.py b/tests/test_session.py index e8a1bf14..7148a008 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -29,7 +29,6 @@ def setup_method(self): def test_session(self, mock_req): agentops.start_session(config=self.config) - print(self.config.api_key) agentops.record(ActionEvent(self.event_type)) agentops.record(ActionEvent(self.event_type))