Skip to content

AgentOps Integration #22

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
43 changes: 32 additions & 11 deletions autogenui/manager.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# a manager class that can
# load an autogen flow run an autogen flow and return the response to the client


from typing import Dict
import autogen
from .utils import parse_token_usage
import time
import agentops
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()

# Initialize AgentOps
agentops.init(os.getenv('AGENTOPS_API_KEY'))

class Manager(object):
@agentops.record_function('Manager_init')
def __init__(self) -> None:

pass

@agentops.record_function('Manager_run_flow')
def run_flow(self, prompt: str, flow: str = "default") -> None:
#autogen.ChatCompletion.start_logging(compact=False)
config_list = autogen.config_list_openai_aoai()
Expand All @@ -25,7 +30,9 @@ def run_flow(self, prompt: str, flow: str = "default") -> None:

assistant = autogen.AssistantAgent(
name="assistant",
max_consecutive_auto_reply=3, llm_config=llm_config,)
max_consecutive_auto_reply=3,
llm_config=llm_config,
)

# create a UserProxyAgent instance named "user_proxy"
user_proxy = autogen.UserProxyAgent(
Expand All @@ -39,18 +46,32 @@ def run_flow(self, prompt: str, flow: str = "default") -> None:
"use_docker": False
},
)

start_time = time.time()
user_proxy.initiate_chat(
assistant,
message=prompt,
)

with agentops.record_span('user_proxy_chat'):
user_proxy.initiate_chat(
assistant,
message=prompt,
)

messages = user_proxy.chat_messages[assistant]
#logged_history = autogen.ChatCompletion.logged_history
autogen.ChatCompletion.stop_logging()

duration = time.time() - start_time

response = {
"messages": messages[1:],
"usage": "", #parse_token_usage(logged_history),
"duration": time.time() - start_time,
"duration": duration,
}

# Record metrics
agentops.record_metric('chat_duration', duration)
agentops.record_metric('message_count', len(messages) - 1)

return response

# End of program
agentops.end_session('Success')