Class ResponseCorrection
java.lang.Object
ai.redouble.nucleo.tools.ResponseCorrection
The self-correction of one LLM exchange, shared by every job that sends a conversation
and expects a typed answer: a response that fails to parse, or parses but fails the
handler's required-field validation, is fed back to the model. The failed assistant
message is already in the conversation (clients append it); this appends a user-role
correction message carrying the error explanation and the ORIGINAL response handler,
then throws
ResponseCorrectionRetryException for the dispatcher to re-run the
job transparently on the grown conversation. The budget is 2
corrections per job instance, so it survives the dispatcher's re-runs. On exhaustion the
failure surfaces, a parse failure as JsonParseException and a missing required
field as ResponseValidationException: required is required, and no caller
receives an answer with a hole in it.- Since:
- 0.1 (2026-09-16)
- Author:
- Andrey Santrosyan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCorrection budget per job: at most this many parse/validation feedback retries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Texchange(LLMClient client, ConversationContext conversation) One exchange: the conversation's last outgoing message sent on the client, the answer parsed or corrected.intgetUsed()Corrections consumed so far by the job holding this.<T> TparseOrCorrect(LLMResponse<T> response, ConversationContext conversation, OutgoingMessage<T> outgoingMessage) The parsed answer of a response, or the correction protocol: within budget the failure becomes a correction turn and a retry signal; past it, the failure surfaces, whether the answer did not parse or lacks a required field.
-
Field Details
-
MAX_CORRECTIONS
public static final int MAX_CORRECTIONSCorrection budget per job: at most this many parse/validation feedback retries.- See Also:
-
-
Constructor Details
-
ResponseCorrection
public ResponseCorrection()
-
-
Method Details
-
getUsed
public int getUsed()Corrections consumed so far by the job holding this. -
exchange
public <T> T exchange(LLMClient client, ConversationContext conversation) throws LLMReadableCheckedException One exchange: the conversation's last outgoing message sent on the client, the answer parsed or corrected. The outgoing message is taken before the call, since the client appends the answer and the last message is no longer outgoing afterwards. What a thinker's call and a one-call tool both do, written once.- Throws:
LLMReadableCheckedException
-
parseOrCorrect
public <T> T parseOrCorrect(LLMResponse<T> response, ConversationContext conversation, OutgoingMessage<T> outgoingMessage) throws LLMReadableCheckedException The parsed answer of a response, or the correction protocol: within budget the failure becomes a correction turn and a retry signal; past it, the failure surfaces, whether the answer did not parse or lacks a required field.- Parameters:
response- what the client answeredconversation- the conversation the correction turn is appended tooutgoingMessage- the message the response answered, taken before the call, since the client appends the answer after it- Throws:
LLMReadableCheckedException
-