microsoft / microsoft/agent-framework

.NET: Provide typed access to RunAgentInput.State in .NET AG-UI

Open
#8,359 0 comments 0 reactions 1 assignee View on GitHub

@javiercn is already working on this.

Since Sep 18, 2026.

.NET ag-ui hosting
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

Description

Accessing AG-UI client state currently requires recovering RunAgentInput from ChatOptions, inspecting its JsonElement, and deserializing it manually:

if (chatOptions.TryGetRunAgentInput(out RunAgentInput? input) &&
    input.State is { ValueKind: JsonValueKind.Object } state)
{
    var value = state.Deserialize(
        AppJsonSerializerContext.Default.DocumentState);
}

Provide a typed convenience API:

if (chatOptions.TryGetRunAgentState(
    AppJsonSerializerContext.Default.DocumentState,
    out DocumentState? state))
{
    Validate(state);
}

Proposed signature:

public static bool TryGetRunAgentState<T>(
    this ChatOptions options,
    JsonTypeInfo<T> jsonTypeInfo,
    out T? state);

The method should return false when no state was supplied and throw a clear deserialization exception for malformed state. Requiring JsonTypeInfo<T> keeps the API AOT-safe.

Client state remains untrusted. The application is responsible for validation and deciding whether to use it in tools or model context. This is narrower than #7745 and does not integrate client state with AgentSession.StateBag.

Code Sample
if (chatOptions.TryGetRunAgentState(
    AppJsonSerializerContext.Default.DocumentState,
    out DocumentState? state))
{
    Validate(state);
}
Language/SDK

.NET

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.