avatarRomin Irani

Summary

The article provides a tutorial on integrating the AgentOps.ai platform for monitoring and metrics with the Autogen framework to enhance the observability of multi-agent interactions.

Abstract

The tutorial is part of a series on the Autogen framework, which has previously covered setting up autonomous agents, terminating conversations, human interaction, and using local language models (LLMs). This installment focuses on the importance of agent monitoring and metrics, emphasizing the need for control and understanding of agent behavior in real-world applications. It introduces the AgentOps.ai platform as a solution for agent observability, offering features such as responsiveness tracking, debugging capabilities, interaction tracing, and session replay. The article outlines a two-step process for integrating AgentOps.ai: obtaining API keys and incorporating the AgentOps Python library into the project. It provides detailed instructions, including code snippets and screenshots, to guide users through the setup process and demonstrates the platform's functionality with a sample run of an application involving two autonomous agents: a Quote Writer and a Quote Reviewer. The conclusion promises further exploration of communication patterns between agents in the next part of the series.

Opinions

  • The author believes that monitoring and metrics are crucial for the practical deployment of autonomous agents.
  • AgentOps.ai is presented as a valuable tool for enhancing the development process and monitoring agents in production.
  • The integration of AgentOps.ai is considered straightforward, involving minimal changes to existing codebases.
  • The free tier of AgentOps.ai is suggested as sufficient for initial exploration and use.
  • The article implies that the ability to replay sessions and observe detailed metrics is essential for debugging and improving agent interactions.
  • The author expresses that the AgentOps.ai platform can provide a comprehensive set of metrics and the ability to export them for further analysis.
  • The use of tags in AgentOps.ai is highlighted as a useful feature for organizing and identifying conversations within the platform.
  • The sample interaction between the Quote Writer and Quote Reviewer agents demonstrates the depth of analysis possible with the AgentOps.ai integration.
  • The conclusion indicates the author's intent to continue exploring advanced aspects of multi-agent communication in future tutorials.

Tutorial : Multi-Agent interactions with Autogen and Gemini — Part 5 : AgentOps

Hope you have been enjoying the series on Autogen framework so far. We’ve taken a look at getting started, autonomous agents talking to each other, a human talking to an autonomous agent, then we’ve used both Google Gemini models and a local Gemma model, powered by Ollama, as the LLMs for the interactions.

The series so far:

Metrics, Monitoring for your Agent

So far, we have just written our code, run it and all is well. But the real world demands that we have good control over what is going on with our Agents. By that, it can mean one or more of the following:

  • How responsive are our agents?
  • If something goes wrong with the Agent, can we understand and debug what happened?
  • Can we see multiple back and forth traces between agents and understand what is going on, what messages are being exchanged?
  • What if we wanted to replay a session or two between Agents again?

The above is not an exhaustive list and a monitoring platform should provide a lot more metrics with the ability to possibly export metrics and dashboards to integrate.

AgentOps.ai platform

Enter Agent Monitoring and Metrics, a very crucial requirement of any framework. Ideally, I would have preferred that some of these metrics are built within the framework and there is the Autogen SQLite and File Logger, but I thought of exploring the Observability integration with AgentOps.ai.

The documentation for the integration is available over here.

The steps to integrate with the platform are straightforward:

  1. Get an account at AgentOps.ai
  2. Integrate the AgentOps Python library and sprinkle in some integration code.

Step 1 : Get an account at AgentOps.ai and obtain API Keys

Visit AgentOps.ai and sign up for the service. The free tier will do for now.

Once you are logged in, visit the main menu on the left and at the bottom, you will find the API Keys section as shown below:

Click on that, create a new project and you will have the API Key. Copy the API Key for now since we shall use that in our code.

Step 2 : Integrate AgentOps Python library

We are going to create a new project to test out the interaction between two autonomous agents : Quote Writer and Quote Reviewer.

We will modify our existing requirements.txt file to add in the agentops module too as shown below:

utogen-agentchat[llm,gemini]~=0.2
agentops

Create the Python environment with the above requirements.txt file and you are all set to run the main program as shown below.

The main program is available in the file multi-agent-101.py and the code is shown below:

from autogen import ConversableAgent
import autogen
import agentops

config_list_gemini = autogen.config_list_from_json("model_config.json")
agentops.init(api_key="YOUR AGENTOPS API KEY", 
              default_tags=["my-multi-agent-101-tag"])

quote_writer = ConversableAgent(
    name="Quote Generator",
    system_message="Your task is to provide famous quotes",
    llm_config = {"config_list" : config_list_gemini},
    code_execution_config = False,
    human_input_mode = "NEVER",
)

quote_reviewer = ConversableAgent(
    name="Joke Reviewer",
    system_message="Your task is to review a famous quote and provide your comments briefly in a list.",
    llm_config = {"config_list" : config_list_gemini},
    code_execution_config = False,
    human_input_mode = "NEVER",
)

reply = quote_writer.generate_reply(messages=[{"content": "Give me a quote by Albert Einstein", "role": "user"}])

quote_writer.initiate_chat(quote_reviewer,message=reply['content'], max_turns=2)

agentops.end_session("Success")

The code is not very different except for the additional agentops module code. Let’s go through it briefly.

  1. We are still using the model_config.json file to initialize the list of Gemini models. This file is the same from some of earlier parts that we have seen.
  2. We initialize the agentops module via the init method and we are also putting in a tag that we can use in their application to identify our conversation. Note that you will have to use the AgentOps API Key that you got, as instructed in the earlier section.
  3. The quote_writer and quote_reviewer agents are the same. Each of them is an Autonomous agent that is using the ConversableAgent class. One of them generates the quotes and the other reviews them.
  4. We finally get an initial quote and then initiate the chat between the quote_writer and the quote_reviewer.
  5. We end the agentops session at the end.

AgentOps.ai in Action

You can run the application via the following command:

$ python multi-agent-101.py

Run this a few times and then visit https://app.agentops.ai/projects, where you can possibly go to your default project and observe the metrics and more. A few sample screenshots are shown below:

Sample run on the command line:

🖇 AgentOps: Session Replay: https://app.agentops.ai/drilldown?session_id=94154fb7-fe9b-4021-af91-138258199d2f
Quote Generator (to Joke Reviewer):

"Strive not to be a success, but rather to be of value." 


--------------------------------------------------------------------------------
Joke Reviewer (to Quote Generator):

Here are some brief comments on the quote "Strive not to be a success, but rather to be of value":

* **Focus on Impact:** This quote encourages a shift in focus from personal achievement to making a positive contribution to others. 
* **Intrinsic Motivation:** It suggests that true fulfillment comes from serving a purpose larger than oneself, rather than chasing external validation.
* **Long-Term Value:**  Value, unlike fleeting success, can have a lasting impact and leave a legacy beyond individual accomplishment.
* **Defining Value:** The quote doesn't explicitly define "value," leaving room for individual interpretation and finding meaning in their own unique contributions.
* **Practical Application:** While aspirational, the quote can be applied to daily life by considering the impact of actions and decisions on others. 


--------------------------------------------------------------------------------
Quote Generator (to Joke Reviewer):

Those are great observations about the quote "Strive not to be a success, but rather to be of value"!  You've captured its essence perfectly. 

Here are a few additional points to consider:

* **Humility and Service:** The quote promotes a sense of humility, recognizing that true value comes from serving others, not from self-promotion. 
* **Authenticity:**  It encourages people to pursue their passions and contribute in ways that align with their core values, leading to a more authentic and fulfilling life.
* **Legacy:**  The quote implies that leaving a positive mark on the world is more meaningful than simply achieving a certain level of success. It encourages us to think about the long-term impact of our choices.

Overall, this quote offers a powerful message about living a purposeful life that goes beyond personal gain. It inspires us to consider the value we bring to the world and the difference we can make through our actions. 


--------------------------------------------------------------------------------
Joke Reviewer (to Quote Generator):

You've added some truly insightful points! I especially love how you highlight the connections between the quote and:

* **Humility and Service:**  The quote beautifully underscores that genuine value comes from serving others, not self-aggrandizement. 
* **Authenticity:** The pursuit of value encourages us to align our actions with our core values, leading to a more authentic and fulfilling life. 
* **Legacy:** The quote beautifully underscores the importance of leaving a positive impact on the world, a legacy that transcends individual achievement. 

It's clear this quote resonates deeply, prompting us to consider the impact we have and encouraging us to live with purpose and meaning.  


--------------------------------------------------------------------------------
🖇 AgentOps: Session stats - Cost: $0.00 Duration: 1.9s LLMs: 4 Tools: 0 Actions: 20 Errors: 0
🖇 AgentOps: Session Replay: https://app.agentops.ai/drilldown?session_id=94154fb7-fe9b-4021-af91-138258199d2f

AgentOps.ai web application

Sample Session Drilldown

Source Code

The source code for this application in available in the app5 folder and is linked here:

Conclusion

Hope this helps you understand the mechanism to incorporate observability into your Agents using the AgentOps.ai platform. In the next part in the series, we will investigate into various communication patterns between agents. Stay tuned.

Autogen
Multi Agent Systems
Observability
Agentops
Gemini
Recommended from ReadMedium