Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
965d9a4
FEAT: select group chat could using stream
SongChiYoung Apr 12, 2025
d42a382
Merge remote-tracking branch 'upstream/main' into feature/model_clien…
SongChiYoung Apr 13, 2025
7aff3b6
FIX: delete useless if block
SongChiYoung Apr 13, 2025
99194d4
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
SongChiYoung Apr 15, 2025
7e24527
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
SongChiYoung Apr 16, 2025
55a1341
Merge
SongChiYoung Apr 17, 2025
fda2d28
clean
SongChiYoung Apr 17, 2025
31d0d66
done - maybe need to adding testcase
SongChiYoung Apr 17, 2025
29f2c0f
Merge remote-tracking branch 'upstream/main' into feature/model_clien…
SongChiYoung Apr 17, 2025
cd9e000
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
SongChiYoung Apr 18, 2025
d563032
FIX: adding full message of content of stream.
SongChiYoung Apr 19, 2025
3486d6d
Clean, Add test
SongChiYoung Apr 19, 2025
548171a
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
SongChiYoung Apr 19, 2025
4abae5a
Apply suggestions from code review
ekzhu Apr 21, 2025
e68dbbf
Update python/packages/autogen-agentchat/src/autogen_agentchat/teams/…
ekzhu Apr 21, 2025
4fabfce
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
ekzhu Apr 21, 2025
b711739
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
SongChiYoung Apr 21, 2025
05c250a
Fix tests
ekzhu Apr 21, 2025
c9f7582
fix
ekzhu Apr 21, 2025
ef67c17
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
ekzhu Apr 21, 2025
f698469
Fix
ekzhu Apr 21, 2025
94a8f9b
Merge branch 'main' into feature/model_client_streaming_from_the_sele…
ekzhu Apr 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from typing import Any, Awaitable, Callable, Dict, List, Mapping, Optional, Sequence, Union, cast

from autogen_core import AgentRuntime, Component, ComponentModel
from autogen_core.models import AssistantMessage, ChatCompletionClient, ModelFamily, SystemMessage, UserMessage
from autogen_core.logging import LLMStreamEndEvent
from autogen_core.models import (
AssistantMessage,
ChatCompletionClient,
CreateResult,
ModelFamily,
SystemMessage,
UserMessage,
)
from pydantic import BaseModel
from typing_extensions import Self

Expand Down Expand Up @@ -55,6 +63,7 @@ def __init__(
selector_func: Optional[SelectorFuncType],
max_selector_attempts: int,
candidate_func: Optional[CandidateFuncType],
streaming: bool = False,
Comment thread
ekzhu marked this conversation as resolved.
Outdated
) -> None:
super().__init__(
name,
Expand All @@ -77,6 +86,7 @@ def __init__(
self._max_selector_attempts = max_selector_attempts
self._candidate_func = candidate_func
self._is_candidate_func_async = iscoroutinefunction(self._candidate_func)
self._streaming = streaming

async def validate_group_state(self, messages: List[BaseChatMessage] | None) -> None:
pass
Expand Down Expand Up @@ -192,7 +202,18 @@ async def _select_speaker(self, roles: str, participants: List[str], history: st
num_attempts = 0
while num_attempts < max_attempts:
num_attempts += 1
response = await self._model_client.create(messages=select_speaker_messages)
if self._streaming:
message: CreateResult | str = ""
async for _message in self._model_client.create_stream(messages=select_speaker_messages):
if isinstance(_message, LLMStreamEndEvent):
Comment thread
ekzhu marked this conversation as resolved.
Outdated
break
message = _message
Comment thread
ekzhu marked this conversation as resolved.
Outdated
if isinstance(message, CreateResult):
response = message
else:
raise ValueError("Model failed to select a speaker.")
else:
response = await self._model_client.create(messages=select_speaker_messages)
assert isinstance(response.content, str)
select_speaker_messages.append(AssistantMessage(content=response.content, source="selector"))
# NOTE: we use all participant names to check for mentions, even if the previous speaker is not allowed.
Expand Down Expand Up @@ -278,6 +299,7 @@ class SelectorGroupChatConfig(BaseModel):
allow_repeated_speaker: bool
# selector_func: ComponentModel | None
max_selector_attempts: int = 3
streaming: bool = False


class SelectorGroupChat(BaseGroupChat, Component[SelectorGroupChatConfig]):
Expand Down Expand Up @@ -307,7 +329,7 @@ class SelectorGroupChat(BaseGroupChat, Component[SelectorGroupChatConfig]):
A custom function that takes the conversation history and returns a filtered list of candidates for the next speaker
selection using model. If the function returns an empty list or `None`, `SelectorGroupChat` will raise a `ValueError`.
This function is only used if `selector_func` is not set. The `allow_repeated_speaker` will be ignored if set.

streaming (bool, optional): Whether to use streaming for the model.(Only use for specify case e.g. QwQ) Defaults to False.

Raises:
ValueError: If the number of participants is less than two or if the selector prompt is invalid.
Expand Down Expand Up @@ -449,6 +471,7 @@ def __init__(
selector_func: Optional[SelectorFuncType] = None,
candidate_func: Optional[CandidateFuncType] = None,
custom_message_types: List[type[BaseAgentEvent | BaseChatMessage]] | None = None,
streaming: bool = False,
):
super().__init__(
participants,
Expand All @@ -468,6 +491,7 @@ def __init__(
self._selector_func = selector_func
self._max_selector_attempts = max_selector_attempts
self._candidate_func = candidate_func
self._streaming = streaming

def _create_group_chat_manager_factory(
self,
Expand Down Expand Up @@ -499,6 +523,7 @@ def _create_group_chat_manager_factory(
self._selector_func,
self._max_selector_attempts,
self._candidate_func,
self._streaming,
)

def _to_config(self) -> SelectorGroupChatConfig:
Expand Down