Skip to content

.NET: Support for intermediate state from Tools for AG-UI #2081

@anktsrkr

Description

@anktsrkr

Hi,
I am trying to build Deep Research Agent using AGUI and CopilotKit. I would like to do below steps -

  1. Break the objective into 3-4 short steps for the UI to display
Image

This is working using useCoAgentStateRender with DelegatingAIAgent as above.

  1. For Each Steps It will call perform_research tool. <-- 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_CONTENT so not invoking useCoAgentStateRender and 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

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions