Skip to content
Merged
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: 5 additions & 5 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
<PackageVersion Include="System.Net.Http.Json" Version="10.0.0" />
<PackageVersion Include="System.Net.ServerSentEvents" Version="10.0.8" />
<!-- AG-UI .NET SDK packages (published by the AG-UI team). -->
<PackageVersion Include="AGUI.Abstractions" Version="0.0.4" />
<PackageVersion Include="AGUI.Formatting" Version="0.0.4" />
<PackageVersion Include="AGUI.Protobuf" Version="0.0.4" />
<PackageVersion Include="AGUI.Client" Version="0.0.4" />
<PackageVersion Include="AGUI.Server" Version="0.0.4" />
<PackageVersion Include="AGUI.Abstractions" Version="0.0.5" />
<PackageVersion Include="AGUI.Formatting" Version="0.0.5" />
<PackageVersion Include="AGUI.Protobuf" Version="0.0.5" />
<PackageVersion Include="AGUI.Client" Version="0.0.5" />
Comment thread
javiercn marked this conversation as resolved.
<PackageVersion Include="AGUI.Server" Version="0.0.5" />
<PackageVersion Include="System.Text.Json" Version="10.0.11" />
<PackageVersion Include="System.Threading.Channels" Version="10.0.11" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading;
using System.Threading.Tasks;
using AGUI.Abstractions;
using AGUI.Client;
using AGUI.Server;
using FluentAssertions;
using Microsoft.AspNetCore.Builder;
Expand All @@ -28,6 +29,37 @@ public sealed class ForwardedPropertiesTests : IAsyncDisposable
private WebApplication? _app;
private HttpClient? _client;

[Fact]
public async Task ChatClient_ForwardsContextAndForwardedPropsFromRawRepresentationFactoryAsync()
{
// Arrange
FakeForwardedPropsAgent fakeAgent = new();
await this.SetupTestServerAsync(fakeAgent);
var chatClient = new AGUIChatClient(new(this._client!, "/agent"));
JsonElement forwardedProperties = JsonSerializer.SerializeToElement(new { tenantId = "tenant-123" });
ChatOptions options = new()
{
RawRepresentationFactory = _ => new RunAgentInput
{
Context = [new AGUIContext { Description = "Current user", Value = "Ada Lovelace" }],
ForwardedProperties = forwardedProperties,
Comment on lines +44 to +45

@westey-m westey (westey-m) Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise this is just a regression test, so take my comment as a separate suggestion related to this approach, but not this PR.

For A2A we propagate the AdditionalProperties dictionary (where serializable) to the service via the A2A metadata field. So on the client side the A2A Agent converts it to metadata while on the host side it converts the metadata back into additional properties and passes that into the remote agent.

This is quite nice in that it allows a user to pass a value all the way down the stack, and even access it in tool calls on the service side, if the service has an AF agent with MEAI FICC.

Not sure if either of these properties match this concept (perhaps forwarded properties?), but it could be a nice way of integrating well with the abstractions.

// client side:
await agent.RunAsync(
    "Do something.",
    session,
    options: new() { AdditionalProperties = new() { { "tenantId", "tenant-123" } } });

// since additional properties is propagated service side and down to the chat client stack from the MAF agent, we can then do this inside a server side tool:
FunctionInvokingChatClient
    .CurrentContext
    .Options
    .AdditionalProperties
    .TryGetValue("tenantId", out string tenantId);

},
};

// Act
await foreach (ChatResponseUpdate _ in chatClient.GetStreamingResponseAsync(
[new ChatMessage(ChatRole.User, "test client forwarding")],
options))
{
}

// Assert
fakeAgent.ReceivedContext.Should().ContainSingle();
fakeAgent.ReceivedContext![0].Description.Should().Be("Current user");
fakeAgent.ReceivedContext[0].Value.Should().Be("Ada Lovelace");
fakeAgent.ReceivedForwardedProperties.GetProperty("tenantId").GetString().Should().Be("tenant-123");
}

[Fact]
public async Task ForwardedProps_AreParsedAndPassedToAgent_WhenProvidedInRequestAsync()
{
Expand Down Expand Up @@ -304,6 +336,8 @@ public FakeForwardedPropsAgent()

public override string? Description => "Agent for forwarded properties testing";

public IList<AGUIContext>? ReceivedContext { get; private set; }

public JsonElement ReceivedForwardedProperties { get; private set; }

protected override Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
Expand All @@ -319,10 +353,14 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
{
// Recover the originating AG-UI input from the request options (set by the hosting layer).
if (options is ChatClientAgentRunOptions { ChatOptions: { } chatOptions } &&
chatOptions.TryGetRunAgentInput(out RunAgentInput? agentInput) &&
agentInput.ForwardedProperties is { ValueKind: not JsonValueKind.Undefined } forwardedProps)
chatOptions.TryGetRunAgentInput(out RunAgentInput? agentInput))
{
this.ReceivedForwardedProperties = forwardedProps;
this.ReceivedContext = agentInput.Context;

if (agentInput.ForwardedProperties is { ValueKind: not JsonValueKind.Undefined } forwardedProps)
{
this.ReceivedForwardedProperties = forwardedProps;
}
}

// Always return a text response
Expand Down
Loading