Class InstructionAgentHook
- All Implemented Interfaces:
Hook,Prioritized
When this hook is active, it runs at HookPosition.BEFORE_AGENT and reads
ReactAgent.instruction() from getAgent(). If the instruction is non-empty,
it prepends an AgentInstructionMessage to the given messages and returns an
AgentCommand with UpdatePolicy.REPLACE.
This allows ReactAgent to avoid adding instruction again in the subgraph adapter when used as a subgraph node.
This hook is added by default in ReactAgent when no other hook is an InstructionAgentHook. It runs first among beforeAgent hooks (lowest order).
-
Nested Class Summary
Nested classes/interfaces inherited from class com.alibaba.cloud.ai.graph.agent.hook.messages.MessagesAgentHook
MessagesAgentHook.AfterAgentAction, MessagesAgentHook.BeforeAgentAction -
Field Summary
Fields inherited from interface com.alibaba.cloud.ai.graph.agent.Prioritized
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeforeAgent(List<org.springframework.ai.chat.messages.Message> previousMessages, RunnableConfig config) static InstructionAgentHookcreate()Create the default InstructionAgentHook instance (used when no other hook handles instruction).getAgent()Gets the ReactAgent instance that owns this hook.getName()Gets the unique name of this hook.intgetOrder()Returns the order value for this object.voidsetAgent(ReactAgent agent) Sets the ReactAgent instance that owns this hook.Methods inherited from class com.alibaba.cloud.ai.graph.agent.hook.messages.MessagesAgentHook
afterAgent, afterAgentAction, beforeAgentAction, getAgentName, setAgentNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alibaba.cloud.ai.graph.agent.hook.Hook
canJumpTo, getHookPositions, getKeyStrategys, getModelInterceptors, getToolInterceptors, getTools
-
Constructor Details
-
InstructionAgentHook
public InstructionAgentHook()
-
-
Method Details
-
beforeAgent
public AgentCommand beforeAgent(List<org.springframework.ai.chat.messages.Message> previousMessages, RunnableConfig config) - Overrides:
beforeAgentin classMessagesAgentHook
-
getName
Description copied from interface:HookGets the unique name of this hook. The name is used to identify the hook in the execution graph.- Returns:
- the hook name, must not be null
-
getOrder
public int getOrder()Description copied from interface:PrioritizedReturns the order value for this object.The order value determines the priority of this object when sorted with other
Prioritizedobjects. Objects with smaller order values will be sorted before objects with larger order values (ascending order).For example:
- An object with order 1 will be placed before an object with order 5
- An object with order 10 will be placed before an object with order 20
- Returns:
- the order value (smaller values indicate higher priority)
-
getAgent
Description copied from interface:HookGets the ReactAgent instance that owns this hook. This allows hooks to access the agent's state and configuration.- Returns:
- the ReactAgent instance, or null if not set
-
setAgent
Description copied from interface:HookSets the ReactAgent instance that owns this hook. This is typically called by the framework during agent initialization.- Parameters:
agent- the ReactAgent instance, must not be null
-
create
Create the default InstructionAgentHook instance (used when no other hook handles instruction).- Returns:
- a new InstructionAgentHook
-