Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sdks/dotnet/src/AGUI.Client/AGUIChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ private static RunAgentInput BuildRunAgentInput(
{
input.ParentRunId = providedInput.ParentRunId;
}

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

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

// Convert M.E.AI tools to AG-UI format
Expand Down
38 changes: 38 additions & 0 deletions sdks/dotnet/tests/AGUI.Client.UnitTests/AGUIChatClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using AGUI.Abstractions;
Expand Down Expand Up @@ -143,6 +144,43 @@ public async Task GetStreamingResponse_SendsFullHistoryEveryTurn()
Assert.Equal(3, transport.LastInput!.Messages.Count);
}

// https://github.com/ag-ui-protocol/ag-ui/issues/2151
// A caller-supplied RunAgentInput (via RawRepresentationFactory) must have its
// Context and ForwardedProperties carried through onto the request that is sent,
// just like Messages/Tools/State/ParentRunId already are.
[Fact]
public async Task GetStreamingResponse_WithRawRepresentationFactory_PreservesContextAndForwardedProperties()
{
var transport = new CapturingTransport();
using var client = new AGUIChatClient(new() { Transport = transport });

var forwarded = JsonDocument.Parse("{\"tenant\":\"acme\"}").RootElement.Clone();
var options = new ChatOptions
{
RawRepresentationFactory = _ => new RunAgentInput
{
Context = new List<AGUIContext>
{
new() { Description = "userId", Value = "u-123" }
},
ForwardedProperties = forwarded,
}
};

await DrainAsync(client.GetStreamingResponseAsync(
[new ChatMessage(ChatRole.User, "Hello")], options));

var sent = transport.LastInput!;

Assert.NotNull(sent.Context);
Assert.Single(sent.Context!);
Assert.Equal("userId", sent.Context![0].Description);
Assert.Equal("u-123", sent.Context[0].Value);

Assert.Equal(JsonValueKind.Object, sent.ForwardedProperties.ValueKind);
Assert.Equal("acme", sent.ForwardedProperties.GetProperty("tenant").GetString());
}

// https://github.com/microsoft/agent-framework/issues/5587
[Fact]
public async Task AGUIChatClient_ToolCallResultWithPlainTextContent_DoesNotParseAsJson()
Expand Down
Loading