-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
New Feature: Agent Names captured in traces and logs to aggregate per agent stats #10174
Comments
Adding @dmytrostruk , it might make sense that this should be at the Kernel level |
@dmytrostruk can you handle making the equivalent .NET changes |
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Address feature request: #10174 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> This pull request introduces a new decorator for tracing agent invocations and applies it to various methods in the `ChatCompletionAgent` and `OpenAIAssistantAgent` classes. Additionally, it includes new unit tests to ensure the decorator is correctly applied and functions as expected. ### Key Changes: **Decorator Implementation:** * Added a new `trace_agent_invocation` decorator in `python/semantic_kernel/utils/telemetry/agent_diagnostics/decorators.py` to trace agent invocations using OpenTelemetry. **Decorator Application:** * Applied the `trace_agent_invocation` decorator to the `invoke` and `invoke_stream` methods in `ChatCompletionAgent` (`python/semantic_kernel/agents/chat_completion/chat_completion_agent.py`). [[1]](diffhunk://#diff-0f0a27c107368504c4347c88528b7b4234dcead1919005bcae13f5d16d6cf26dR19) [[2]](diffhunk://#diff-0f0a27c107368504c4347c88528b7b4234dcead1919005bcae13f5d16d6cf26dR80) [[3]](diffhunk://#diff-0f0a27c107368504c4347c88528b7b4234dcead1919005bcae13f5d16d6cf26dR134) * Applied the `trace_agent_invocation` decorator to the `invoke` and `invoke_stream` methods in `OpenAIAssistantAgent` (`python/semantic_kernel/agents/open_ai/open_ai_assistant_base.py`). [[1]](diffhunk://#diff-70e75c57136d3a90d045af4b8d59fb8e8101251d7c5126458bb5d9e6c36556a4R46) [[2]](diffhunk://#diff-70e75c57136d3a90d045af4b8d59fb8e8101251d7c5126458bb5d9e6c36556a4R608) [[3]](diffhunk://#diff-70e75c57136d3a90d045af4b8d59fb8e8101251d7c5126458bb5d9e6c36556a4R861) ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]>
Reopening for .Net @dmytrostruk We may need to similar sample in .Net to verify the feature: #10184 Please let me know if you want to split the work or have a discussion. |
Including the agent-id along with the name may be something to consider. Name is optional, but Id is required. Name is also not enforced as unique. May want to revisit the Python changes as well. |
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Related: #10174 This PR updates logging messages in Agent Framework to include agent name. `UnnamedAgent` is used as a default value when the agent's name is not specified to provide meaningful context in logs. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
name: Feature request
about: Tracing agent names
For the internal audit I would like to be able to trace agent token usage statistics.
I am OK to rely on Kusto SQL, but I need the agent names to be captured in traces and logs automatically.
The text was updated successfully, but these errors were encountered: