@@ -776,35 +776,57 @@ await foreach (var content in agent.InvokeAsync(userInput, thread))
776776
777777** With this Agent Framework CodeInterpreter pattern:**
778778``` csharp
779+ using System .Text ;
780+ using Microsoft .Agents .AI ;
781+ using Microsoft .Extensions .AI ;
782+
779783var result = await agent .RunAsync (userInput , thread );
780784Console .WriteLine (result );
781785
782- // Extract chat response MEAI type via first level breaking glass
783- var chatResponse = result .RawRepresentation as ChatResponse ;
786+ // Get the CodeInterpreterToolCallContent (code input)
787+ CodeInterpreterToolCallContent ? toolCallContent = result .Messages
788+ .SelectMany (m => m .Contents )
789+ .OfType <CodeInterpreterToolCallContent >()
790+ .FirstOrDefault ();
791+
792+ if (toolCallContent ? .Inputs is not null )
793+ {
794+ DataContent ? codeInput = toolCallContent .Inputs .OfType <DataContent >().FirstOrDefault ();
795+ if (codeInput ? .HasTopLevelMediaType (" text" ) ?? false )
796+ {
797+ Console .WriteLine ($" Code Input: {Encoding .UTF8 .GetString (codeInput .Data .ToArray ())}" );
798+ }
799+ }
784800
785- // Extract underlying SDK updates via second level breaking glass
786- var underlyingStreamingUpdates = chatResponse ? .RawRepresentation as IEnumerable <object ?> ?? [];
801+ // Get the CodeInterpreterToolResultContent (code output)
802+ CodeInterpreterToolResultContent ? toolResultContent = result .Messages
803+ .SelectMany (m => m .Contents )
804+ .OfType <CodeInterpreterToolResultContent >()
805+ .FirstOrDefault ();
787806
788- StringBuilder generatedCode = new ();
789- foreach (object ? underlyingUpdate in underlyingStreamingUpdates ?? [])
807+ if (toolResultContent ? .Outputs is not null )
790808{
791- if (underlyingUpdate is RunStepDetailsUpdate stepDetailsUpdate && stepDetailsUpdate .CodeInterpreterInput is not null )
809+ TextContent ? resultOutput = toolResultContent .Outputs .OfType <TextContent >().FirstOrDefault ();
810+ if (resultOutput is not null )
792811 {
793- generatedCode . Append ( stepDetailsUpdate . CodeInterpreterInput );
812+ Console . WriteLine ( $" Code Tool Result: { resultOutput . Text } " );
794813 }
795814}
796815
797- if (! string .IsNullOrEmpty (generatedCode .ToString ()))
816+ // Getting any annotations generated by the tool
817+ foreach (AIAnnotation annotation in result .Messages
818+ .SelectMany (m => m .Contents )
819+ .SelectMany (c => c .Annotations ?? []))
798820{
799- Console .WriteLine ($" \n # { chatResponse ? . Messages [ 0 ]. Role }:Generated Code: \n { generatedCode }" );
821+ Console .WriteLine ($" Annotation: { annotation }" );
800822}
801823```
802824
803825** Functional differences:**
804- 1 . Code interpreter output is separate from text content, not a metadata property
805- 2 . Access code via ` RunStepDetailsUpdate.CodeInterpreterInput ` instead of metadata
806- 3 . Use breaking glass pattern to access underlying SDK objects
807- 4 . Process text content and code interpreter output independently
826+ 1 . Code interpreter content is now available via MEAI abstractions - no breaking glass required
827+ 2 . Use ` CodeInterpreterToolCallContent ` to access code inputs (the generated code)
828+ 3 . Use ` CodeInterpreterToolResultContent ` to access code outputs (execution results)
829+ 4 . Annotations are accessible via ` AIAnnotation ` on content items
808830</behavioral_changes>
809831
810832#### Provider-Specific Options Configuration
0 commit comments