The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →In Microsoft Agent Framework, agent middleware wraps an agent run, while ChatClient middleware wraps calls to an IChatClient. Use agent middleware for run-wide behavior such as input/output handling or control flow; use ChatClient middleware when you need to inspect or change the messages, options, or response at the model-call boundary. For tool execution, use function-calling middleware.
Where each middleware layer sits
The distinction is the boundary being intercepted: the agent run as a whole, the chat-client call made during that run, or a function/tool invocation. Microsoft describes middleware handlers of the same type as a chain: a handler can call the next handler to continue processing.
As an Amazon Associate I earn from qualifying purchases.
| Layer | What it wraps | Best fit |
|---|---|---|
| Agent middleware | Agent execution, including run inputs, outputs, and control flow. | Behavior that should apply around the broader run. |
| ChatClient middleware | Requests and responses at an IChatClient boundary. |
Model-call logging or transforming messages, options, or responses. |
| Function-calling middleware | Function or tool calls made during agent execution. | Validating tool arguments, transforming results, or controlling tool execution. |
See Microsoft Learn’s Agent Middleware and Agent Pipeline Architecture documentation for the layer descriptions and examples.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsWhen to choose agent middleware
Choose agent middleware when a policy belongs to the run rather than to a particular model request. It can inspect or modify run inputs and outputs and participate in execution flow. That makes it suitable for run-level logging, validation, shared behavior, or changing the final result.
#1 Best Overall
Because it wraps the agent, this layer can apply across agent implementations where their supported behavior permits it. It is the more appropriate choice when the behavior should remain relevant even if the agent’s underlying model-client arrangement changes.
When to choose ChatClient middleware
Choose ChatClient middleware when the behavior needs access to the conversation messages or options sent to the model, or to the response returned by the client. In Microsoft’s documented C# example, the middleware receives messages and options, calls the inner client, and can inspect the response.
Rank #2
This is the natural place for model-call-level logging or transformations. It is narrower than agent middleware: it applies at the chat-client interaction, not automatically to every part of an agent run.
Recommended Free Tools
Check whether the agent uses an IChatClient
ChatClient middleware requires an IChatClient in the execution path. A ChatClientAgent uses an IChatClient, so its client can be decorated before it is supplied to the agent. Microsoft also documents specialized or remote agents that communicate with remote services instead of using a local IChatClient. Such an agent may still support agent middleware, but a ChatClient middleware layer cannot intercept a client call that does not occur.
Rank #3
Microsoft’s Agent concepts documentation describes the relationship between ChatClientAgent and IChatClient. Verify the actual agent path before choosing a client-level hook.
Keep tool policies at the tool boundary
If the policy concerns what a tool is asked to do or what it returns, function-calling middleware is the more specific layer. Use it to validate tool arguments, transform tool results, or control tool execution. Agent middleware can govern the broader run, but tool-specific behavior belongs at the function-calling boundary.
Rank #4
Middleware chains and language-specific examples
When several handlers of the same middleware type are registered, they form a chain. A handler that intends normal processing to continue should call the next handler; otherwise, it can stop or alter the flow. Consider ordering when handlers depend on each other—for example, whether validation should run before or after a transformation.
Free tools Windows power users keep installed
One-click scans. No signup required.
The registration APIs are language-specific. Microsoft’s middleware documentation provides separate C# and Python examples, so do not assume a snippet or registration surface transfers unchanged between .NET, Python, and Go. The documented responsibilities establish where each layer runs, not a universal latency or throughput advantage for either one.
Best Value
For broader cross-cutting patterns such as guardrails, exception handling, result overrides, shared state, and runtime context, see Microsoft Learn’s Adding Middleware guidance.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




