Class SupervisorAgent
java.lang.Object
com.tnsai.coordination.supervisor.SupervisorAgent
Wraps an AgentGroup and applies guardrails to all member actions.
SupervisorAgent acts as a policy enforcement layer on top of an AgentGroup. Before any member action is executed, all registered guardrails are checked. If any guardrail blocks the action, the overall result is blocked.
Usage Example
AgentGroup group = DefaultAgentGroup.builder()
.name("Research Team")
.build();
SupervisorAgent supervisor = new SupervisorAgent(group, List.of(
new HITLApproval(Set.of("deploy"), callback),
myCustomGuardrail
));
// Check action before executing
GuardrailResult result = supervisor.checkAction("agent-1", "deploy", Map.of());
if (result.allowed()) {
// proceed with action
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSupervisorAgent(com.tnsai.agents.groups.AgentGroup group) Creates a new SupervisorAgent with no initial guardrails.SupervisorAgent(com.tnsai.agents.groups.AgentGroup group, List<Guardrail> guardrails) Creates a new SupervisorAgent wrapping the given group with the specified guardrails. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGuardrail(Guardrail guardrail) Adds a guardrail to the supervisor.Checks an action against all registered guardrails.com.tnsai.agents.groups.AgentGroupgetGroup()Returns the supervised group.Returns an unmodifiable view of the registered guardrails.voidremoveGuardrail(String name) Removes a guardrail by name.
-
Constructor Details
-
SupervisorAgent
Creates a new SupervisorAgent wrapping the given group with the specified guardrails.- Parameters:
group- the agent group to superviseguardrails- initial list of guardrails to apply- Throws:
NullPointerException- if group or guardrails is null
-
SupervisorAgent
public SupervisorAgent(com.tnsai.agents.groups.AgentGroup group) Creates a new SupervisorAgent with no initial guardrails.- Parameters:
group- the agent group to supervise- Throws:
NullPointerException- if group is null
-
-
Method Details
-
checkAction
public Guardrail.GuardrailResult checkAction(String agentId, String action, Map<String, Object> context) Checks an action against all registered guardrails.Guardrails are evaluated in order. If any guardrail blocks the action, evaluation stops and the blocking result is returned. If all guardrails allow the action, the result from the last guardrail is returned (or a default "allowed" result if no guardrails are registered).
- Parameters:
agentId- the ID of the agent attempting the actionaction- the action being attemptedcontext- additional context about the action- Returns:
- the combined guardrail result
- Throws:
NullPointerException- if agentId or action is null
-
addGuardrail
Adds a guardrail to the supervisor.- Parameters:
guardrail- the guardrail to add- Throws:
NullPointerException- if guardrail is null
-
removeGuardrail
Removes a guardrail by name.- Parameters:
name- the name of the guardrail to remove- Throws:
NullPointerException- if name is null
-
getGuardrails
Returns an unmodifiable view of the registered guardrails.- Returns:
- list of guardrails
-
getGroup
public com.tnsai.agents.groups.AgentGroup getGroup()Returns the supervised group.- Returns:
- the agent group
-