Skip to content

[azsdk-cli] Use scoped tools and helpers, add micro agent example#12017

Merged
benbp merged 7 commits into
Azure:mainfrom
benbp:benbp/azsdk-cli-scoped
Sep 15, 2025
Merged

[azsdk-cli] Use scoped tools and helpers, add micro agent example#12017
benbp merged 7 commits into
Azure:mainfrom
benbp:benbp/azsdk-cli-scoped

Conversation

@benbp
Copy link
Copy Markdown
Member

@benbp benbp commented Sep 9, 2025

Making all the MCP tools injected via AddScoped instead of as singletons. This will allow us to inject other classes that can manage state for the request scope. In this PR the token usage helper is made scoped so that we can track agent token usage across the code for an entire request, and then later consume it from multiple places like our telemetry service (FYI @praveenkuttappan).

Also updating the backend foundry project endpoint for the agent service, since the legacy project has started breaking for API calls.

To play around with the scoped token usage helper, I added an example tool/cli command for the micro agent service which computes fibonacci.

Finally, this fixes an issue from last month where logs coming out of any Azure.Sdk.Tools.* namespace were not printed to console.

Copilot AI review requested due to automatic review settings September 9, 2025 19:57
@benbp benbp added the Central-EngSys This issue is owned by the Engineering System team. label Sep 9, 2025
@benbp benbp self-assigned this Sep 9, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR changes the AI project endpoint and default model for the agent service to use a different Azure OpenAI resource and upgrades to the newer "o3-mini" model.

  • Updates the default AI project endpoint to use azsdk-engsys-openai instead of azsdk-engsys-ai
  • Changes the default model from "gpt-4.1-mini" to "o3-mini"
  • Refactors token usage tracking to use a scoped service pattern with dependency injection

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
PipelineAnalysisTool.cs Updates to use injected TokenUsageHelper and removes manual token usage tracking
ExampleTool.cs Adds TokenUsageHelper injection and usage tracking for AI operations
ServiceRegistrations.cs Changes service registrations to scoped lifetime and adds TokenUsageHelper registration
AzureAgentServiceFactory.cs Updates factory to inject TokenUsageHelper into created services
AzureAgentService.cs Updates endpoint/model defaults and integrates TokenUsageHelper for usage tracking
Program.cs Minor code formatting improvements and logging filter adjustments
TokenUsageHelper.cs Complete refactor to use dependency injection and support multiple model pricing
ExampleToolTests.cs Updates test to provide required TokenUsageHelper dependency
MCPTool.cs Code formatting changes with no functional impact

@benbp benbp moved this from 🤔 Triage to 🔬 Dev in PR in Azure SDK EngSys 🚀🌒🧑‍🚀 Sep 9, 2025
@benbp benbp added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Sep 9, 2025
@benbp benbp changed the title Change ai project endpoint and default model for agent service Make token usage helper and mcp tools scoped Sep 9, 2025
Comment thread tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/TokenUsageHelper.cs Outdated
@benbp benbp force-pushed the benbp/azsdk-cli-scoped branch from 4234eed to d39d995 Compare September 10, 2025 21:26
@benbp benbp changed the title Make token usage helper and mcp tools scoped [azsdk-cli] Use scoped tools and helpers, add micro agent example Sep 10, 2025
}

[McpServerTool(Name = "azsdk_example_microagent_fibonacci"), Description("Demonstrates micro-agent computing Nth Fibonacci number via iterative tool calls")]
public async Task<DefaultCommandResponse> DemonstrateMicroagentFibonacci(int n, CancellationToken ct = default)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

FYI @timovv I added this example tool and cli command to run the micro agent service in case it's useful for ad-hoc testing.

azsdk example demo microagent --fibonacci 7

Copy link
Copy Markdown
Member

@praveenkuttappan praveenkuttappan left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@benbp benbp force-pushed the benbp/azsdk-cli-scoped branch from d39d995 to 14d2c88 Compare September 15, 2025 18:35
@benbp benbp merged commit 3cd7067 into Azure:main Sep 15, 2025
10 of 13 checks passed
@benbp benbp deleted the benbp/azsdk-cli-scoped branch September 15, 2025 18:45
@kurtzeborn kurtzeborn moved this from 🔬 Dev in PR to 🎊 Closed in Azure SDK EngSys 🚀🌒🧑‍🚀 Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli Central-EngSys This issue is owned by the Engineering System team.

Projects

Development

Successfully merging this pull request may close these issues.

5 participants