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

AgentOps Implementation #2516

Closed
wants to merge 33 commits into from
Closed

AgentOps Implementation #2516

wants to merge 33 commits into from

Conversation

bboynton97
Copy link

@bboynton97 bboynton97 commented Apr 25, 2024

Why are these changes needed?

This PR integrates AgentOps agent observability within Autogen. Autogen users can start tracking a plethora of data by simply adding agentops.init() to their code.

AgentOps is added as an optional dependency and can be installed with pip install pyautogen[agentops].

https://www.loom.com/share/8b489e9c07aa4211a87d0f8092e317d9?sid=b09e7576-c507-4a8d-aae3-6394716d40d2

Related issue number

Checks

@bboynton97
Copy link
Author

bboynton97 commented Apr 25, 2024

@microsoft-github-policy-service agree company="AgentOps"

@sonichi sonichi added integration software integration logging related to logging issue labels Apr 26, 2024
Copy link

gitguardian bot commented Apr 26, 2024

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
10404662 Triggered Generic CLI Secret 0d685f3 .github/workflows/dotnet-release.yml View secret
10404662 Triggered Generic CLI Secret 74dbc5e .github/workflows/dotnet-release.yml View secret
- Generic High Entropy Secret db9fb81 website/docs/tutorial/tool-use.ipynb View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Two things to help this moving forward:

  1. Can you take a look at the databricks PR for comments regarding ecosystem page (i.e., having a logo helps) and how to make the notebook displayed on the website. DBRX (Databricks LLM) example notebook #2434
  2. Can you take a look at autogen.runtime_logging for our logging entry points?

@bboynton97
Copy link
Author

Thanks for the PR. Two things to help this moving forward:

  1. Can you take a look at the databricks PR for comments regarding ecosystem page (i.e., having a logo helps) and how to make the notebook displayed on the website. DBRX (Databricks LLM) example notebook #2434
  2. Can you take a look at autogen.runtime_logging for our logging entry points?
  1. Should be good to go!
  2. We did look at runtime_logging.py. For basic logging, this works. However to use the full functionality that our instrumenting enables, we need to integrate at a deeper level. For instance, for our SDK to identify which agent corresponds with a specific chat_completion, we need to be able to look at the context of that specific call, not just a logging callback.

@bboynton97 bboynton97 requested a review from ekzhu April 29, 2024 22:02
@sonichi
Copy link
Collaborator

sonichi commented Apr 30, 2024

Could you fix code formatting error? https://github.com/microsoft/autogen/actions/runs/8885436373/job/24396787206?pr=2516
and docs error?
pre-commit may help.

@ekzhu
Copy link
Collaborator

ekzhu commented Apr 30, 2024

@cheng-tan can you take a look at the action events this PR added in conversable_agent.py. Do you think this is something we can cover by adding to the runtime_logging.py interface?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please write tests to cover the newly added code? The tests can be run in a subset of envs of the CI.

.gitattributes Outdated Show resolved Hide resolved
__all__ = ("ConversableAgent",)

logger = logging.getLogger(__name__)

F = TypeVar("F", bound=Callable[..., Any])


@track_agent()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this decorator do if activated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wraps the init function of the class to assign an agentops ID. Then in our instrumentation of LLM calls, we look up the call stack to see if the call or Event is being made by a decorated agent class. If so, we relate them in our db

original_init = obj.__init__

            def new_init(self, *args, **kwargs):
                try:
                    original_init(self, *args, **kwargs)
                    self.agent_ops_agent_id = str(uuid4())
                    Client().create_agent(self.agent_ops_agent_id, self.agent_ops_agent_name)
                except AttributeError as e:
                    logger.warning("AgentOps failed to track an agent. This often happens if agentops.init() was not "
                                  "called before initializing an agent with the @track_agent decorator.")
                    raise e

            obj.__init__ = new_init

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the biggest thing preventing us from using the runtime_logging as events like log_chat_completion don't have an Agent ID that we can use to display what agents performed what functions. I can make a note of this in the related issue

Copy link
Collaborator

@ekzhu ekzhu May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a unique agent ID is certainly useful for many other things. We can add an id field in the agent constructor to generate an id upon creation or using an existing id.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonichi @jackgerrits for adding a new id field for each agent to support external analytics

@@ -637,16 +652,29 @@ def send(
Raises:
ValueError: if the message can't be converted into a valid ChatCompletion message.
"""
action_event = (
Copy link
Collaborator

@ekzhu ekzhu May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take a look at runtime_logging module and work with @lalo in #2423 to add new events through the logging API rather than adding agent ops specific code here?

Can you also implement an agent ops logger to cover those new events. You can take a look at the ongoing PR by our colleague at Microsoft's cosmos db as a reference. #2329

Copy link
Collaborator

@ekzhu ekzhu May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to have a custom logger that user can pass into runtime_logging, and the custom logger (I.e, agent ops logger) can receive all events logged by the runtime_logging.

#2581

auto-merge was automatically disabled May 7, 2024 21:12

Head branch was pushed to by a user without write access

@bboynton97 bboynton97 closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration software integration logging related to logging issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants