microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
34.85k stars 5.05k forks source link

AgentChat agents and teams can be rolled back to snapshots of states #4100

Open ekzhu opened 2 weeks ago

ekzhu commented 2 weeks ago

What feature would you like to be added?

ChatAgent has a method save_state() that exports the internal state of the agent, and a load_state() method to bring the agent back to an existing state.

agent = AssistantAgent(...)
state = await agent.save_state()
# The state can be used to bring the agent back to an existing state. 
await agent.load_state(state)

Same with team

team = RoundRobinGroupChat(...)
state = await team.save_state()
# The team itself can be brought back to a previous state
await team.load_state(state)

Same with termination condition

termiantion = MaxMessageTermination(12)
state = await termination.save_state()
# Bring the termination condition state back.
await termination.load_state(state)

The team's state can optionally include all the participant agents' state recursively, and with that you don't need to update the agents separately.

What this doesn't solve: It is not a replacement for a complete serialization because you still need to construct the agent and team instances, and you still need to know the parameters you need to configure. The save_state and load_state methods should be used in conjunction with #4007 to perform complete serialization and deserialization.

Why is this needed?

In web services, it's desirable to not have persistent in-memory state. So, when user is idle the state is kept off the heap to allow more scaling. This requires the agents and teams to be able to save its state and rehydrate from a previous state snapshot.