MiddlewareAgentTool
Models & Types · AiDotNet.Agentic.Pipeline
An IAgentTool decorator that runs a chain of IToolMiddleware around an inner
tool’s execution. Register the wrapped tool like any other and the agent loop applies the middleware
transparently whenever the model calls it — the composition root for tool approval, guardrails, logging,
and caching.
Implements: IAgentTool
For Beginners
Wrap a tool with this and a list of filters, and every time the model uses that tool the filters run first (approve it, log it, fix the inputs) — the model still sees the same tool.
How It Works
The tool’s identity (name, description, schema, definition) is delegated to the inner tool, so wrapping is invisible to the model — only execution is intercepted. Middleware run in registration order (first = outermost).
Constructors
| Constructor | Summary |
|---|---|
MiddlewareAgentTool(IAgentTool inner, IReadOnlyList<IToolMiddleware> middlewares) |
Initializes a new middleware tool decorator. |
Properties
| Property | Summary |
|---|---|
JObject ParametersSchema { get; } |
|
string Description { get; } |
|
string Name { get; } |
Methods
| Method | Summary |
|---|---|
AiToolDefinition ToDefinition() |
|
Task<ToolInvocationResult> InvokeAsync(JObject arguments, CancellationToken cancellationToken) |