autogen icon indicating copy to clipboard operation
autogen copied to clipboard

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

Open EvanYao826 opened this issue 6 months ago • 1 comments

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

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

EvanYao826 avatar May 13 '26 06:05 EvanYao826

@microsoft-github-policy-service agree

EvanYao826 avatar May 15 '26 10:05 EvanYao826