Class MiddlewareExtension
public static class MiddlewareExtension
- Inheritance
-
MiddlewareExtension
- Inherited Members
Methods
RegisterMiddleware<TAgent>(MiddlewareAgent<TAgent>, IMiddleware)
Register a middleware to an existing agent and return a new agent with the middleware. To register a streaming middleware, use RegisterStreamingMiddleware<TAgent>(MiddlewareStreamingAgent<TAgent>, IStreamingMiddleware).
public static MiddlewareAgent<TAgent> RegisterMiddleware<TAgent>(this MiddlewareAgent<TAgent> agent, IMiddleware middleware) where TAgent : IAgent
Parameters
agent
MiddlewareAgent<TAgent>middleware
IMiddleware
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
RegisterMiddleware<TAgent>(MiddlewareAgent<TAgent>, Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>>, string?)
Register a middleware to an existing agent and return a new agent with the middleware. To register a streaming middleware, use RegisterStreamingMiddleware<TAgent>(MiddlewareStreamingAgent<TAgent>, IStreamingMiddleware).
public static MiddlewareAgent<TAgent> RegisterMiddleware<TAgent>(this MiddlewareAgent<TAgent> agent, Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>> func, string? middlewareName = null) where TAgent : IAgent
Parameters
agent
MiddlewareAgent<TAgent>func
Func<IEnumerable<IMessage>, GenerateReplyOptions, IAgent, CancellationToken, Task<IMessage>>middlewareName
string
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
RegisterMiddleware<TAgent>(TAgent, IMiddleware)
Register a middleware to an existing agent and return a new agent with the middleware. To register a streaming middleware, use RegisterStreamingMiddleware<TAgent>(MiddlewareStreamingAgent<TAgent>, IStreamingMiddleware).
public static MiddlewareAgent<TAgent> RegisterMiddleware<TAgent>(this TAgent agent, IMiddleware middleware) where TAgent : IAgent
Parameters
agent
TAgentmiddleware
IMiddleware
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
RegisterMiddleware<TAgent>(TAgent, Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>>, string?)
Register a middleware to an existing agent and return a new agent with the middleware. To register a streaming middleware, use RegisterStreamingMiddleware<TAgent>(MiddlewareStreamingAgent<TAgent>, IStreamingMiddleware).
public static MiddlewareAgent<TAgent> RegisterMiddleware<TAgent>(this TAgent agent, Func<IEnumerable<IMessage>, GenerateReplyOptions?, IAgent, CancellationToken, Task<IMessage>> func, string? middlewareName = null) where TAgent : IAgent
Parameters
agent
TAgentfunc
Func<IEnumerable<IMessage>, GenerateReplyOptions, IAgent, CancellationToken, Task<IMessage>>middlewareName
string
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
RegisterPostProcess<TAgent>(TAgent, Func<IEnumerable<IMessage>, IMessage, CancellationToken, Task<IMessage>>)
Register a post process hook to an agent. The hook will be called before the agent return the reply and after the agent generate the reply. This is useful when you want to customize arbitrary behavior before the agent return the reply.
One example is RegisterPrintMessage<TAgent>(TAgent), which print the formatted message to console before the agent return the reply.
[Obsolete("Use RegisterMiddleware instead.")]
public static MiddlewareAgent<TAgent> RegisterPostProcess<TAgent>(this TAgent agent, Func<IEnumerable<IMessage>, IMessage, CancellationToken, Task<IMessage>> postprocessFunc) where TAgent : IAgent
Parameters
agent
TAgentpostprocessFunc
Func<IEnumerable<IMessage>, IMessage, CancellationToken, Task<IMessage>>
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
Exceptions
- Exception
throw when agent name is null.
RegisterPreProcess<TAgent>(TAgent, Func<IEnumerable<IMessage>, CancellationToken, Task<IEnumerable<IMessage>>>)
Register a pre process hook to an agent. The hook will be called before the agent generate the reply. This is useful when you want to modify the conversation history before the agent generate the reply.
[Obsolete("Use RegisterMiddleware instead.")]
public static MiddlewareAgent<TAgent> RegisterPreProcess<TAgent>(this TAgent agent, Func<IEnumerable<IMessage>, CancellationToken, Task<IEnumerable<IMessage>>> preprocessFunc) where TAgent : IAgent
Parameters
agent
TAgentpreprocessFunc
Func<IEnumerable<IMessage>, CancellationToken, Task<IEnumerable<IMessage>>>
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
Exceptions
- Exception
throw when agent name is null.
RegisterReply<TAgent>(TAgent, Func<IEnumerable<IMessage>, CancellationToken, Task<IMessage?>>)
Register a auto reply hook to an agent. The hook will be called before the agent generate the reply. If the hook return a non-null reply, then that non-null reply will be returned directly without calling the agent. Otherwise, the agent will generate the reply. This is useful when you want to override the agent reply in some cases.
[Obsolete("Use RegisterMiddleware instead.")]
public static MiddlewareAgent<TAgent> RegisterReply<TAgent>(this TAgent agent, Func<IEnumerable<IMessage>, CancellationToken, Task<IMessage?>> replyFunc) where TAgent : IAgent
Parameters
agent
TAgentreplyFunc
Func<IEnumerable<IMessage>, CancellationToken, Task<IMessage>>
Returns
- MiddlewareAgent<TAgent>
Type Parameters
TAgent
Exceptions
- Exception
throw when agent name is null.