File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ using System . ComponentModel ;
2+ using System . Runtime . CompilerServices ;
3+ using Microsoft . Agents . AI ;
4+ using Microsoft . Extensions . AI ;
5+
6+ namespace Devlooped . Agents . AI ;
7+
8+ /// <summary>
9+ /// Miscenalleous extension methods for agents.
10+ /// </summary>
11+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
12+ public static class AgentExtensions
13+ {
14+ /// <summary>Ensures the returned <see cref="ChatResponse"/> contains the <see cref="AgentRunResponse.AgentId"/> as an additional property.</summary>
15+ /// <devdoc>Change priority to -10 and make EditorBrowsable.Never when https://github.com/microsoft/agent-framework/issues/1574 is fixed.</devdoc>
16+ [ OverloadResolutionPriority ( 10 ) ]
17+ public static ChatResponse AsChatResponse ( this AgentRunResponse response )
18+ {
19+ var chatResponse = AgentRunResponseExtensions . AsChatResponse ( response ) ;
20+
21+ chatResponse . AdditionalProperties ??= [ ] ;
22+ chatResponse . AdditionalProperties [ nameof ( response . AgentId ) ] = response . AgentId ;
23+
24+ return chatResponse ;
25+ }
26+ }
Original file line number Diff line number Diff line change 2727 <PackageReference Include =" Microsoft.Agents.AI.OpenAI" Version =" 1.0.0-preview.251009.1" />
2828 <PackageReference Include =" Microsoft.Extensions.Configuration.Abstractions" Version =" 9.0.9" />
2929 <PackageReference Include =" Microsoft.Extensions.Logging" Version =" 9.0.9" />
30+ <PackageReference Include =" PolySharp" Version =" 1.15.0" PrivateAssets =" all" />
3031 </ItemGroup >
3132
3233 <ItemGroup >
Original file line number Diff line number Diff line change @@ -249,5 +249,14 @@ public void CanSetGrokOptions()
249249 Assert . Equal ( ReasoningEffort . High , grok . ReasoningEffort ) ;
250250 Assert . Equal ( GrokSearch . Off , grok . Search ) ;
251251 }
252+
253+ [ Fact ]
254+ public void Task ( )
255+ {
256+ var agent = new AgentRunResponse ( ) { AgentId = "agent-123" } ;
257+ var chat = agent . AsChatResponse ( ) ;
258+
259+ Assert . Equal ( "agent-123" , chat . AdditionalProperties ! [ "AgentId" ] ) ;
260+ }
252261}
253262
You can’t perform that action at this time.
0 commit comments