Package com.alibaba.cloud.ai.graph.agent
Class ReactAgent
java.lang.Object
com.alibaba.cloud.ai.graph.agent.Agent
com.alibaba.cloud.ai.graph.agent.BaseAgent
com.alibaba.cloud.ai.graph.agent.ReactAgent
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class com.alibaba.cloud.ai.graph.agent.BaseAgent
includeContents, inputSchema, inputType, outputKey, outputKeyStrategy, outputSchema, outputType, returnReasoningContentsFields inherited from class com.alibaba.cloud.ai.graph.agent.Agent
compileConfig, compiledGraph, description, executor, graph, name -
Constructor Summary
ConstructorsConstructorDescriptionReactAgent(AgentLlmNode llmNode, AgentToolNode toolNode, CompileConfig compileConfig, Builder builder) -
Method Summary
Modifier and TypeMethodDescriptionasNode(boolean includeContents, boolean returnReasoningContents) static Builderbuilder()static Builderbuilder(AgentBuilderFactory agentBuilderFactory) org.springframework.ai.chat.messages.AssistantMessageorg.springframework.ai.chat.messages.AssistantMessagecall(String message, RunnableConfig config) org.springframework.ai.chat.messages.AssistantMessageorg.springframework.ai.chat.messages.AssistantMessagecall(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) org.springframework.ai.chat.messages.AssistantMessageCalls the agent with the given inputs map and returns the assistant message.org.springframework.ai.chat.messages.AssistantMessagecall(Map<String, Object> inputs, RunnableConfig config) Calls the agent with the given inputs map and runtime config, returns the assistant message.org.springframework.ai.chat.messages.AssistantMessagecall(org.springframework.ai.chat.messages.UserMessage message) org.springframework.ai.chat.messages.AssistantMessagecall(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) getThreadState(String threadId) protected StateGraphvoidinterrupt(RunnableConfig config) voidinterrupt(String userMessage, RunnableConfig config) voidinterrupt(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) voidsetInstruction(String instruction) voidsetSystemPrompt(String systemPrompt) voidupdateAgentState(Object state, RunnableConfig config) Updates the agent thread state with interruption feedback.Methods inherited from class com.alibaba.cloud.ai.graph.agent.BaseAgent
asNode, getOutputKey, getOutputKeyStrategy, isIncludeContents, isReturnReasoningContents, setOutputKey, setOutputKeyStrategy, setReturnReasoningContentsMethods inherited from class com.alibaba.cloud.ai.graph.agent.Agent
applyExecutorConfig, buildMessageInput, buildNonStreamConfig, buildStreamConfig, description, doInvoke, doInvokeAndGetOutput, doStream, getAndCompileGraph, getCurrentState, getGraph, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, invokeAndGetOutput, name, schedule, schedule, stream, stream, stream, stream, stream, stream, stream, stream, streamMessages, streamMessages, streamMessages, streamMessages, streamMessages, streamMessages, streamMessages, streamMessages
-
Constructor Details
-
ReactAgent
public ReactAgent(AgentLlmNode llmNode, AgentToolNode toolNode, CompileConfig compileConfig, Builder builder)
-
-
Method Details
-
builder
-
builder
-
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 GraphRunnerExceptionCalls the agent with the given inputs map and returns the assistant message.When you need to pass additional parameters beyond
messagesandinput, use this overload.Reserved keys:
messagesandinputare 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 GraphRunnerExceptionCalls the agent with the given inputs map and runtime config, returns the assistant message.When you need to pass additional parameters beyond
messagesandinput, use this overload.Reserved keys:
messagesandinputare 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
-
interrupt
public void interrupt(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) -
interrupt
-
updateAgentState
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
-
getCompiledGraph
-
asNode
-
initGraph
- Specified by:
initGraphin classAgent- Throws:
GraphStateException
-
instruction
-
setInstruction
-
setSystemPrompt
-
getThreadState
-