5151
5252
5353def _transform_system_instructions (
54- system_instructions : "list[SystemPromptPart]" ,
54+ permanent_instructions : "list[SystemPromptPart]" ,
55+ current_instructions : "list[str]" ,
5556) -> "list[SentryTextPart]" :
5657 return [
5758 {
5859 "type" : "text" ,
5960 "content" : instruction .content ,
6061 }
61- for instruction in system_instructions
62+ for instruction in permanent_instructions
63+ ] + [
64+ {
65+ "type" : "text" ,
66+ "content" : instruction ,
67+ }
68+ for instruction in current_instructions
6269 ]
6370
6471
6572def _get_system_instructions (
6673 messages : "list[ModelMessage]" ,
67- ) -> "list[SystemPromptPart]" :
68- system_instructions = []
74+ ) -> "tuple[list[SystemPromptPart], list[str]]" :
75+ permanent_instructions = []
76+ current_instructions = []
6977
7078 for msg in messages :
7179 if hasattr (msg , "parts" ):
7280 for part in msg .parts :
7381 if SystemPromptPart and isinstance (part , SystemPromptPart ):
74- system_instructions .append (part )
82+ permanent_instructions .append (part )
83+
84+ if hasattr (msg , "instructions" ) and msg .instructions is not None :
85+ current_instructions .append (msg .instructions )
7586
76- return system_instructions
87+ return permanent_instructions , current_instructions
7788
7889
7990def _set_input_messages (span : "sentry_sdk.tracing.Span" , messages : "Any" ) -> None :
@@ -84,12 +95,14 @@ def _set_input_messages(span: "sentry_sdk.tracing.Span", messages: "Any") -> Non
8495 if not messages :
8596 return
8697
87- system_instructions = _get_system_instructions (messages )
88- if len (system_instructions ) > 0 :
98+ permanent_instructions , current_instructions = _get_system_instructions (messages )
99+ if len (permanent_instructions ) > 0 or len ( current_instructions ) > 0 :
89100 set_data_normalized (
90101 span ,
91102 SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ,
92- _transform_system_instructions (system_instructions ),
103+ _transform_system_instructions (
104+ permanent_instructions , current_instructions
105+ ),
93106 unpack = False ,
94107 )
95108
0 commit comments