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

public abstract class ReactiveThinker<A extends ChatAnswer> extends AbstractThinker<VoidThinkerInput, VoidThinkerOutput>
Thinker for message-driven interactions, executed as one finite TURN.

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
  • Constructor Details

    • ReactiveThinker

      public ReactiveThinker(Identifiable parent, ThinkerDeclaration declaration, Class<A> answerClass)
      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 tracking
      answerClass - 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. See AbstractThinker(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 tracking
      answerClass - the class of the answer each exchange ends with
      forceReadOnly - true to bind this thinker to tools that change nothing
  • Method Details

    • execute

      The backstop half of the inbox invariant: a turn that dies before its conversation is acquired never enters runThinkingLoop(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:
      execute in class AbstractThinker<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: AbstractThinker
      Runs the main thinking loop - subclass specific implementation.
      Specified by:
      runThinkingLoop in class AbstractThinker<VoidThinkerInput, VoidThinkerOutput>
      Parameters:
      conversation - the conversation context with messages
      context - the job context for progress and events
      Throws:
      LLMReadableCheckedException - if processing fails
    • addMessage

      public boolean addMessage(String message)
      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

      protected VoidThinkerOutput getResult()
      Description copied from class: AbstractThinker
      Gets the final result - subclass specific.
      Specified by:
      getResult in class AbstractThinker<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 context
      context - 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 process
      conversation - the conversation context
      context - 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

      public void setDepth(Depth depth)
      Declares this seat's effort; see the field.
    • getDepth

      public Depth getDepth()
      Description copied from interface: Thinker
      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. Stamped onto the conversation by ConversationService at obtain time, next to the grade.
    • streamResponse

      protected void streamResponse(A answer, JobContext<VoidThinkerOutput> context)
      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 resolved
      context - the job context