Class MiddlewareAgent
An agent that allows you to add middleware and modify the behavior of an existing agent.
- Inheritance
-
Middleware
Agent
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
MiddlewareAgent(IAgent, string?, IEnumerable<IMiddleware>?)
Create a new instance of Middleware
public MiddlewareAgent(IAgent innerAgent, string? name = null, IEnumerable<IMiddleware>? middlewares = null)
Parameters
innerAgent
IAgentthe inner agent where middleware will be added.
name
stringthe name of the agent if provided. Otherwise, the name of
innerAgent
will be used.middlewares
IEnumerable<IMiddleware>
MiddlewareAgent(MiddlewareAgent)
Create a new instance of Middleware
Parameters
other
MiddlewareAgent
Properties
Agent
Get the inner agent.
Property Value
Middlewares
Get the middlewares.
Property Value
Name
Property Value
Methods
GenerateReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
Generate reply
public Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages
IEnumerable<IMessage>conversation history
options
GenerateReply Options completion option. If provided, it should override existing option if there's any
cancellationToken
CancellationToken
Returns
ToString()
Returns
Use(IMiddleware)
Use middleware.
Parameters
middleware
IMiddleware
Use(Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>>, string?)
Add a middleware to the agent. If multiple middlewares are added, they will be executed in the LIFO order. Call into the next function to continue the execution of the next middleware. Short cut middleware execution by not calling into the next function.
public void Use(Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>> func, string? middlewareName = null)
Parameters
func
Func<IEnumerable<IMessage>, GenerateReply , IAgent, CancellationOptions Token , Task<IMessage>>middlewareName
string