Skip to content

OnCondition

autogen.OnCondition dataclass #

OnCondition(target=None, condition=None, available=None)

Defines a condition for transitioning to another agent or nested chats.

This is for LLM-based condition evaluation where these conditions are translated into tools and attached to the agent.

These are evaluated after the OnCondition conditions but before the AfterWork conditions.

PARAMETER DESCRIPTION
target

The agent to hand off to or the nested chat configuration. Can be a ConversableAgent or a Dict. If a Dict, it should follow the convention of the nested chat configuration, with the exception of a carryover configuration which is unique to Swarms. Swarm Nested chat documentation: https://docs.ag2.ai/docs/user-guide/advanced-concepts/swarm-deep-dive#registering-handoffs-to-a-nested-chat

TYPE: Optional[Union[ConversableAgent, dict[str, Any]]] DEFAULT: None

condition

The condition for transitioning to the target agent, evaluated by the LLM. If a string or Callable, no automatic context variable substitution occurs. If a ContextStr, context variable substitution occurs. The Callable signature is: def my_condition_string(agent: ConversableAgent, messages: list[Dict[str, Any]]) -> str

TYPE: Optional[Union[str, ContextStr, Callable[[ConversableAgent, list[dict[str, Any]]], str]]] DEFAULT: None

available

Optional condition to determine if this OnCondition is included for the LLM to evaluate. If a string, it will look up the value of the context variable with that name, which should be a bool, to determine whether it should include this condition. If a ContextExpression, it will evaluate the logical expression against the context variables. Can use not, and, or, and comparison operators (>, <, >=, <=, ==, !=). Example: ContextExpression("not(${logged_in} and ${is_admin}) or (${guest_checkout})") Example with comparison: ContextExpression("${attempts} >= 3 or ${is_premium} == True or ${tier} == 'gold'") The Callable signature is: def my_available_func(agent: ConversableAgent, messages: list[Dict[str, Any]]) -> bool

TYPE: Optional[Union[Callable[[ConversableAgent, list[dict[str, Any]]], bool], str, ContextExpression]] DEFAULT: None

target class-attribute instance-attribute #

target = None

condition class-attribute instance-attribute #

condition = None

available class-attribute instance-attribute #

available = None