Skip to content

NestedChatTarget

autogen.agentchat.group.targets.transition_target.NestedChatTarget #

Bases: TransitionTarget

Target that represents a nested chat configuration.

nested_chat_config instance-attribute #

nested_chat_config

can_resolve_for_speaker_selection #

can_resolve_for_speaker_selection()

Check if the target can resolve for speaker selection. For NestedChatTarget the nested chat must be encapsulated into an agent.

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. For NestedChatTarget the nested chat must be encapsulated into an agent."""
    return False

resolve #

resolve(groupchat, current_agent, user_agent)

Resolve to the nested chat configuration.

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 nested chat configuration."""
    raise NotImplementedError(
        "NestedChatTarget does not support the resolve method. An agent should be used to encapsulate this nested chat and then the target changed to an AgentTarget."
    )

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 "a nested chat"

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 "nested_chat"

needs_agent_wrapper #

needs_agent_wrapper()

Check if the target needs to be wrapped in an agent. NestedChatTarget must 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. NestedChatTarget must be wrapped in an agent."""
    return True

create_wrapper_agent #

create_wrapper_agent(parent_agent, index)

Create a wrapper agent for the nested chat.

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 nested chat."""
    from ...conversable_agent import ConversableAgent  # to avoid circular import - NEED SOLUTION

    nested_chat_agent = ConversableAgent(name=f"{__AGENT_WRAPPER_PREFIX__}nested_{parent_agent.name}_{index + 1}")

    nested_chat_agent.register_nested_chats(
        self.nested_chat_config["chat_queue"],
        reply_func_from_nested_chats=self.nested_chat_config.get("reply_func_from_nested_chats")
        or "summary_from_nested_chats",
        config=self.nested_chat_config.get("config"),
        trigger=lambda sender: True,
        position=0,
        use_async=self.nested_chat_config.get("use_async", False),
    )

    # After the nested chat is complete, transfer back to the parent agent
    nested_chat_agent.handoffs.set_after_work(AgentTarget(parent_agent))

    return nested_chat_agent