Class Agent
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CompileConfigprotected CompiledGraphprotected StringOne line description about the agent's capability.protected Executorprotected StateGraphprotected StringThe agent's name. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidApplies executor configuration to the RunnableConfig builder.buildMessageInput(Object message) protected RunnableConfigbuildNonStreamConfig(RunnableConfig config) protected RunnableConfigbuildStreamConfig(RunnableConfig config) Gets the one-line description of the agent's capability.protected Optional<OverAllState>doInvoke(Map<String, Object> input, RunnableConfig runnableConfig) protected Optional<NodeOutput>doInvokeAndGetOutput(Map<String, Object> input, RunnableConfig runnableConfig) protected reactor.core.publisher.Flux<NodeOutput>doStream(Map<String, Object> input, RunnableConfig runnableConfig) getCurrentState(RunnableConfig config) getGraph()protected abstract StateGraphinvoke(String message, RunnableConfig config) invoke(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) Invokes the agent with the given inputs map.invoke(Map<String, Object> inputs, RunnableConfig config) Invokes the agent with the given inputs map and runtime config.invoke(org.springframework.ai.chat.messages.UserMessage message) invoke(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) invokeAndGetOutput(String message) invokeAndGetOutput(String message, RunnableConfig config) invokeAndGetOutput(List<org.springframework.ai.chat.messages.Message> messages) invokeAndGetOutput(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) invokeAndGetOutput(Map<String, Object> inputs) Invokes the agent with the given inputs map and returns the node output.invokeAndGetOutput(Map<String, Object> inputs, RunnableConfig config) Invokes the agent with the given inputs map and runtime config, returns the node output.invokeAndGetOutput(org.springframework.ai.chat.messages.UserMessage message) invokeAndGetOutput(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) name()Gets the agent's unique name.schedule(ScheduleConfig scheduleConfig) Schedule the agent task with trigger.Schedule the agent task with trigger.reactor.core.publisher.Flux<NodeOutput>reactor.core.publisher.Flux<NodeOutput>stream(String message, RunnableConfig config) reactor.core.publisher.Flux<NodeOutput>reactor.core.publisher.Flux<NodeOutput>stream(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) reactor.core.publisher.Flux<NodeOutput>Streams the graph execution with the given inputs map.reactor.core.publisher.Flux<NodeOutput>stream(Map<String, Object> inputs, RunnableConfig config) Streams the graph execution with the given inputs map and runtime config.reactor.core.publisher.Flux<NodeOutput>stream(org.springframework.ai.chat.messages.UserMessage message) reactor.core.publisher.Flux<NodeOutput>stream(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(String message) Streams the execution result as aFluxofMessageobjects using a plain text input.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(String message, RunnableConfig config) Streams the execution result as aFluxofMessageobjects using a plain text input and a customRunnableConfig.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(List<org.springframework.ai.chat.messages.Message> messages) Streams the execution result as aFluxofMessageobjects using a list of inputMessageinstances.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) Streams the execution result as aFluxofMessageobjects using a list of inputMessageinstances and a customRunnableConfig.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(Map<String, Object> inputs) Streams the execution result as aFluxofMessageobjects using an inputs map.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(Map<String, Object> inputs, RunnableConfig config) Streams the execution result as aFluxofMessageobjects using an inputs map and a customRunnableConfig.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(org.springframework.ai.chat.messages.UserMessage message) Streams the execution result as aFluxofMessageobjects using aUserMessageas input.reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message>streamMessages(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) Streams the execution result as aFluxofMessageobjects using aUserMessageas input and a customRunnableConfig.
-
Field Details
-
name
The agent's name. Must be a unique identifier within the graph. -
description
One line description about the agent's capability. The system can use this for decision-making when delegating control to different agents. -
compileConfig
-
compiledGraph
-
graph
-
executor
-
-
Constructor Details
-
Agent
Protected constructor for initializing all base agent properties.- Parameters:
name- the unique name of the agentdescription- the description of the agent's capability
-
Agent
protected Agent()Default protected constructor for subclasses that need to initialize properties differently.
-
-
Method Details
-
name
Gets the agent's unique name.- Returns:
- the unique name of the agent.
-
description
Gets the one-line description of the agent's capability.- Returns:
- the description of the agent.
-
getGraph
-
getAndCompileGraph
-
schedule
public ScheduledAgentTask schedule(org.springframework.scheduling.Trigger trigger, Map<String, Object> input) throws GraphStateException, GraphRunnerExceptionSchedule the agent task with trigger.- Parameters:
trigger- the schedule configurationinput- the agent input- Returns:
- a ScheduledAgentTask instance for managing the scheduled task
- Throws:
GraphStateExceptionGraphRunnerException
-
schedule
Schedule the agent task with trigger.- Parameters:
scheduleConfig- the schedule configuration- Returns:
- a ScheduledAgentTask instance for managing the scheduled task
- Throws:
GraphStateException
-
getCurrentState
- Throws:
GraphRunnerException
-
invoke
- Throws:
GraphRunnerException
-
invoke
public Optional<OverAllState> invoke(String message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invoke
public Optional<OverAllState> invoke(org.springframework.ai.chat.messages.UserMessage message) throws GraphRunnerException - Throws:
GraphRunnerException
-
invoke
public Optional<OverAllState> invoke(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invoke
public Optional<OverAllState> invoke(List<org.springframework.ai.chat.messages.Message> messages) throws GraphRunnerException - Throws:
GraphRunnerException
-
invoke
public Optional<OverAllState> invoke(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invoke
Invokes the agent with the given inputs map.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 resulting overall state, or empty if none
- Throws:
GraphRunnerException- if the graph execution fails
-
invoke
public Optional<OverAllState> invoke(Map<String, Object> inputs, RunnableConfig config) throws GraphRunnerExceptionInvokes the agent with the given inputs map and runtime config.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 resulting overall state, or empty if none
- Throws:
GraphRunnerException- if the graph execution fails
-
invokeAndGetOutput
- Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(String message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(org.springframework.ai.chat.messages.UserMessage message) throws GraphRunnerException - Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(List<org.springframework.ai.chat.messages.Message> messages) throws GraphRunnerException - Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(Map<String, Object> inputs) throws GraphRunnerExceptionInvokes the agent with the given inputs map and returns the node output.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 node output, or empty if none
- Throws:
GraphRunnerException- if the graph execution fails
-
invokeAndGetOutput
public Optional<NodeOutput> invokeAndGetOutput(Map<String, Object> inputs, RunnableConfig config) throws GraphRunnerExceptionInvokes the agent with the given inputs map and runtime config, returns the node output.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 node output, or empty if none
- Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(String message) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using a plain text input.This is a convenience API built on top of
stream(...)that extracts and emitsMessageinstances directly instead of low-levelNodeOutputobjects. It is intended for use cases that only care about the generated messages and do not require access to graph orchestration or node execution details.- Parameters:
message- the input message as plain text- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(String message, RunnableConfig config) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using a plain text input and a customRunnableConfig.- Parameters:
message- the input message as plain textconfig- runtime configuration controlling execution behavior- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(org.springframework.ai.chat.messages.UserMessage message) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using aUserMessageas input.- Parameters:
message- the user message input- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using aUserMessageas input and a customRunnableConfig.- Parameters:
message- the user message inputconfig- runtime configuration controlling execution behavior- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(List<org.springframework.ai.chat.messages.Message> messages) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using a list of inputMessageinstances.- Parameters:
messages- the input messages- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) throws GraphRunnerException Streams the execution result as aFluxofMessageobjects using a list of inputMessageinstances and a customRunnableConfig.- Parameters:
messages- the input messagesconfig- runtime configuration controlling execution behavior- Returns:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(Map<String, Object> inputs) throws GraphRunnerExceptionStreams the execution result as aFluxofMessageobjects using an inputs map.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:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
streamMessages
public reactor.core.publisher.Flux<org.springframework.ai.chat.messages.Message> streamMessages(Map<String, Object> inputs, RunnableConfig config) throws GraphRunnerExceptionStreams the execution result as aFluxofMessageobjects using an inputs map and a customRunnableConfig.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:
- a
FluxemittingMessageobjects as they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
stream
- Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(String message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(org.springframework.ai.chat.messages.UserMessage message) throws GraphRunnerException - Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(org.springframework.ai.chat.messages.UserMessage message, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(List<org.springframework.ai.chat.messages.Message> messages) throws GraphRunnerException - Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(List<org.springframework.ai.chat.messages.Message> messages, RunnableConfig config) throws GraphRunnerException - Throws:
GraphRunnerException
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(Map<String, Object> inputs) throws GraphRunnerExceptionStreams the graph execution with the given inputs map.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:
- a
FluxemittingNodeOutputas they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
stream
public reactor.core.publisher.Flux<NodeOutput> stream(Map<String, Object> inputs, RunnableConfig config) throws GraphRunnerExceptionStreams the graph execution with the given inputs map and runtime config.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:
- a
FluxemittingNodeOutputas they are produced - Throws:
GraphRunnerException- if the graph execution fails
-
doInvoke
-
doInvokeAndGetOutput
protected Optional<NodeOutput> doInvokeAndGetOutput(Map<String, Object> input, RunnableConfig runnableConfig) -
doStream
protected reactor.core.publisher.Flux<NodeOutput> doStream(Map<String, Object> input, RunnableConfig runnableConfig) -
buildNonStreamConfig
-
buildStreamConfig
-
applyExecutorConfig
Applies executor configuration to the RunnableConfig builder. This method sets the default executor for parallel nodes from the agent's configuration.- Parameters:
builder- the RunnableConfig builder to apply executor configuration to
-
buildMessageInput
-
initGraph
- Throws:
GraphStateException
-