Package com.tnsai.communication
Class CommunicationEnforcer
java.lang.Object
com.tnsai.communication.CommunicationEnforcer
Enforces communication policies defined via @Communication annotation.
This class handles runtime enforcement of:
- Language restrictions (responses must be in allowed languages)
- Response length limits
- Response format validation
Usage
CommunicationEnforcer enforcer = new CommunicationEnforcer();
// Get system prompt constraints
String constraints = enforcer.buildConstraintsPrompt(role);
// Validate response
enforcer.validateResponse(role, response);
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildConstraintsPrompt(Role role) Builds a system prompt section that describes communication constraints.truncateIfNeeded(Role role, String response) Truncates response to max length if needed.voidvalidateResponse(Role role, String response) Validates a response against communication constraints.
-
Constructor Details
-
CommunicationEnforcer
public CommunicationEnforcer()
-
-
Method Details
-
buildConstraintsPrompt
Builds a system prompt section that describes communication constraints.- Parameters:
role- the role with communication settings- Returns:
- constraint description for system prompt
-
validateResponse
Validates a response against communication constraints.- Parameters:
role- the role with communication settingsresponse- the response to validate- Throws:
CommunicationViolationException- if validation fails
-
truncateIfNeeded
Truncates response to max length if needed.- Parameters:
role- the role with communication settingsresponse- the response to truncate- Returns:
- truncated response
-