mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
7a8b456294
* WIP * Wip * Updated ADR * Updated ADR * Update files * Address copilot comments * Update filters from Task<T> to Task only * Project endpoint * Add agent ctor filter * Other Agent Framework investigation * Remove SK Java, no support * Update LlamaIndex info * Removing unrelated files * Implementation with specialization * Remove the specialization option as extra unecessary complexity * Move middleware responsibility to a decorator * Update readme * Function invocation wip * Add Agent Builder * Adding comparison samples * Reorganize Samples and Processor vs Decorator * Remove merge files * Address formating warnigs * Update ADR * Step13 README's update * Address PR feedback * Address PR feedback * Remove configure await from ADR samples * Update variables * Address feedback * Address Agent level tool invocation with Options.ToolsTransformer strategy * Removing the Processor approach * Proposal design for Middleware in CreateAIAgent extensions * Examples clean up and consolitation * Update middlewares to work with ApprovalREquiredFunction * Clean-up sample * Update override function call sample * Drop configuration from the extensions, looks overkill * Builder interface .. * Revert IAIBuilder interface approach * Cleanup sample * Adding unit tests * Fix UT * Cleanup sample * Remove unneeded dependency * Address PR comment + Readme Samples * Add missing comments for Program.cs Middleware * Address mor PR comments + add client factory for OpenAI extensions * Add OpenAI UnitTests for extensions * Add AzureAI PersistentChatClient UT * Addess feedback * Add function invoking UT * Add builder extension UT * Address feedback + Rearange abstractions + UT fixes * Drop context based middleware for full decorating impl * Update unit tests * Update UT coverage * Removing Middelware namespace * Add missing UT * Remove internal ToolTransformation Property * Adjust xmldoc * Remove transient file * Address merge conflict * Add xmldoc remark for clarity * Address comment * Address feedback * Update UT --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
7a8b456294
·
2025-09-29 17:58:04 +00:00
History
Agent Middleware
This sample demonstrates how to add middleware to intercept:
- Chat client calls (global and per‑request)
- Agent runs (guardrails and PII filtering)
- Function calling (logging/override)
What This Sample Shows
- Azure OpenAI integration via
AzureOpenAIClientandAzureCliCredential - Chat client middleware using
ChatClientBuilder.Use(...) - Agent run middleware (PII redaction and wording guardrails)
- Function invocation middleware (logging and overriding a tool result)
- Per‑request chat client middleware
- Per‑request function pipeline with approval
- Combining agent‑level and per‑request middleware
Function Invocation Middleware
Not all agents support function invocation middleware.
Attempting to use function middleware on agents that do not wrap a ChatClientAgent or derives from it will throw an InvalidOperationException.
Prerequisites
- Environment variables:
AZUREOPENAI_ENDPOINT: Your Azure OpenAI endpointAZUREOPENAI_DEPLOYMENT_NAME: Chat deployment name (optional; defaults togpt-4o)
- Sign in with Azure CLI (PowerShell):
az login
Running the Sample
Use PowerShell:
cd dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware
dotnet run