Skip to content

AgentEligibilityPolicy

autogen.AgentEligibilityPolicy #

Bases: Protocol

Protocol for runtime eligibility filters in GroupChat speaker selection.

Implement this protocol to remove agents from the candidate set before the speaker selection method (auto/manual/random/round_robin) runs.

Example - always allow all agents (no-op, equivalent to no policy)::

class AllowAll:
    def is_eligible(self, agent: Agent, ctx: SelectionContext) -> bool:
        return True

Example - exclude a specific agent by name::

class ExcludeAgent:
    def __init__(self, name: str) -> None:
        self.name = name

    def is_eligible(self, agent: Agent, ctx: SelectionContext) -> bool:
        return agent.name != self.name

Multiple policies can be registered on a GroupChat; all must return True for an agent to be considered eligible (AND semantics).

Note

isinstance(obj, AgentEligibilityPolicy) only checks that is_eligible exists as an attribute -- it does not verify the method signature. A class with the wrong arity will fail at call time, not at registration.

is_eligible #

is_eligible(agent, ctx)

Return True if agent should be included in the candidate set.

PARAMETER DESCRIPTION
agent

The candidate agent being evaluated.

TYPE: Agent

ctx

Minimal context about the current selection round.

TYPE: SelectionContext

RETURNS DESCRIPTION
bool

True to keep the agent in the candidate set; False to exclude it.

Source code in autogen/agentchat/eligibility_policy.py
def is_eligible(self, agent: Agent, ctx: SelectionContext) -> bool:
    """Return True if agent should be included in the candidate set.

    Args:
        agent: The candidate agent being evaluated.
        ctx: Minimal context about the current selection round.

    Returns:
        True to keep the agent in the candidate set; False to exclude it.
    """
    ...