microsoft / microsoft/agent-framework
.NET: Provide typed access to RunAgentInput.State in .NET AG-UI
@javiercn is already working on this.
Since Sep 18, 2026.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.