Skip to content

Commit 798591c

Browse files
committed
feat(dotnet): add subagent events and attribution to AGUI.Abstractions
Part of PNI-196. Brings the .NET wire format to parity with TypeScript: SubagentStartedEvent, SubagentFinishedEvent and SubagentErrorEvent, plus `subagentId` on every event type the design makes attributable, wired through the polymorphic event converter, the source-generated serializer context, and the message model. Deliberate choices: - The three required lifecycle properties are declared nullable and rejected only when MISSING, not when empty. An earlier pass rejected empty strings too, which made .NET stricter than the zod schemas and would have had the two SDKs disagree on whether a stream is valid. Where the schemas differ, the schemas win. - `subagentId` travels on ChatMessage.AdditionalProperties under "agui.subagentId" so attribution survives a round trip through Microsoft.Extensions.AI types, which have no field for it. - PublicAPI.Unshipped.txt is appended to in place rather than re-sorted. The analyzer accepts either, but re-sorting turned 83 new entries into a 611-line diff that buried them. Known limitation, with a test pinning it: parallel tool calls owned by DIFFERENT subagents keep only the first owner, because AsChatMessages merges a parallel-call run into one ChatMessage and one message holds one attribution. Splitting the run by owner was implemented and reverted — it split without reordering the results and so produced the exact shape OpenAI rejects (microsoft/agent-framework#2699). The provider constraint is adjacency, not grouping, so interleaving would satisfy it AND keep both owners; that changes reconstruction for non-subagent parallel calls too, so it is a deliberate decision rather than a drive-by fix here. PNI-293 carries the analysis; the pinning test should be replaced if it lands.
1 parent 1647e7f commit 798591c

33 files changed

Lines changed: 857 additions & 12 deletions

‎sdks/dotnet/src/AGUI.Abstractions/Events/AGUIEventTypes.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ public static class AGUIEventTypes
3232
public const string Custom = "CUSTOM";
3333
public const string Raw = "RAW";
3434
public const string MessagesSnapshot = "MESSAGES_SNAPSHOT";
35+
public const string SubagentStarted = "SUBAGENT_STARTED";
36+
public const string SubagentFinished = "SUBAGENT_FINISHED";
37+
public const string SubagentError = "SUBAGENT_ERROR";
3538
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ActivityDeltaEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public sealed class ActivityDeltaEvent : BaseEvent
3030
/// </summary>
3131
[JsonPropertyName("patch")]
3232
public JsonElement Patch { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets the subagent that produced this event, absent when the parent agent
36+
/// produced it directly.
37+
/// </summary>
38+
[JsonPropertyName("subagentId")]
39+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
40+
public string? SubagentId { get; set; }
3341
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ActivitySnapshotEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public sealed class ActivitySnapshotEvent : BaseEvent
3737
[JsonPropertyName("replace")]
3838
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
3939
public bool? Replace { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the subagent that produced this event, absent when the parent agent
43+
/// produced it directly.
44+
/// </summary>
45+
[JsonPropertyName("subagentId")]
46+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
47+
public string? SubagentId { get; set; }
4048
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/BaseEventJsonConverter.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public override BaseEvent Read(ref Utf8JsonReader reader, Type typeToConvert, Js
5151
AGUIEventTypes.Custom => jsonElement.Deserialize(options.GetTypeInfo(typeof(CustomEvent))) as CustomEvent,
5252
AGUIEventTypes.Raw => jsonElement.Deserialize(options.GetTypeInfo(typeof(RawEvent))) as RawEvent,
5353
AGUIEventTypes.MessagesSnapshot => jsonElement.Deserialize(options.GetTypeInfo(typeof(MessagesSnapshotEvent))) as MessagesSnapshotEvent,
54+
AGUIEventTypes.SubagentStarted => jsonElement.Deserialize(options.GetTypeInfo(typeof(SubagentStartedEvent))) as SubagentStartedEvent,
55+
AGUIEventTypes.SubagentFinished => jsonElement.Deserialize(options.GetTypeInfo(typeof(SubagentFinishedEvent))) as SubagentFinishedEvent,
56+
AGUIEventTypes.SubagentError => jsonElement.Deserialize(options.GetTypeInfo(typeof(SubagentErrorEvent))) as SubagentErrorEvent,
5457
_ => throw new JsonException($"Unknown BaseEvent type discriminator: '{discriminator}'")
5558
};
5659

@@ -144,6 +147,15 @@ public override void Write(Utf8JsonWriter writer, BaseEvent value, JsonSerialize
144147
case MessagesSnapshotEvent messagesSnapshot:
145148
JsonSerializer.Serialize(writer, messagesSnapshot, options.GetTypeInfo(typeof(MessagesSnapshotEvent)));
146149
break;
150+
case SubagentStartedEvent subagentStarted:
151+
JsonSerializer.Serialize(writer, subagentStarted, options.GetTypeInfo(typeof(SubagentStartedEvent)));
152+
break;
153+
case SubagentFinishedEvent subagentFinished:
154+
JsonSerializer.Serialize(writer, subagentFinished, options.GetTypeInfo(typeof(SubagentFinishedEvent)));
155+
break;
156+
case SubagentErrorEvent subagentError:
157+
JsonSerializer.Serialize(writer, subagentError, options.GetTypeInfo(typeof(SubagentErrorEvent)));
158+
break;
147159
default:
148160
throw new InvalidOperationException($"Unknown event type: {value.GetType().Name}");
149161
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/CustomEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ public sealed class CustomEvent : BaseEvent
2525
[JsonPropertyName("value")]
2626
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2727
public JsonElement? Value { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the subagent that produced this event, absent when the parent agent
31+
/// produced it directly.
32+
/// </summary>
33+
[JsonPropertyName("subagentId")]
34+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35+
public string? SubagentId { get; set; }
2836
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/RawEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ public sealed class RawEvent : BaseEvent
2525
[JsonPropertyName("source")]
2626
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2727
public string? Source { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the subagent that produced this event, absent when the parent agent
31+
/// produced it directly.
32+
/// </summary>
33+
[JsonPropertyName("subagentId")]
34+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35+
public string? SubagentId { get; set; }
2836
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ReasoningEncryptedValueEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public sealed class ReasoningEncryptedValueEvent : BaseEvent
2929
/// </summary>
3030
[JsonPropertyName("encryptedValue")]
3131
public string EncryptedValue { get; set; } = string.Empty;
32+
33+
/// <summary>
34+
/// Gets or sets the subagent that produced this event, absent when the parent agent
35+
/// produced it directly.
36+
/// </summary>
37+
[JsonPropertyName("subagentId")]
38+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
39+
public string? SubagentId { get; set; }
3240
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ReasoningEndEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ public sealed class ReasoningEndEvent : BaseEvent
1717
/// </summary>
1818
[JsonPropertyName("messageId")]
1919
public string MessageId { get; set; } = string.Empty;
20+
21+
/// <summary>
22+
/// Gets or sets the subagent that produced this event, absent when the parent agent
23+
/// produced it directly.
24+
/// </summary>
25+
[JsonPropertyName("subagentId")]
26+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
27+
public string? SubagentId { get; set; }
2028
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ReasoningMessageChunkEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ public sealed class ReasoningMessageChunkEvent : BaseEvent
2525
[JsonPropertyName("delta")]
2626
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2727
public string? Delta { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the subagent that produced this event, absent when the parent agent
31+
/// produced it directly.
32+
/// </summary>
33+
[JsonPropertyName("subagentId")]
34+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35+
public string? SubagentId { get; set; }
2836
}

‎sdks/dotnet/src/AGUI.Abstractions/Events/ReasoningMessageContentEvent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public sealed class ReasoningMessageContentEvent : BaseEvent
2323
/// </summary>
2424
[JsonPropertyName("delta")]
2525
public string Delta { get; set; } = string.Empty;
26+
27+
/// <summary>
28+
/// Gets or sets the subagent that produced this event, absent when the parent agent
29+
/// produced it directly.
30+
/// </summary>
31+
[JsonPropertyName("subagentId")]
32+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
33+
public string? SubagentId { get; set; }
2634
}

0 commit comments

Comments
 (0)