41 lines
1.2 KiB
Python
Raw Normal View History

from abc import ABC, abstractmethod
from typing import Any, Mapping
from autogen_core import ComponentBase
from pydantic import BaseModel
2024-11-01 04:12:43 -07:00
from ._task import TaskRunner
class Team(ABC, TaskRunner, ComponentBase[BaseModel]):
component_type = "team"
@abstractmethod
async def reset(self) -> None:
"""Reset the team and all its participants to its initial state."""
...
feat: Pause and Resume for AgentChat Teams and Agents (#5887) 1. Add `on_pause` and `on_resume` API to `ChatAgent` to support pausing behavior when running `on_message` concurrently. 2. Add `GroupChatPause` and `GroupChatResume` RPC events and handle them in `ChatAgentContainer`. 3. Add `pause` and `resume` API to `BaseGroupChat` to allow for this behavior accessible from the public API. 4. Improve `SequentialRoutedAgent` class to customize which message types are sequentially handled, making it possible to have concurrent handling for some messages (e.g., `GroupChatPause`). 5. Added unit tests. See `test_group_chat_pause_resume.py` for how to use this feature. What is the difference between pause/resume vs. termination and restart? - Pause and resume issue direct RPC calls to the participanting agents of a team while they are running, allowing putting the on-going generation or actions on hold. This is useful when an agent's turn takes a long time and multiple steps to complete, and user/application wants to re-evaluate whether it is worth continue the step or cancel. This also allows user/application to pause individual agents and resuming them independently from the team API. - Termination and restart requires the whole team to comes to a full-stop, and termination conditions are checked in between agents' turns. So termination can only happen when no agent is working on its turn. It is possible that a termination condition has reached well before the team is terminated, if the agent is taking a long time to generate a response. Resolves: #5881
2025-03-11 17:12:34 -07:00
@abstractmethod
async def pause(self) -> None:
"""Pause the team and all its participants. This is useful for
pausing the :meth:`autogen_agentchat.base.TaskRunner.run` or
:meth:`autogen_agentchat.base.TaskRunner.run_stream` methods from
concurrently, while keeping them alive."""
...
@abstractmethod
async def resume(self) -> None:
"""Resume the team and all its participants from a pause after
:meth:`pause` was called."""
...
@abstractmethod
async def save_state(self) -> Mapping[str, Any]:
"""Save the current state of the team."""
...
@abstractmethod
async def load_state(self, state: Mapping[str, Any]) -> None:
"""Load the state of the team."""
...