From dfb4f69c3bd08826a17747c3590827b87917a761 Mon Sep 17 00:00:00 2001 From: Jesse Liberty Date: Sat, 8 Aug 2026 13:56:09 -0400 Subject: [PATCH] Add agent middleware to track calls to tavily --- ResearcherAgent.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ResearcherAgent.cs b/ResearcherAgent.cs index eda3a41..bc86bf7 100644 --- a/ResearcherAgent.cs +++ b/ResearcherAgent.cs @@ -50,6 +50,20 @@ public ResearcherAgent(IChatClient llm, ChatOptions chatOptions, AIFunction tavi }, }) .AsBuilder() + // Function-invocation middleware: fires around every tool call the agent + // makes. We log each time the model invokes the Tavily search tool. + .Use(async (agent, context, next, cancellationToken) => + { + if (context.Function.Name == tavilyTool.Name) + { + _logger.LogInformation( + "Researcher invoking Tavily tool '{Tool}' with arguments {Arguments}", + context.Function.Name, + context.Arguments); + } + + return await next(context, cancellationToken); + }) .UseOpenTelemetry(sourceName: "BlogWriter.Agents") .Build();