Skip to content

RandomAgentTarget

autogen.agentchat.group.targets.transition_target.RandomAgentTarget #

RandomAgentTarget(agents, **data)

Bases: TransitionTarget

Target that represents a random selection from a list of agents.

Source code in autogen/agentchat/group/targets/transition_target.py
def __init__(self, agents: list["ConversableAgent"], **data: Any) -> None:  # type: ignore[no-untyped-def]
    # Store the name from the agent for serialization
    super().__init__(agent_names=[agent.name for agent in agents], **data)

agent_names instance-attribute #

agent_names

nominated_name class-attribute instance-attribute #

nominated_name = '<Not Randomly Selected Yet>'

can_resolve_for_speaker_selection #

can_resolve_for_speaker_selection()

Check if the target can resolve for speaker selection.

Source code in autogen/agentchat/group/targets/transition_target.py
def can_resolve_for_speaker_selection(self) -> bool:
    """Check if the target can resolve for speaker selection."""
    return True

resolve #

resolve(groupchat, current_agent, user_agent)

Resolve to the actual agent object from the groupchat, choosing a random agent (except the current one)

Source code in autogen/agentchat/group/targets/transition_target.py
def resolve(
    self,
    groupchat: "GroupChat",
    current_agent: "ConversableAgent",
    user_agent: Optional["ConversableAgent"],
) -> SpeakerSelectionResult:
    """Resolve to the actual agent object from the groupchat, choosing a random agent (except the current one)"""
    # Randomly select the next agent
    self.nominated_name = random.choice([name for name in self.agent_names if name != current_agent.name])

    return SpeakerSelectionResult(agent_name=self.nominated_name)

display_name #

display_name()

Get the display name for the target.

Source code in autogen/agentchat/group/targets/transition_target.py
def display_name(self) -> str:
    """Get the display name for the target."""
    return self.nominated_name

normalized_name #

normalized_name()

Get a normalized name for the target that has no spaces, used for function calling

Source code in autogen/agentchat/group/targets/transition_target.py
def normalized_name(self) -> str:
    """Get a normalized name for the target that has no spaces, used for function calling"""
    return self.display_name()

needs_agent_wrapper #

needs_agent_wrapper()

Check if the target needs to be wrapped in an agent.

Source code in autogen/agentchat/group/targets/transition_target.py
def needs_agent_wrapper(self) -> bool:
    """Check if the target needs to be wrapped in an agent."""
    return False

create_wrapper_agent #

create_wrapper_agent(parent_agent, index)

Create a wrapper agent for the target if needed.

Source code in autogen/agentchat/group/targets/transition_target.py
def create_wrapper_agent(self, parent_agent: "ConversableAgent", index: int) -> "ConversableAgent":
    """Create a wrapper agent for the target if needed."""
    raise NotImplementedError("RandomAgentTarget does not require wrapping in an agent.")