@@ -271,7 +271,9 @@ async def _prompt_sending_orchestrator(
271271
272272 # Check if any context has agent-specific fields (context_type, tool_name)
273273 has_agent_fields = any (
274- isinstance (ctx , dict ) and ("context_type" in ctx or "tool_name" in ctx ) for ctx in contexts
274+ isinstance (ctx , dict )
275+ and ("context_type" in ctx and "tool_name" in ctx and ctx ["tool_name" ] is not None )
276+ for ctx in contexts
275277 )
276278
277279 # Build context_dict to pass via memory labels
@@ -284,46 +286,6 @@ async def _prompt_sending_orchestrator(
284286 else None
285287 )
286288
287- # Initialize processed_prompt with the original prompt as default
288- processed_prompt = prompt
289-
290- # Determine how to handle the prompt based on target type and context fields
291- if isinstance (chat_target , _CallbackChatTarget ):
292- # CallbackChatTarget: Always pass contexts via context_dict, embed in prompt content
293- if contexts and not has_agent_fields :
294- # For contexts without agent fields, the prompt already has context embedded
295- # (done in _extract_objective_content), so just use it as-is
296- processed_prompt = prompt
297- self .logger .debug (
298- f"CallbackChatTarget: Prompt has embedded context, passing { len (contexts )} context source(s) in context_dict"
299- )
300- else :
301- # Agent fields present - prompt is clean, contexts have structure
302- processed_prompt = prompt
303- tool_names = [
304- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
305- ]
306- self .logger .debug (
307- f"CallbackChatTarget: Passing { len (contexts )} structured context(s) with agent fields, tool_names={ tool_names } "
308- )
309- else :
310- # Non-CallbackChatTarget: Embed contexts in the actual PyRIT message
311- if has_agent_fields :
312- # Agent target with structured context - don't embed in prompt
313- processed_prompt = prompt
314- tool_names = [
315- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
316- ]
317- self .logger .debug (
318- f"Non-CallbackChatTarget with agent fields: { len (contexts )} context source(s), tool_names={ tool_names } "
319- )
320- elif contexts :
321- # Model target without agent fields - embed context in prompt
322- # Note: The prompt already has context embedded from _extract_objective_content
323- # But for non-CallbackChatTarget, we may need additional wrapping
324- processed_prompt = prompt
325- self .logger .debug (f"Non-CallbackChatTarget: Using prompt with embedded context" )
326-
327289 try :
328290 # Create retry-enabled function using the reusable decorator
329291 @network_retry_decorator (
@@ -339,7 +301,7 @@ async def send_prompt_with_retry():
339301 memory_labels ["risk_sub_type" ] = risk_sub_type
340302 return await asyncio .wait_for (
341303 orchestrator .send_prompts_async (
342- prompt_list = [processed_prompt ],
304+ prompt_list = [prompt ],
343305 memory_labels = memory_labels ,
344306 ),
345307 timeout = calculated_timeout ,
@@ -514,46 +476,6 @@ async def _multi_turn_orchestrator(
514476 ctx .get ("content" , "" ) if isinstance (ctx , dict ) else str (ctx ) for ctx in contexts
515477 )
516478
517- # Initialize processed_prompt with the original prompt as default
518- processed_prompt = prompt
519-
520- # Determine how to handle the prompt based on target type and context fields
521- if isinstance (chat_target , _CallbackChatTarget ):
522- # CallbackChatTarget: Always pass contexts via context_dict, embed in prompt content
523- if contexts and not has_agent_fields :
524- # For contexts without agent fields, the prompt already has context embedded
525- # (done in _extract_objective_content), so just use it as-is
526- processed_prompt = prompt
527- self .logger .debug (
528- f"CallbackChatTarget: Prompt has embedded context, passing { len (contexts )} context source(s) in context_dict"
529- )
530- else :
531- # Agent fields present - prompt is clean, contexts have structure
532- processed_prompt = prompt
533- tool_names = [
534- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
535- ]
536- self .logger .debug (
537- f"CallbackChatTarget: Passing { len (contexts )} structured context(s) with agent fields, tool_names={ tool_names } "
538- )
539- else :
540- # Non-CallbackChatTarget: Embed contexts in the actual PyRIT message
541- if has_agent_fields :
542- # Agent target with structured context - don't embed in prompt
543- processed_prompt = prompt
544- tool_names = [
545- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
546- ]
547- self .logger .debug (
548- f"Non-CallbackChatTarget with agent fields: { len (contexts )} context source(s), tool_names={ tool_names } "
549- )
550- elif contexts :
551- # Model target without agent fields - embed context in prompt
552- # Note: The prompt already has context embedded from _extract_objective_content
553- # But for non-CallbackChatTarget, we may need additional wrapping
554- processed_prompt = prompt
555- self .logger .debug (f"Non-CallbackChatTarget: Using prompt with embedded context" )
556-
557479 try :
558480 azure_rai_service_scorer = AzureRAIServiceTrueFalseScorer (
559481 client = self .generated_rai_client ,
@@ -741,7 +663,9 @@ async def _crescendo_orchestrator(
741663
742664 # Check if any context has agent-specific fields (context_type, tool_name)
743665 has_agent_fields = any (
744- isinstance (ctx , dict ) and ("context_type" in ctx or "tool_name" in ctx ) for ctx in contexts
666+ isinstance (ctx , dict )
667+ and ("context_type" in ctx and "tool_name" in ctx and ctx ["tool_name" ] is not None )
668+ for ctx in contexts
745669 )
746670
747671 # Build context_dict to pass via memory labels
@@ -762,46 +686,6 @@ async def _crescendo_orchestrator(
762686 ctx .get ("content" , "" ) if isinstance (ctx , dict ) else str (ctx ) for ctx in contexts
763687 )
764688
765- # Initialize processed_prompt with the original prompt as default
766- processed_prompt = prompt
767-
768- # Determine how to handle the prompt based on target type and context fields
769- if isinstance (chat_target , _CallbackChatTarget ):
770- # CallbackChatTarget: Always pass contexts via context_dict, embed in prompt content
771- if contexts and not has_agent_fields :
772- # For contexts without agent fields, the prompt already has context embedded
773- # (done in _extract_objective_content), so just use it as-is
774- processed_prompt = prompt
775- self .logger .debug (
776- f"CallbackChatTarget: Prompt has embedded context, passing { len (contexts )} context source(s) in context_dict"
777- )
778- else :
779- # Agent fields present - prompt is clean, contexts have structure
780- processed_prompt = prompt
781- tool_names = [
782- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
783- ]
784- self .logger .debug (
785- f"CallbackChatTarget: Passing { len (contexts )} structured context(s) with agent fields, tool_names={ tool_names } "
786- )
787- else :
788- # Non-CallbackChatTarget: Embed contexts in the actual PyRIT message
789- if has_agent_fields :
790- # Agent target with structured context - don't embed in prompt
791- processed_prompt = prompt
792- tool_names = [
793- ctx .get ("tool_name" ) for ctx in contexts if isinstance (ctx , dict ) and "tool_name" in ctx
794- ]
795- self .logger .debug (
796- f"Non-CallbackChatTarget with agent fields: { len (contexts )} context source(s), tool_names={ tool_names } "
797- )
798- elif contexts :
799- # Model target without agent fields - embed context in prompt
800- # Note: The prompt already has context embedded from _extract_objective_content
801- # But for non-CallbackChatTarget, we may need additional wrapping
802- processed_prompt = prompt
803- self .logger .debug (f"Non-CallbackChatTarget: Using prompt with embedded context" )
804-
805689 try :
806690 red_llm_scoring_target = RAIServiceEvalChatTarget (
807691 logger = self .logger ,
0 commit comments