Class ReactAgent


public class ReactAgent extends BaseAgent
  • Constructor Details

  • Method Details

    • builder

      public static Builder builder()
    • builder

      public static Builder builder(AgentBuilderFactory agentBuilderFactory)
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(String message) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(String message, RunnableConfig config) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(org.springframework.ai.chat.messages.UserMessage message) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(List<org.springframework.ai.chat.messages.Message> messages) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) throws GraphRunnerException
      Throws:
      GraphRunnerException
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(Map<String,Object> inputs) throws GraphRunnerException
      Calls the agent with the given inputs map and returns the assistant message.

      When you need to pass additional parameters beyond messages and input, use this overload.

      Reserved keys: messages and input are used as question/input for the agent. Other keys can be arbitrary and are passed as graph state, e.g. for prompt placeholders or any other state values.

      Parameters:
      inputs - the input map (reserved: messages, input; other keys as state)
      Returns:
      the assistant message response
      Throws:
      GraphRunnerException - if the graph execution fails
    • call

      public org.springframework.ai.chat.messages.AssistantMessage call(Map<String,Object> inputs, RunnableConfig config) throws GraphRunnerException
      Calls the agent with the given inputs map and runtime config, returns the assistant message.

      When you need to pass additional parameters beyond messages and input, use this overload.

      Reserved keys: messages and input are used as question/input for the agent. Other keys can be arbitrary and are passed as graph state, e.g. for prompt placeholders or any other state values.

      Parameters:
      inputs - the input map (reserved: messages, input; other keys as state)
      config - runtime configuration controlling execution behavior
      Returns:
      the assistant message response
      Throws:
      GraphRunnerException - if the graph execution fails
    • interrupt

      public void interrupt(RunnableConfig config)
    • interrupt

      public void interrupt(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config)
    • interrupt

      public void interrupt(String userMessage, RunnableConfig config)
    • updateAgentState

      public void updateAgentState(Object state, RunnableConfig config)
      Updates the agent thread state with interruption feedback. This method is thread-safe and can be called concurrently with apply() in InterruptionHook. Thread-safety guarantees: - threadIdStateMap is a ConcurrentHashMap, ensuring thread-safe access - computeIfAbsent ensures atomic creation of the inner map if it doesn't exist - The inner map is always a ConcurrentHashMap, ensuring thread-safe put() operations Concurrency behavior: - If called before apply() processes feedback: the new value will be processed - If called after apply() removes feedback: the new value will be set for next iteration - If called concurrently with apply(): the atomic operations ensure no data loss
    • getStateGraph

      public StateGraph getStateGraph()
    • getCompiledGraph

      public CompiledGraph getCompiledGraph()
    • asNode

      public Node asNode(boolean includeContents, boolean returnReasoningContents)
      Specified by:
      asNode in class BaseAgent
    • initGraph

      protected StateGraph initGraph() throws GraphStateException
      Specified by:
      initGraph in class Agent
      Throws:
      GraphStateException
    • instruction

      public String instruction()
    • setInstruction

      public void setInstruction(String instruction)
    • setSystemPrompt

      public void setSystemPrompt(String systemPrompt)
    • getThreadState

      public Map<String,Object> getThreadState(String threadId)