OnContextCondition
autogen.OnContextCondition dataclass
#
Defines a condition for transitioning to another agent or nested chats using context variables and the ContextExpression class.
This is for context variable-based condition evaluation (does not use the agent's LLM).
These are evaluated before the OnCondition and 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: |
condition | The condition for transitioning to the target agent, evaluated by the LLM. If a string, it needs to represent a context variable key and the value will be evaluated as a boolean If a ContextExpression, it will evaluate the logical expression against the context variables. If it is True, the transition will occur. 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'") TYPE: |
available | Optional condition to determine if this OnContextCondition 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 (>, <, >=, <=, ==, !=). The Callable signature is: def my_available_func(agent: ConversableAgent, messages: list[Dict[str, Any]]) -> bool TYPE: |