AgentDescriptionGuard
autogen.AgentDescriptionGuard #
Manages soft-signal description mutation for LLM-based speaker selection.
Wraps an agent via composition and toggles an [UNAVAILABLE] prefix on its description so that LLM-based auto-selection is less likely to choose it when it is unavailable (e.g. circuit breaker open). Restore on recovery.
Warning
This guard owns the [UNAVAILABLE] prefix on agent.description. External code may modify the description between mark_unavailable and mark_available calls -- those changes are preserved. However, if external code adds or removes the [UNAVAILABLE] prefix itself, the guard's state becomes inconsistent.
Source code in autogen/agentchat/eligibility_policy.py
mark_unavailable #
Prepend [UNAVAILABLE] to agent.description (idempotent, thread-safe).
Note
If agent.description is None, it is treated as "" for the prefix but the original None value is remembered and restored by :meth:mark_available.
Source code in autogen/agentchat/eligibility_policy.py
mark_available #
Strip [UNAVAILABLE] prefix from description (thread-safe).
If the current agent.description does not start with the [UNAVAILABLE] prefix this is a no-op. Otherwise, the prefix is stripped and the description is restored to the value it held at the time :meth:mark_unavailable was called. Any modifications made to the suffix after the prefix (e.g. by external code appending text) are preserved: the prefix is stripped from the live value, not replaced wholesale.
Note
The check is structural (prefix present or absent) rather than based on internal guard state. If another source added the [UNAVAILABLE] prefix without going through this guard instance, calling this method will strip it -- see the class-level Warning for details on multi-guard scenarios.