Skip to content

fix(dotnet): preserve Context and ForwardedProperties from caller-supplied RunAgentInput#2164

Closed
NathanTarbert wants to merge 1 commit into
mainfrom
fix/dotnet-preserve-context-forwarded-properties
Closed

fix(dotnet): preserve Context and ForwardedProperties from caller-supplied RunAgentInput#2164
NathanTarbert wants to merge 1 commit into
mainfrom
fix/dotnet-preserve-context-forwarded-properties

Conversation

@NathanTarbert

Copy link
Copy Markdown
Contributor

Fixes #2151

Problem

When a caller seeds the outgoing request with a RunAgentInput via ChatOptions.RawRepresentationFactory, AGUIChatClient.BuildRunAgentInput copies Messages, Tools, State, and ParentRunId from that input — but never copies Context or ForwardedProperties. Both fields are silently dropped, even though they are part of the same RunAgentInput and are documented as caller-supplied run parameters.

var providedInput = new RunAgentInput
{
    Context = new List<AGUIContext> { new() { Description = "userId", Value = "u-123" } }
};
var options = new ChatOptions { RawRepresentationFactory = _ => providedInput };
await chatClient.GetStreamingResponseAsync(messages, options, ct);
// Expected: outgoing RunAgentInput.Context contains the userId entry
// Actual:   Context is null/empty over the wire — the entry is lost

Affects AGUI.Client / AGUI.Abstractions 0.0.3.

Fix

In BuildRunAgentInput, carry both fields through with the same guarded treatment as the existing fields:

if (providedInput.Context is { Count: > 0 })
{
    input.Context = providedInput.Context;
}

if (providedInput.ForwardedProperties.ValueKind is not JsonValueKind.Undefined)
{
    input.ForwardedProperties = providedInput.ForwardedProperties;
}

ForwardedProperties is a JsonElement value type whose default is ValueKind == Undefined, so the guard copies it only when the caller actually set it.

Tests

  • Added GetStreamingResponse_WithRawRepresentationFactory_PreservesContextAndForwardedProperties (uses the existing CapturingTransport to assert both fields reach the sent RunAgentInput).
  • TDD-verified: the test fails against the unpatched BuildRunAgentInput (Context is null) and passes with the fix.
  • Full AGUI.Client.UnitTests suite green (111 passed, net10.0).

…plied RunAgentInput

AGUIChatClient.BuildRunAgentInput copied Messages, Tools, State, and ParentRunId
from a RunAgentInput supplied via ChatOptions.RawRepresentationFactory, but never
copied Context or ForwardedProperties. Both were silently dropped from the request
sent over the wire, even though they are documented caller-supplied run parameters.

Carry both through with the same guarded treatment as the other fields: copy
Context when non-empty, and ForwardedProperties when the caller set it (ValueKind
is not Undefined).

Fixes #2151
@NathanTarbert
NathanTarbert requested a review from a team as a code owner July 11, 2026 21:37
@github-actions

Copy link
Copy Markdown
Contributor

Python Preview Packages

Version 0.0.0.dev1783805828 published to TestPyPI.

Warning: These packages are built from contributor code that may not yet have been vetted for correctness or security. Install at your own risk and do not use in production.

Install with uv

Add the TestPyPI index to your pyproject.toml:

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
explicit = true

Then install the packages you need:

# Core SDK
uv add 'ag-ui-protocol==0.0.0.dev1783805828' --index testpypi

# Integrations (each already depends on the matching ag-ui-protocol preview)
uv add 'ag-ui-langgraph==0.0.0.dev1783805828' --index testpypi
uv add 'ag-ui-crewai==0.0.0.dev1783805828' --index testpypi
# NOTE: ag-ui-agent-spec depends on pyagentspec (git-only, not on PyPI).
# You will need to install pyagentspec separately from its git repo.
uv add 'ag-ui-agent-spec==0.0.0.dev1783805828' --index testpypi
uv add 'ag_ui_adk==0.0.0.dev1783805828' --index testpypi
uv add 'ag_ui_strands==0.0.0.dev1783805828' --index testpypi

Install with pip

pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  ag-ui-protocol==0.0.0.dev1783805828

Use --extra-index-url https://pypi.org/simple/ so pip can resolve
transitive dependencies (pydantic, fastapi, etc.) from real PyPI.


Commit: 5427afd

@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ag-ui/a2a-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a-middleware@2164

@ag-ui/a2ui-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-middleware@2164

@ag-ui/event-throttle-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/event-throttle-middleware@2164

@ag-ui/mcp-apps-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-apps-middleware@2164

@ag-ui/mcp-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-middleware@2164

@ag-ui/a2a

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a@2164

@ag-ui/adk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/adk@2164

@ag-ui/ag2

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/ag2@2164

@ag-ui/agno

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/agno@2164

@ag-ui/aws-strands

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/aws-strands@2164

@ag-ui/claude-agent-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/claude-agent-sdk@2164

@ag-ui/crewai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/crewai@2164

@ag-ui/langchain

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langchain@2164

@ag-ui/langgraph

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langgraph@2164

@ag-ui/llamaindex

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/llamaindex@2164

@ag-ui/mastra

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mastra@2164

@ag-ui/pydantic-ai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/pydantic-ai@2164

@ag-ui/vercel-ai-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/vercel-ai-sdk@2164

@ag-ui/watsonx

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/watsonx@2164

@ag-ui/a2ui-toolkit

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-toolkit@2164

create-ag-ui-app

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/create-ag-ui-app@2164

@ag-ui/client

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/client@2164

@ag-ui/core

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/core@2164

@ag-ui/encoder

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/encoder@2164

@ag-ui/proto

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/proto@2164

commit: 1bf55fe

@javiercn

Copy link
Copy Markdown
Contributor

LGTM

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Thanks so much for this, @NathanTarbert — and apologies again for the duplicate; you spotted the Context/ForwardedProperties drop first here.

That fix has now landed via #2177 (merged in 828e444), which used the same guarded pattern as yours and additionally forwards Resume (also dropped from a caller-supplied RunAgentInput) plus a fix for a related approval/interrupt asymmetry that surfaced in review.

Since #2177 is the superset, I'm closing this as a duplicate — but the credit for catching the original issue is yours. Really appreciate the contribution. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AGUIChatClient.BuildRunAgentInput drops RunAgentInput.Context (and ForwardedProperties) from a caller-supplied RawRepresentationFactory input

3 participants