-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load and Save state in AgentChat #4436
Conversation
I believe right now for team you can serialize the SingleThreadedAgentRuntime by calling the runtime's This will obviously change once we allow user to customize the runtime the team uses, and a runtime can be shared across multiple teams. However, this will serve as the driving force for that design. |
Not sure I understand what you mean above? Can you add some sample code to show what is meant by this? |
Each group chat team carries its own runtime currently: Lines 67 to 68 in f02aac7
The SingleThreadedAgentRuntime supports autogen/python/packages/autogen-core/src/autogen_core/application/_single_threaded_agent_runtime.py Lines 298 to 299 in f02aac7
So, from This requires implementing the autogen/python/packages/autogen-core/src/autogen_core/base/_agent.py Lines 36 to 37 in f02aac7
So this means the Besides all the agent's state, the team itself also carries some state including the team's id, which is generated in the constructor. This team id should be saved and loaded because it forms the reference to the Core agents in the runtime -- all Core agents' AgentID's key field is the team id. class BaseGroupChat(Team, ABC):
...
async def save_state(self) -> Mapping[str, Any]:
if not self._initialized:
return {"team_id": self._team_id} # If not initialized the only state we have is team id
if self._is_running:
raise RuntimeError("The group chat is currently running. It must be stopped before calling save_state()")
self._is_running = True # Prevent running the team while saving states.
runtime_state = await self._runtime.save_state()
self._is_running = False
return {"runtime_state": runtime_state, "team_id": self._team_id} There might be other stuff like |
Ah, got it. This PR certainly goes in a diff/wrong direction. Do you want to take a stab at the approach you describe above which seems a lot more straightforward (it is still way too under specified for me to explore atm, similar to the original issue). |
…runtime API for managing team state
Thanks Eric, I tested, looks good. |
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]>
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]>
Hello. How to use the team save_state feature? Currently, I am not able to use it. I got "AttributeError: 'RoundRobinGroupChat' object has no attribute 'save_state'" in 0.4.0 dev |
@lsy641 please upgrade to the latest dev release (dev11 as we speak) |
Loading and Saving State in AgentChat
This PR adds mechanisms to load/save state in AgentChat.
_model_context
. Load and save serves to populate that variable. Current changes addsload_state
andsave_state
ChatAgent (abs methods) and stub for BaseChatAgent. Introduces aBaseState
andAssistantAgentState
classload state in a new agent
Currently implemented on the
BaseGroupChat
class withload_state
andsave_state
methods. Introduces aBaseTeamState
load_state
will load each participant agent state inagent_states
andtermination_state
. All teams that inherit fromBaseGroupChat
should benefit from this OOTBNote
What this does not do:
manager_state
member ofBaseTeamState
.This can have some effects - e.g, after you load a team state, it might not know the last speaker to continue from and will begin from the first e.g. in RoundRobinGroupChat
Why are these changes needed?
Related issue number
Closes #4100
Checks