Repository navigation
Closed
Labels
.NETUsage: [Issues, PRs], Target: .NetUsage: [Issues, PRs], Target: .Netag-uiUsage: [Issues, PRs], Target: AG-UI protocol integrationUsage: [Issues, PRs], Target: AG-UI protocol integrationquestionUsage: [Issues, PRs], Target: all issues or PRs where additional context is needed from the authorUsage: [Issues, PRs], Target: all issues or PRs where additional context is needed from the author
Description
Hi,
I am trying to build Deep Research Agent using AGUI and CopilotKit. I would like to do below steps -
- Break the objective into 3-4 short steps for the UI to display
This is working using useCoAgentStateRender with DelegatingAIAgent as above.
- For Each Steps It will call
perform_researchtool. <-- This steps also works fine. Here is my tool definition -
[Description("Perform a research task and track progress.")]
static async IAsyncEnumerable<AgentRunResponseUpdate> PerformResearch([Description("The research query")] string query)
{
var agentState = new AgentStateSnapshot { Searches = [] };
agentState.Searches.Add(new SearchInfo { Query = query, Status= "InProgress"});
byte[] stateBytes = JsonSerializer.SerializeToUtf8Bytes(
agentState);
// Emit state snapshot as DataContent
yield return new AgentRunResponseUpdate
{
Contents = [new DataContent(stateBytes, "application/json")]
};
// Simulate initial research phase
var research_content = $" Research Overview: Actual content......";
agentState.Searches.Add(new SearchInfo { Query = query, Status= "Done" });
stateBytes = JsonSerializer.SerializeToUtf8Bytes(
agentState);
yield return new AgentRunResponseUpdate
{
Contents = [new DataContent(stateBytes, "application/json")]
};
yield return new AgentRunResponseUpdate
{
Contents = [new TextContent(research_content)]
};
}
Above snippet has few problem
- Unable to access existing state
- all three outputs are returning together at once it seems
- all three outputs are returning as
TEXT_MESSAGE_CONTENTso not invokinguseCoAgentStateRenderand it is getting treated as Tool's actual output.
My question -
- How do I get existing Agent State in Tool?
- How do I return intermediate state seperatly.
- How do I stream these intermediate state as
STATE_SNAPSHOT
Metadata
Metadata
Assignees
Labels
.NETUsage: [Issues, PRs], Target: .NetUsage: [Issues, PRs], Target: .Netag-uiUsage: [Issues, PRs], Target: AG-UI protocol integrationUsage: [Issues, PRs], Target: AG-UI protocol integrationquestionUsage: [Issues, PRs], Target: all issues or PRs where additional context is needed from the authorUsage: [Issues, PRs], Target: all issues or PRs where additional context is needed from the author
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][.NET] Support for intermediate state from Tools for AG-UI[/-][+].NET: [.NET] Support for intermediate state from Tools for AG-UI[/+][-].NET: [.NET] Support for intermediate state from Tools for AG-UI[/-][+].NET: Support for intermediate state from Tools for AG-UI[/+]anktsrkr commentedon Nov 11, 2025
Instead of above, I can think of
CustomFunctionCallingMiddlewarebut seems we cant yield theAgentRunResponseUpdatefrom it.Any suggestion on this Javier Calvarro Nelson (@javiercn) ?
javiercn commentedon Nov 12, 2025
Ankit Sarkar (@anktsrkr) thanks for contacting us.
In general, you need to decorate the agent to do these things. We will have more demos coming soon, but I'll try to give you some pointers.
Since the state is sent on every turn, there are a couple of ways I can think of doing this. You can get the state on RunStreamingAsync from the chat options, create new chat options and add a tool instance to the options that contains the state.
Typically, you can't do this from tool calls. the pattern in AG-UI is that you define additional tool definitions that map tool invocations to state updates, and then you convert those tool calls into state snapshots/deltas before sending them to the client. We will have a sample for this pattern in the following days. I'll update this issue when that's available.
https://github.com/microsoft/agent-framework/blob/main/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedStateAgent.cs shows how to access the state from AG-UI and how to emit it.
Let me know if this helps or you need more assistance.
markwallace-microsoft commentedon Mar 20, 2026
Ankit Sarkar (@anktsrkr), friendly reminder — this issue is waiting on your response. Please share any updates when you get a chance. (This is an automated message.)
javiercn commentedon Aug 18, 2026
I took another look at this. An
AIFunctionstill produces one final tool result, but a delegating agent can surface intermediate updates while the function is executing by using a per-run channel.The delegating agent creates the function for that run. Its lambda captures both the current AG-UI state and the channel writer, so no ambient context or
AdditionalPropertiesplumbing is needed:The delegating agent then pumps the inner-agent stream into the same channel and yields the combined stream:
CreateStateSnapshotwraps the state as an AG-UI event:This allows the channel updates to pass through while the inner agent is blocked waiting for the tool’s final result.