Skip to content

feat(agentchat): add get_thread() to BaseGroupChat (closes #6085)#7684

Open
EvanYao826 wants to merge 1 commit into
microsoft:mainfrom
EvanYao826:feat/get-thread-6085
Open

feat(agentchat): add get_thread() to BaseGroupChat (closes #6085)#7684
EvanYao826 wants to merge 1 commit into
microsoft:mainfrom
EvanYao826:feat/get-thread-6085

Conversation

@EvanYao826
Copy link
Copy Markdown

Why are these changes needed?

Implements the feature requested in #6085: expose the group chat message thread as a public async API on BaseGroupChat.

Changes

_events.py — new GroupChatGetThread / GroupChatThreadResponse RPC message types for the protocol.

_base_group_chat_manager.py — new @rpc handler handle_get_thread() that returns a shallow copy of the internal self._message_thread.

_base_group_chat.py — new async def get_thread() on BaseGroupChat:

  • Tracks messages in self._thread during run_stream, cleared on reset()
  • Returns a snapshot (shallow copy) so callers cannot mutate internal state
  • Works both during a run and after completion — no dependency on runtime message processing (avoids the embedded-runtime-stops-after-run issue)

tests/test_group_chat_get_thread.py — 4 pytest-asyncio tests:

  • test_get_thread_after_run — non-empty snapshot matches TaskResult messages
  • test_get_thread_not_initialized_raises — RuntimeError before first run
  • test_get_thread_returns_snapshot — mutating returned list does not affect internal state
  • test_get_thread_with_no_task — works after run with no initial task

Design note

Unlike pause() / resume() which use send_message during an active run, get_thread() must work after run() completes. Since the embedded SingleThreadedAgentRuntime stops processing messages after stop_when_idle(), a pure send_message-based approach would hang. Instead, BaseGroupChat maintains its own self._thread list populated during run_stream, which the manager also populates via the shared output message queue. This keeps the API reliable regardless of runtime lifecycle.

Related issue number

Closes #6085

Checks

  • I have included tests
  • All 4 tests pass locally (pytest-asyncio)
  • No existing tests broken

Add a public method to retrieve the current message thread from a
group chat team after or during a run.

- Add  and  event types
  in  for the RPC protocol.
- Add  RPC handler in  that
  returns a shallow copy of the internal message thread.
- Add  public method on  that returns
  a snapshot of the message thread accumulated during runs.
- Track messages in  on BaseGroupChat during run_stream,
  clear on reset.
- Add 4 pytest-asyncio tests covering: after-run retrieval, not-
  initialized error, snapshot isolation, and no-task continuation.

Closes microsoft#6085

Signed-off-by: EvanYao826 <2869018789@qq.com>
@EvanYao826
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get current message thread from a group chat team.

1 participant