类 PostReasoningEvent


public final class PostReasoningEvent extends ReasoningEvent
Event fired after LLM reasoning completes.

Modifiable: Yes - setReasoningMessage(Msg)

Context:

Note: Message content may include text blocks, thinking blocks, and tool use blocks. You can modify any of these before the agent processes tool calls.

Use Cases:

  • Filter or modify tool calls before execution
  • Add/remove content blocks
  • Modify text or thinking content
  • Add metadata
  • Request to stop the agent for human review via stopAgent()
  • 构造器详细资料

    • PostReasoningEvent

      public PostReasoningEvent(Agent agent, String modelName, GenerateOptions generateOptions, Msg reasoningMessage)
      Constructor for PostReasoningEvent.
      参数:
      agent - The agent instance (must not be null)
      modelName - The model name (must not be null)
      generateOptions - The generation options (may be null)
      reasoningMessage - The reasoning result message (may be null)
  • 方法详细资料

    • getReasoningMessage

      public Msg getReasoningMessage()
      Get the reasoning result message from LLM.
      返回:
      The reasoning message, may be null
    • setReasoningMessage

      public void setReasoningMessage(Msg reasoningMessage)
      Modify the reasoning result message.
      参数:
      reasoningMessage - The new reasoning message
    • stopAgent

      public void stopAgent()
      Request to stop the agent after this reasoning phase.

      When called, the agent will return the current message containing ToolUseBlocks instead of proceeding to execute the tools. The user can then review the pending tool calls and resume execution by calling agent.call() with no arguments.

      This enables human-in-the-loop scenarios where sensitive or important tool calls need user confirmation before execution.

    • isStopRequested

      public boolean isStopRequested()
      Check if a stop has been requested.
      返回:
      true if stopAgent() has been called, false otherwise
    • gotoReasoning

      public void gotoReasoning()
      Request to go back to reasoning phase without adding any messages.

      This is only valid when there are no pending ToolUse blocks in the reasoning message. If there are pending ToolUse blocks, an IllegalStateException will be thrown because ToolResult messages must be provided first.

      抛出:
      IllegalStateException - if there are pending ToolUse blocks
    • gotoReasoning

      public void gotoReasoning(Msg msg)
      Request to go back to reasoning phase with a single message.

      If the reasoning message contains ToolUse blocks, the provided message must contain matching ToolResult blocks. Additional messages (like hints or prompts) can also be included.

      参数:
      msg - The message to add to memory before reasoning (e.g., ToolResult or hint message)
      抛出:
      IllegalStateException - if ToolResult validation fails
    • gotoReasoning

      public void gotoReasoning(List<Msg> msgs)
      Request to go back to reasoning phase with multiple messages.

      Validation rules:

      • If no pending ToolUse: messages are added as-is (can be hints/prompts)
      • If pending ToolUse: messages must contain matching ToolResult blocks
      参数:
      msgs - The messages to add to memory before reasoning
      抛出:
      IllegalStateException - if ToolResult validation fails
    • isGotoReasoningRequested

      public boolean isGotoReasoningRequested()
      Check if a goto reasoning has been requested.
      返回:
      true if any gotoReasoning method has been called, false otherwise
    • getGotoReasoningMsgs

      public List<Msg> getGotoReasoningMsgs()
      Get the messages to add before going back to reasoning.
      返回:
      The messages to add, or null if gotoReasoning was not called