-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load and Save state in AgentChat (#4436)
1. convert dataclass types to pydantic basemodel 2. add save_state and load_state for ChatAgent 3. state types for AgentChat --------- Co-authored-by: Eric Zhu <[email protected]>
- Loading branch information
1 parent
fef06fd
commit 777f2ab
Showing
39 changed files
with
3,684 additions
and
2,964 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
python/packages/autogen-agentchat/src/autogen_agentchat/state/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""State management for agents, teams and termination conditions.""" | ||
|
||
from ._states import ( | ||
AssistantAgentState, | ||
BaseGroupChatManagerState, | ||
BaseState, | ||
ChatAgentContainerState, | ||
MagenticOneOrchestratorState, | ||
RoundRobinManagerState, | ||
SelectorManagerState, | ||
SwarmManagerState, | ||
TeamState, | ||
) | ||
|
||
__all__ = [ | ||
"BaseState", | ||
"AssistantAgentState", | ||
"BaseGroupChatManagerState", | ||
"ChatAgentContainerState", | ||
"RoundRobinManagerState", | ||
"SelectorManagerState", | ||
"SwarmManagerState", | ||
"MagenticOneOrchestratorState", | ||
"TeamState", | ||
] |
81 changes: 81 additions & 0 deletions
81
python/packages/autogen-agentchat/src/autogen_agentchat/state/_states.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from typing import Any, List, Mapping, Optional | ||
|
||
from autogen_core.components.models import ( | ||
LLMMessage, | ||
) | ||
from pydantic import BaseModel, Field | ||
|
||
from ..messages import ( | ||
AgentMessage, | ||
ChatMessage, | ||
) | ||
|
||
|
||
class BaseState(BaseModel): | ||
"""Base class for all saveable state""" | ||
|
||
type: str = Field(default="BaseState") | ||
version: str = Field(default="1.0.0") | ||
|
||
|
||
class AssistantAgentState(BaseState): | ||
"""State for an assistant agent.""" | ||
|
||
llm_messages: List[LLMMessage] = Field(default_factory=list) | ||
type: str = Field(default="AssistantAgentState") | ||
|
||
|
||
class TeamState(BaseState): | ||
"""State for a team of agents.""" | ||
|
||
agent_states: Mapping[str, Any] = Field(default_factory=dict) | ||
team_id: str = Field(default="") | ||
type: str = Field(default="TeamState") | ||
|
||
|
||
class BaseGroupChatManagerState(BaseState): | ||
"""Base state for all group chat managers.""" | ||
|
||
message_thread: List[AgentMessage] = Field(default_factory=list) | ||
current_turn: int = Field(default=0) | ||
type: str = Field(default="BaseGroupChatManagerState") | ||
|
||
|
||
class ChatAgentContainerState(BaseState): | ||
"""State for a container of chat agents.""" | ||
|
||
agent_state: Mapping[str, Any] = Field(default_factory=dict) | ||
message_buffer: List[ChatMessage] = Field(default_factory=list) | ||
type: str = Field(default="ChatAgentContainerState") | ||
|
||
|
||
class RoundRobinManagerState(BaseGroupChatManagerState): | ||
"""State for :class:`~autogen_agentchat.teams.RoundRobinGroupChat` manager.""" | ||
|
||
next_speaker_index: int = Field(default=0) | ||
type: str = Field(default="RoundRobinManagerState") | ||
|
||
|
||
class SelectorManagerState(BaseGroupChatManagerState): | ||
"""State for :class:`~autogen_agentchat.teams.SelectorGroupChat` manager.""" | ||
|
||
previous_speaker: Optional[str] = Field(default=None) | ||
type: str = Field(default="SelectorManagerState") | ||
|
||
|
||
class SwarmManagerState(BaseGroupChatManagerState): | ||
"""State for :class:`~autogen_agentchat.teams.Swarm` manager.""" | ||
|
||
current_speaker: str = Field(default="") | ||
type: str = Field(default="SwarmManagerState") | ||
|
||
|
||
class MagenticOneOrchestratorState(BaseGroupChatManagerState): | ||
"""State for :class:`~autogen_agentchat.teams.MagneticOneGroupChat` orchestrator.""" | ||
|
||
task: str = Field(default="") | ||
facts: str = Field(default="") | ||
plan: str = Field(default="") | ||
n_rounds: int = Field(default=0) | ||
n_stalls: int = Field(default=0) | ||
type: str = Field(default="MagenticOneOrchestratorState") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.