@@ -255,6 +255,7 @@ def _initialize_fresh_execution(
255255 messages : list [ChatMessage ],
256256 streaming_callback : Optional [StreamingCallbackT ],
257257 requires_async : bool ,
258+ system_prompt : Optional [str ] = None ,
258259 ** kwargs ,
259260 ) -> _ExecutionContext :
260261 """
@@ -263,10 +264,12 @@ def _initialize_fresh_execution(
263264 :param messages: List of ChatMessage objects to start the agent with.
264265 :param streaming_callback: Optional callback for streaming responses.
265266 :param requires_async: Whether the agent run requires asynchronous execution.
267+ :param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
266268 :param kwargs: Additional data to pass to the State used by the Agent.
267269 """
268- if self .system_prompt is not None :
269- messages = [ChatMessage .from_system (self .system_prompt )] + messages
270+ system_prompt = system_prompt or self .system_prompt
271+ if system_prompt is not None :
272+ messages = [ChatMessage .from_system (system_prompt )] + messages
270273
271274 if all (m .is_from (ChatRole .SYSTEM ) for m in messages ):
272275 logger .warning ("All messages provided to the Agent component are system messages. This is not recommended." )
@@ -443,6 +446,7 @@ def run(
443446 * ,
444447 break_point : Optional [AgentBreakpoint ] = None ,
445448 snapshot : Optional [AgentSnapshot ] = None ,
449+ system_prompt : Optional [str ] = None ,
446450 ** kwargs : Any ,
447451 ) -> dict [str , Any ]:
448452 """
@@ -455,6 +459,7 @@ def run(
455459 for "tool_invoker".
456460 :param snapshot: A dictionary containing a snapshot of a previously saved agent execution. The snapshot contains
457461 the relevant information to restart the Agent execution from where it left off.
462+ :param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
458463 :param kwargs: Additional data to pass to the State schema used by the Agent.
459464 The keys must match the schema defined in the Agent's `state_schema`.
460465 :returns:
@@ -482,7 +487,11 @@ def run(
482487 )
483488 else :
484489 exe_context = self ._initialize_fresh_execution (
485- messages = messages , streaming_callback = streaming_callback , requires_async = False , ** kwargs
490+ messages = messages ,
491+ streaming_callback = streaming_callback ,
492+ requires_async = False ,
493+ system_prompt = system_prompt ,
494+ ** kwargs ,
486495 )
487496
488497 with self ._create_agent_span () as span :
@@ -558,6 +567,7 @@ async def run_async(
558567 * ,
559568 break_point : Optional [AgentBreakpoint ] = None ,
560569 snapshot : Optional [AgentSnapshot ] = None ,
570+ system_prompt : Optional [str ] = None ,
561571 ** kwargs : Any ,
562572 ) -> dict [str , Any ]:
563573 """
@@ -574,6 +584,7 @@ async def run_async(
574584 for "tool_invoker".
575585 :param snapshot: A dictionary containing a snapshot of a previously saved agent execution. The snapshot contains
576586 the relevant information to restart the Agent execution from where it left off.
587+ :param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
577588 :param kwargs: Additional data to pass to the State schema used by the Agent.
578589 The keys must match the schema defined in the Agent's `state_schema`.
579590 :returns:
@@ -601,7 +612,11 @@ async def run_async(
601612 )
602613 else :
603614 exe_context = self ._initialize_fresh_execution (
604- messages = messages , streaming_callback = streaming_callback , requires_async = False , ** kwargs
615+ messages = messages ,
616+ streaming_callback = streaming_callback ,
617+ requires_async = False ,
618+ system_prompt = system_prompt ,
619+ ** kwargs ,
605620 )
606621
607622 with self ._create_agent_span () as span :
0 commit comments