1212from event_utils import track_event_if_configured
1313from models .messages_kernel import (ActionRequest , ActionResponse ,
1414 AgentMessage , Step , StepStatus )
15+ from semantic_kernel .agents import AzureAIAgentThread # pylint:disable=E0611
1516from semantic_kernel .agents .azure_ai .azure_ai_agent import AzureAIAgent
1617from semantic_kernel .functions import KernelFunction
1718from semantic_kernel .functions .kernel_arguments import KernelArguments
@@ -34,6 +35,7 @@ def __init__(
3435 system_message : Optional [str ] = None ,
3536 client = None ,
3637 definition = None ,
38+ thread : AzureAIAgentThread = None ,
3739 ):
3840 """Initialize the base agent.
3941
@@ -74,19 +76,12 @@ def __init__(
7476 self ._tools = tools
7577 self ._system_message = system_message
7678 self ._chat_history = [{"role" : "system" , "content" : self ._system_message }]
77- # self._agent = None # Will be initialized in async_init
79+ self ._message = None # Will be initialized in handle_action_request
80+ self ._thread = thread
7881
7982 # Required properties for AgentGroupChat compatibility
8083 self .name = agent_name # This is crucial for AgentGroupChat to identify agents
8184
82- # @property
83- # def plugins(self) -> Optional[dict[str, Callable]]:
84- # """Get the plugins for this agent.
85-
86- # Returns:
87- # A list of plugins, or None if not applicable.
88- # """
89- # return None
9085 @staticmethod
9186 def default_system_message (agent_name = None ) -> str :
9287 name = agent_name
@@ -114,32 +109,17 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
114109 status = StepStatus .failed ,
115110 message = "Step not found in memory." ,
116111 )
117- return response .json ()
112+ return response .model_dump_json ()
118113
119- # Add messages to chat history for context
120- # This gives the agent visibility of the conversation history
121- self ._chat_history .extend (
122- [
123- {"role" : "assistant" , "content" : action_request .action },
124- {
125- "role" : "user" ,
126- "content" : f"{ step .human_feedback } . Now make the function call" ,
127- },
128- ]
129- )
114+ self ._message = [
115+ action_request .action
116+ ]
130117
131118 try :
132- # Use the agent to process the action
133- # chat_history = self._chat_history.copy()
134-
135- # Call the agent to handle the action
136- thread = None
137- # thread = self.client.agents.get_thread(
138- # thread=step.session_id
139- # ) # AzureAIAgentThread(thread_id=step.session_id)
119+ # Use the agent to process the action request
140120 async_generator = self .invoke (
141- messages = f" { str ( self ._chat_history ) } \n \n Please perform this action" ,
142- thread = thread ,
121+ messages = self ._message ,
122+ thread = self . _thread ,
143123 )
144124
145125 response_content = ""
@@ -149,6 +129,10 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
149129 if chunk is not None :
150130 response_content += str (chunk )
151131
132+ # Log the messages in the thread
133+ # async for msg in self._thread.get_messages():
134+ # logging.info(f"thread messages - role:{msg.role} - content:{msg.content}")
135+
152136 logging .info (f"Response content length: { len (response_content )} " )
153137 logging .info (f"Response content: { response_content } " )
154138
0 commit comments