From 35c280bba065e5b8d43f5b6c6acf5f990ce1374a Mon Sep 17 00:00:00 2001 From: Bryan <74067792+Bryan-Roe@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:31:13 -0700 Subject: [PATCH 1/3] Add debug logging to agent threads --- .../python/semantic_kernel/agents/agent.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/01-core-implementations/python/semantic_kernel/agents/agent.py b/01-core-implementations/python/semantic_kernel/agents/agent.py index 1c92c91fe7e4..53201e30574e 100644 --- a/01-core-implementations/python/semantic_kernel/agents/agent.py +++ b/01-core-implementations/python/semantic_kernel/agents/agent.py @@ -139,7 +139,9 @@ async def create(self) -> str | None: return self.id # Otherwise, create the thread. + logger.debug("Creating agent thread") self._id = await self._create() + logger.debug("Created agent thread with id %s", self._id) return self.id async def delete(self) -> None: @@ -154,7 +156,9 @@ async def delete(self) -> None: return # Otherwise, delete the thread. + logger.debug("Deleting agent thread %s", self._id) await self._delete() + logger.debug("Deleted agent thread %s", self._id) self._id = None self._is_deleted = True @@ -167,6 +171,7 @@ async def on_new_message( if self.id is None: await self.create() + logger.debug("Thread %s received new message from role %s", self._id, new_message.role) await self._on_new_message(new_message) @abstractmethod @@ -514,6 +519,7 @@ async def _ensure_thread_exists_with_messages( if thread is None: thread = construct_thread() + logger.debug("Created new thread for agent interaction") await thread.create() if not isinstance(thread, expected_type): @@ -533,6 +539,9 @@ async def _notify_thread_of_new_message( new_message: ChatMessageContent, ) -> None: """Notify the thread of a new message.""" + logger.debug( + "Notifying thread %s of new message from role %s", thread.id, new_message.role + ) await thread.on_new_message(new_message) # endregion From 86f3b90f1b7695665538aeb3014618dcdb9c8a6d Mon Sep 17 00:00:00 2001 From: Bryan <74067792+Bryan-Roe@users.noreply.github.com> Date: Sun, 3 Aug 2025 01:24:15 -0700 Subject: [PATCH 2/3] Update agent.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Bryan <74067792+Bryan-Roe@users.noreply.github.com> --- 01-core-implementations/python/semantic_kernel/agents/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01-core-implementations/python/semantic_kernel/agents/agent.py b/01-core-implementations/python/semantic_kernel/agents/agent.py index 53201e30574e..f7d235ffc6c6 100644 --- a/01-core-implementations/python/semantic_kernel/agents/agent.py +++ b/01-core-implementations/python/semantic_kernel/agents/agent.py @@ -171,7 +171,7 @@ async def on_new_message( if self.id is None: await self.create() - logger.debug("Thread %s received new message from role %s", self._id, new_message.role) + logger.debug("Thread %s received new message from role %s", self.id, new_message.role) await self._on_new_message(new_message) @abstractmethod From 06e9d613336feef39ee55960c12fbe43180294f7 Mon Sep 17 00:00:00 2001 From: Bryan <74067792+Bryan-Roe@users.noreply.github.com> Date: Sun, 3 Aug 2025 01:24:29 -0700 Subject: [PATCH 3/3] Update agent.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: Bryan <74067792+Bryan-Roe@users.noreply.github.com> --- .../python/semantic_kernel/agents/agent.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/01-core-implementations/python/semantic_kernel/agents/agent.py b/01-core-implementations/python/semantic_kernel/agents/agent.py index f7d235ffc6c6..3dce30410485 100644 --- a/01-core-implementations/python/semantic_kernel/agents/agent.py +++ b/01-core-implementations/python/semantic_kernel/agents/agent.py @@ -539,9 +539,14 @@ async def _notify_thread_of_new_message( new_message: ChatMessageContent, ) -> None: """Notify the thread of a new message.""" - logger.debug( - "Notifying thread %s of new message from role %s", thread.id, new_message.role - ) + if thread.id is None: + logger.debug( + "Notifying thread with no ID of new message from role %s", new_message.role + ) + else: + logger.debug( + "Notifying thread %s of new message from role %s", thread.id, new_message.role + ) await thread.on_new_message(new_message) # endregion