Handoffs

Handoffs(**data: Any)

Container for all handoff transition conditions of a ConversableAgent.
Three types of conditions can be added, each with a different order and time of use:
1. OnContextConditions (evaluated without an LLM) 2. OnConditions (evaluated with an LLM) 3. After work TransitionTarget (if no other transition is triggered)

Supports method chaining:
agent.handoffs.add_context_conditions([condition1]) .add_llm_condition(condition2) .set_after_work(after_work)

Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.

Parameters:
NameDescription
**dataType: Any

Class Attributes

after_work



context_conditions



llm_conditions



model_config



Instance Methods

add

add(self, condition: OnContextCondition | OnCondition) -> Handoffs

Add a single condition (OnContextCondition or OnCondition).

Parameters:
NameDescription
conditionThe condition to add (OnContextCondition or OnCondition)

Type: OnContextCondition | OnCondition
Returns:
TypeDescription
HandoffsSelf for method chaining

add_context_condition

add_context_condition(self, condition: OnContextCondition) -> Handoffs

Add a single context condition.

Parameters:
NameDescription
conditionThe OnContextCondition to add

Type: OnContextCondition
Returns:
TypeDescription
HandoffsSelf for method chaining

add_context_conditions

add_context_conditions(self, conditions: list[OnContextCondition]) -> Handoffs

Add multiple context conditions.

Parameters:
NameDescription
conditionsList of OnContextConditions to add

Type: list[OnContextCondition]
Returns:
TypeDescription
HandoffsSelf for method chaining

add_llm_condition

add_llm_condition(self, condition: OnCondition) -> Handoffs

Add a single LLM condition.

Parameters:
NameDescription
conditionThe OnCondition to add

Type: OnCondition
Returns:
TypeDescription
HandoffsSelf for method chaining

add_llm_conditions

add_llm_conditions(self, conditions: list[OnCondition]) -> Handoffs

Add multiple LLM conditions.

Parameters:
NameDescription
conditionsList of OnConditions to add

Type: list[OnCondition]
Returns:
TypeDescription
HandoffsSelf for method chaining

add_many

add_many(self, conditions: list[OnContextCondition | OnCondition]) -> Handoffs

Add multiple conditions of any supported types (OnContextCondition and OnCondition).

Parameters:
NameDescription
conditionsList of conditions to add

Type: list[OnContextCondition | OnCondition]
Returns:
TypeDescription
HandoffsSelf for method chaining

clear

clear(self) -> Handoffs

Clear all handoff conditions.
Returns:
Self for method chaining

Returns:
TypeDescription
HandoffsSelf for method chaining

get_context_conditions_by_target_type

get_context_conditions_by_target_type(self, target_type: type) -> list[OnContextCondition]

Get OnContextConditions for a specific target type.

Parameters:
NameDescription
target_typeThe type of condition to retrieve

Type: type
Returns:
TypeDescription
list[OnContextCondition]List of conditions of the specified type, or None if none exist

get_context_conditions_requiring_wrapping

get_context_conditions_requiring_wrapping(self) -> list[OnContextCondition]

Get context conditions that have targets that require wrapping.
Returns:
List of context conditions that require wrapping

Returns:
TypeDescription
list[OnContextCondition]List of context conditions that require wrapping

get_llm_conditions_by_target_type

get_llm_conditions_by_target_type(self, target_type: type) -> list[OnCondition]

Get OnConditions for a specific target type.

Parameters:
NameDescription
target_typeThe type of condition to retrieve

Type: type
Returns:
TypeDescription
list[OnCondition]List of conditions of the specified type, or None if none exist

get_llm_conditions_requiring_wrapping

get_llm_conditions_requiring_wrapping(self) -> list[OnCondition]

Get LLM conditions that have targets that require wrapping.
Returns:
List of LLM conditions that require wrapping

Returns:
TypeDescription
list[OnCondition]List of LLM conditions that require wrapping

set_after_work

set_after_work(self, target: TransitionTarget) -> Handoffs

Set the after work target (only one allowed).

Parameters:
NameDescription
targetThe after work TransitionTarget to set

Type: TransitionTarget
Returns:
TypeDescription
HandoffsSelf for method chaining

set_llm_function_names

set_llm_function_names(self) -> None

Set the LLM function names for all LLM conditions, creating unique names for each function.