Share via


SelectionStrategy Class

Base strategy class for selecting the next agent in a chat.

Note: This class is marked as 'experimental' and may change in the future.

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.

Constructor

SelectionStrategy(*, has_selected: bool = False, initial_agent: Agent | None = None)

Keyword-Only Parameters

Name Description
has_selected
Required
initial_agent
Required

Methods

next

Select the next agent to interact with.

select_agent

Determines which agent goes next. Override for custom logic.

By default, this fallback returns the first agent in the list.

next

Select the next agent to interact with.

async next(agents: list[Agent], history: list[ChatMessageContent]) -> Agent

Parameters

Name Description
agents
Required

The list of agents to select from.

history
Required

The history of messages in the conversation.

Returns

Type Description

The agent who takes the next turn.

select_agent

Determines which agent goes next. Override for custom logic.

By default, this fallback returns the first agent in the list.

async select_agent(agents: list[Agent], history: list[ChatMessageContent]) -> Agent

Parameters

Name Description
agents
Required
history
Required

Attributes

has_selected

has_selected: bool

initial_agent

initial_agent: Agent | None

is_experimental

is_experimental = True

stage_status

stage_status = 'experimental'