Skip to content

Commit 7cd6df8

Browse files
authored
Merge pull request #787 from MicrosoftDocs/fix-middleware-docs
Improve middleware docs + address MAF issue 2374
2 parents ee0cec7 + 0417cf4 commit 7cd6df8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

agent-framework/user-guide/agents/agent-middleware.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ Agent run and function calling middleware types can be registered on an agent, b
2929
```csharp
3030
var middlewareEnabledAgent = originalAgent
3131
.AsBuilder()
32-
.Use(CustomAgentRunMiddleware)
32+
.Use(runFunc: CustomAgentRunMiddleware, runStreamingFunc: null)
3333
.Use(CustomFunctionCallingMiddleware)
3434
.Build();
3535
```
3636

37+
> [!IMPORTANT]
38+
> Ideally both `runFunc` and `runStreamingFunc` should be provided, when providing just the non-streaming middleware, the agent will use it for both streaming and non-streaming invocations and this will block the streaming to run in non-streaming mode to suffice the middleware expectations.
39+
40+
> [!NOTE]
41+
> There's an additional overload `Use(sharedFunc: ...)` that allows you to provide the same middleware for non-streaming and streaming without blocking the streaming, however, the shared middleware won't be able intercept or override the output, make this the best option only for scenarios where you only need to inspect/modify the input before it reaches the agent.
42+
3743
`IChatClient` middleware can be registered on an `IChatClient` before it is used with a `ChatClientAgent`, by using the chat client builder pattern.
3844

3945
```csharp

0 commit comments

Comments
 (0)