Class ReactiveThinker<A extends ChatAnswer>
- Type Parameters:
A- the class of the answer each exchange ends with
- All Implemented Interfaces:
GuardedExecution, ScopeAuthority, ArtifactRegistryAware, ConversationCarrier, Identifiable, Job<VoidThinkerOutput>, ModelDependent, ModelDependentTool<VoidThinkerInput, VoidThinkerOutput>, Orchestrator<VoidThinkerInput, VoidThinkerOutput>, Thinker<VoidThinkerInput, VoidThinkerOutput>, Tool<VoidThinkerInput, VoidThinkerOutput>
- Direct Known Subclasses:
ChatThinker
A turn is a burst of work over a durable conversation: it drains its inbox,
processing each message through potentially multiple LLM iterations with tool
execution, and completes the moment the inbox is empty at an idle boundary.
Messages sent while an exchange is running are injected at the next iteration
boundary so the model can be steered mid-task; a message arriving after the
turn has committed its close is refused (addMessage(String) returns false)
and the caller starts a fresh turn that resumes the conversation from
ConversationService. An exchange that fails FAILS the turn: the
conversation is rolled back and its marker saved, the failure event published,
and then the failure propagates - the job ends FAILED carrying the cause,
never a completed thinker over an exchange that produced nothing. The next
message starts a fresh turn over the saved conversation, so failing loudly
costs no continuity.
Note: Reactive thinkers don't use structured input.
They process messages added via addMessage(String).
The answer. Each exchange ends with an object of the answer class the thinker
was constructed with, a ChatAnswer or a subclass of it. The model selects the
artifacts that leave with the answer, by naming them in artifact_refs or writing
their references in a field; those are taken from the conversation's registry and no
other artifact is handed to streamResponse(A, JobContext).
- Since:
- 0.1 (2025-10-14)
- Author:
- Andrey Santrosyan
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractThinker
AbstractThinker.CompactedReply<R>, AbstractThinker.ModelCall<R> -
Field Summary
Fields inherited from class AbstractThinker
cacheAllMessages, comfortContextTokens, compactionTrigger, conversationId, grade, interactive, invokedAsTool, OBS_ARTIFACTS_IN, OBS_ARTIFACTS_OUT, outputDeclaration, role, TASK_OBJECTIVE_KEY, toolRegistryFields inherited from class AbstractOrchestrator
META_ITERATIONFields inherited from class AbstractTool
inputFields inherited from class AbstractJob
timeout, upstreamRetriesFields inherited from interface Job
DEFAULT_UPSTREAM_RETRIESFields inherited from interface Tool
OBS_INPUT, OBS_OUTPUT -
Constructor Summary
ConstructorsModifierConstructorDescriptionReactiveThinker(Identifiable parent, ThinkerDeclaration declaration, Class<A> answerClass) Creates a reactive thinker.protectedReactiveThinker(Identifiable parent, ThinkerDeclaration declaration, Class<A> answerClass, boolean forceReadOnly) Chat-shaped thinker bound to tools that change nothing - a conversational surface that can answer about a corpus but cannot act on it. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddMessage(String message) Offers a message to the running turn.execute(JobContext<VoidThinkerOutput> context) The backstop half of the inbox invariant: a turn that dies before its conversation is acquired never entersrunThinkingLoop(ConversationContext, JobContext), so its finally cannot close the inbox.getDepth()How much effort this thinker's calls ask for: its input's depth for a goal-directed thinker, its declared field for a reactive one.protected VoidThinkerOutputGets the final result - subclass specific.protected abstract voidinitializeConversation(ConversationContext conversation, JobContext<VoidThinkerOutput> context) Initializes the conversation at the start of the loop.protected voidprocessMessage(String message, ConversationContext conversation, JobContext<VoidThinkerOutput> context) Processes a message through LLM iterations with tool support.protected voidrunThinkingLoop(ConversationContext conversation, JobContext<VoidThinkerOutput> context) Runs the main thinking loop - subclass specific implementation.voidDeclares this seat's effort; see the field.voidsetMaxIterationsPerMessage(int maxIterationsPerMessage) The tool-call budget for answering ONE user message.protected voidstreamResponse(A answer, JobContext<VoidThinkerOutput> context) Hands an exchange's answer to whoever is waiting for it.Methods inherited from class AbstractThinker
addTool, addTool, admitConfiguredSkills, appendCorrection, buildToolDefinitionBlocks, cacheAllMessages, compactAndRetry, correctableFailureAppended, declareCompatibleSkills, declareCompatibleTools, declareDefaultProviders, declareDefaultSkills, declareDefaultTools, declareValidationGuardrails, delegationThreshold, executeTools, forceCompaction, getArtifactRegistry, getConversationId, getFinalRetainDuration, getGrade, getOutputDeclaration, getProviders, getRetainDuration, getRole, getTools, hasTool, hasTool, isConversationMinted, isForceReadOnly, isInteractive, isInvokedAsTool, mintConversationId, newLLMCall, performCompactionLoop, pinModel, pinnedModel, reconcileCatalog, reconcileSkillCatalog, reconcileToolRegistry, removeTool, removeTool, setArtifactRegistry, setCacheAllMessages, setComfortContextTokens, setCompactionTrigger, setConversationId, setFinalRetainDuration, setGrade, setInvokedAsTool, setOutputBudget, setOutputSize, setRetainDuration, subAgentsWorkOneLevelBelow, submitToolCall, transcript, validateToolCallMethods inherited from class AbstractOrchestrator
execute, getJobType, getRequirements, getScopeGuard, getTimeout, sealScopeGuard, setScopeGuard, setTimeout, submitInIteration, submitInIteration, submitInIterationMethods inherited from class AbstractTool
getInput, postExecute, preExecute, setInputMethods inherited from class AbstractJob
getId, getName, getParentJobId, getPriority, getUpstreamRetries, getUserId, getWorkflowId, randomIdSuffix, setUpstreamRetries, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface GuardedExecution
declareAdmissionGuardrails, declareAuthGuardrails, declareContentGuardrailsMethods inherited from interface Identifiable
getParentJobId, getUserId, getWorkflowIdMethods inherited from interface Job
getDisplayName, getId, getJobId, getJobType, getName, getPriority, getRequirements, getTimeout, getUpstreamRetries, postExecute, preExecuteMethods inherited from interface ModelDependent
requireSeatMethods inherited from interface ScopeAuthority
getScopeGuard, sealScopeGuard, setScopeGuardMethods inherited from interface Tool
execute, getInput, guardedInputTarget, setInput
-
Constructor Details
-
ReactiveThinker
Creates a reactive thinker. This is the REQUIRED constructor for all tools.Interactive by construction: a human is waiting on every answer. The declaration is the subclass's, as for every thinker - a chat that wants the best model the deployment serves declares
Grade.CEILING, a reactive shape with a narrower job states its own rung.- Parameters:
parent- the parent identity for lineage trackinganswerClass- the class of the answer each exchange ends with:ChatAnswer, or a subclass of it when the application's answer has fields of its own
-
ReactiveThinker
protected ReactiveThinker(Identifiable parent, ThinkerDeclaration declaration, Class<A> answerClass, boolean forceReadOnly) Chat-shaped thinker bound to tools that change nothing - a conversational surface that can answer about a corpus but cannot act on it. SeeAbstractThinker(Identifiable, ThinkerDeclaration, boolean)for what the binding guarantees and how it travels to whatever this thinker delegates to.- Parameters:
parent- the parent identity for lineage trackinganswerClass- the class of the answer each exchange ends withforceReadOnly- true to bind this thinker to tools that change nothing
-
-
Method Details
-
execute
public VoidThinkerOutput execute(JobContext<VoidThinkerOutput> context) throws LLMReadableCheckedException The backstop half of the inbox invariant: a turn that dies before its conversation is acquired never entersrunThinkingLoop(ConversationContext, JobContext), so its finally cannot close the inbox. No holder exists on that path, so ordering against the release is moot and the idempotent close here suffices.- Overrides:
executein classAbstractThinker<VoidThinkerInput, VoidThinkerOutput>- Parameters:
context- the job context for progress reporting and cancellation- Returns:
- the result of the coordinator's work
- Throws:
LLMReadableCheckedException- if coordination fails
-
runThinkingLoop
protected void runThinkingLoop(ConversationContext conversation, JobContext<VoidThinkerOutput> context) throws LLMReadableCheckedException Description copied from class:AbstractThinkerRuns the main thinking loop - subclass specific implementation.- Specified by:
runThinkingLoopin classAbstractThinker<VoidThinkerInput, VoidThinkerOutput>- Parameters:
conversation- the conversation context with messagescontext- the job context for progress and events- Throws:
LLMReadableCheckedException- if processing fails
-
addMessage
Offers a message to the running turn.Returns false when the turn has committed its close (or the message is blank - callers pre-filter blanks, so to a well-behaved caller false means exactly "this turn is over: resume the conversation with a new turn").
- Parameters:
message- the message to add- Returns:
- true if the running turn will process the message
-
getResult
Description copied from class:AbstractThinkerGets the final result - subclass specific.- Specified by:
getResultin classAbstractThinker<VoidThinkerInput, VoidThinkerOutput>- Returns:
- the result of type O, or null if no result
-
initializeConversation
protected abstract void initializeConversation(ConversationContext conversation, JobContext<VoidThinkerOutput> context) Initializes the conversation at the start of the loop.- Parameters:
conversation- the conversation contextcontext- the job context
-
processMessage
protected void processMessage(String message, ConversationContext conversation, JobContext<VoidThinkerOutput> context) throws Exception Processes a message through LLM iterations with tool support.- Parameters:
message- the message to processconversation- the conversation contextcontext- the job context- Throws:
Exception- if processing fails
-
setMaxIterationsPerMessage
public void setMaxIterationsPerMessage(int maxIterationsPerMessage) The tool-call budget for answering ONE user message. When it runs out, one additional closing call is made that must answer from the gathered evidence. -
setDepth
Declares this seat's effort; see the field. -
getDepth
-
streamResponse
Hands an exchange's answer to whoever is waiting for it. The answer arrives with the artifacts it selected already taken from the conversation's registry (ThinkerOutput.getArtifacts()). The default implementation logs the start of the text; a subclass overrides to publish the answer.- Parameters:
answer- the answer, its selected artifacts resolvedcontext- the job context
-