@@ -354,10 +354,11 @@ def _process_message(self, event):
354354 trace_attributes = self .agent .trace_attributes
355355
356356 agent = Agent (
357+ model = self .agent .model ,
357358 messages = [],
358359 system_prompt = f"{ self .agent .system_prompt } \n { SLACK_SYSTEM_PROMPT } " ,
359360 tools = tools ,
360- callback_handler = None ,
361+ callback_handler = self . agent . callback_handler ,
361362 trace_attributes = trace_attributes ,
362363 )
363364
@@ -386,12 +387,14 @@ def _process_message(self, event):
386387 logger .info (f"Skipping message - does not contain tag: { listen_only_tag } " )
387388 return
388389
389- # Process with agent
390- response = agent (
391- f"[Channel: { channel_id } ] User { user } says: { text } " ,
392- system_prompt = f"{ SLACK_SYSTEM_PROMPT } \n \n Event Context:\n Current: { json .dumps (event )} { event_context } " ,
390+ # Refresh the system prompt with latest context handled from Slack events
391+ agent .system_prompt = (
392+ f"{ SLACK_SYSTEM_PROMPT } \n \n Event Context:\n Current: { json .dumps (event )} { event_context } "
393393 )
394394
395+ # Process with agent
396+ response = agent (f"[Channel: { channel_id } ] User { user } says: { text } " )
397+
395398 # If we have a valid response, send it back to Slack
396399 if response and str (response ).strip ():
397400 if client :
@@ -437,7 +440,13 @@ def _process_interactive(self, event):
437440 if client and self .agent :
438441 tools = list (self .agent .tool_registry .registry .values ())
439442
440- agent = Agent (messages = [], system_prompt = SLACK_SYSTEM_PROMPT , tools = tools , callback_handler = None )
443+ agent = Agent (
444+ model = self .agent .model ,
445+ messages = [],
446+ system_prompt = SLACK_SYSTEM_PROMPT ,
447+ tools = tools ,
448+ callback_handler = self .agent .callback_handler ,
449+ )
441450
442451 channel_id = event .get ("channel" )
443452 actions = event .get ("actions" , [])
@@ -447,10 +456,8 @@ def _process_interactive(self, event):
447456 interaction_text = f"Interactive event from user { event .get ('user' )} . Actions: { actions } "
448457
449458 try :
450- response = agent (
451- interaction_text ,
452- system_prompt = f"{ SLACK_SYSTEM_PROMPT } \n \n Interactive Context:\n { json .dumps (event , indent = 2 )} " ,
453- )
459+ agent .system_prompt = f"{ SLACK_SYSTEM_PROMPT } \n \n Interactive Context:\n { json .dumps (event , indent = 2 )} "
460+ response = agent (interaction_text )
454461
455462 # Only send a response if auto-reply is enabled
456463 if os .getenv ("STRANDS_SLACK_AUTO_REPLY" , "false" ).lower () == "true" :
@@ -531,8 +538,7 @@ def stop(self):
531538
532539@tool
533540def slack (action : str , parameters : Dict [str , Any ] = None , agent = None ) -> str :
534- """
535- Comprehensive Slack integration for messaging, events, and interactions.
541+ """Slack integration for messaging, events, and interactions.
536542
537543 This tool provides complete access to Slack's API methods and real-time
538544 event handling through a unified interface. It enables Strands agents to
@@ -668,8 +674,7 @@ def slack(action: str, parameters: Dict[str, Any] = None, agent=None) -> str:
668674
669675@tool
670676def slack_send_message (channel : str , text : str , thread_ts : str = None ) -> str :
671- """
672- Send a message to a Slack channel.
677+ """Send a message to a Slack channel.
673678
674679 This is a simplified interface for the most common Slack operation: sending messages.
675680 It wraps the Slack API's chat_postMessage method with a more direct interface,
0 commit comments