Elemental | Documentation
Agent Selection

Agent Selection

Agent selection is central point in the multi-agent conversation. When agent tries to handover the task execution to another agent we employ AgentSelector. The purpose of this object is to keep track of all agents involved in the conversation and upon request provide which agent should continue based on pre-selected criteria.

class AgentSelectorParameters(BaseModel):
    """
    Parameters for the agent selector.
    """

    agents: Dict[str, AgentExecutor]
    last_message: str | None = None
    execution_order: Optional[List[str]] = None

Agent selection is simple concept, however, it allows to design many agentic execution patterns. Every selector object is initialized with the information about the lead agent. This indicates an execution leading in terms of starting the work on a task with this agent and using it always as a fallback agent in case selection arguments are not reliable to process. Agent selectors follow this interface:

class AgentSelector(ABC):

    def __init__(
            self, 
            lead_agent: AgentExecutor
        ) -> None:
        """
        Initialize the agent selector with the 
        lead agent.
        """

        self._lead_agent = lead_agent
        self._current_agent = None

    @abstractmethod
    def select(
            self, 
            parameters: AgentSelectorParameters
        ) -> AgentExecutor:
        """
        Select an agent to execute the instruction 
        based on the instruction itself.
        """

Several different selection strategies are provided and may be used in different workflows.

  • ConversationalSelector - Select an agent to execute the instruction based on the last message received and <next> section with @AgentName tag. This method falls back to the lead agent if the last message provides invalid input for conversational pattern.
  • IdentitySelector - This selector always selects the lead agent.
  • IterativeSelector - Select next agent based of the list provided in the workflow configuration and cycle through the elements of this list.