Skip to content

OnContextCondition

autogen.agentchat.group.on_context_condition.OnContextCondition #

Bases: BaseModel

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 after work conditions.

PARAMETER DESCRIPTION
target

The transition (essentially an agent) to hand off to.

TYPE: TransitionTarget

condition

The context variable based condition for transitioning to the target agent.

TYPE: ContextCondition

available

Optional condition to determine if this OnCondition is included for the LLM to evaluate based on context variables using classes like StringAvailableCondition and ContextExpressionAvailableCondition.

TYPE: AvailableCondition

target instance-attribute #

target

condition instance-attribute #

condition

available class-attribute instance-attribute #

available = None

has_target_type #

has_target_type(target_type)

Check if the target type matches the specified type.

PARAMETER DESCRIPTION
target_type

The target type to check against. Should be a subclass of TransitionTarget.

TYPE: type

RETURNS DESCRIPTION
bool

True if the target type matches, False otherwise

TYPE: bool

Source code in autogen/agentchat/group/on_context_condition.py
def has_target_type(self, target_type: type) -> bool:
    """
    Check if the target type matches the specified type.

    Args:
        target_type (type): The target type to check against. Should be a subclass of TransitionTarget.

    Returns:
        bool: True if the target type matches, False otherwise
    """
    return isinstance(self.target, target_type)

target_requires_wrapping #

target_requires_wrapping()

Check if the target requires wrapping in an agent.

RETURNS DESCRIPTION
bool

True if the target requires wrapping, False otherwise

TYPE: bool

Source code in autogen/agentchat/group/on_context_condition.py
def target_requires_wrapping(self) -> bool:
    """
    Check if the target requires wrapping in an agent.

    Returns:
        bool: True if the target requires wrapping, False otherwise
    """
    return self.target.needs_agent_wrapper()