Package com.rpl.agentorama
Interface AgentClient
- All Superinterfaces:
AutoCloseable,Closeable
Client for interacting with a specific agent.
Agent clients provide the interface for invoking agents, streaming data,
handling human input, and managing agent executions.
When called from within an agent node function, this enables subagent execution:
- Can invoke any other agent in the same module (including the current agent)
- Enables recursive agent execution patterns
- Enables mutually recursive agent execution between different agents
- Subagent calls are tracked and displayed in the UI trace
// From client code
AgentClient client = manager.getAgentClient("my-agent");
String result = client.invoke("Hello world");
// From within an agent node (subagent execution)
AgentClient subClient = agentNode.getAgentClient("other-agent");
String subResult = subClient.invoke("Process this data");
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCallback interface for streaming data from all invocations of a specific node.static interfaceCallback interface for streaming data from a single node invoke. -
Method Summary
Modifier and TypeMethodDescription<T> Tfork(AgentInvoke invoke, Map<UUID, List> nodeInvokeIdToNewArgs) Synchronously forks an agent execution with new arguments for specific nodes.<T> CompletableFuture<T> forkAsync(AgentInvoke invoke, Map<UUID, List> nodeInvokeIdToNewArgs) Asynchronously forks an agent execution with new arguments for specific nodes.getMetadata(AgentInvoke invoke) Gets all metadata for an agent execution.Initiates an agent execution and returns a handle for tracking.initiateAsync(Object... args) Asynchronously initiates an agent execution and returns a CompletableFuture with a handle for tracking.initiateFork(AgentInvoke invoke, Map<UUID, List> nodeInvokeIdToNewArgs) Initiates a fork of an agent execution and returns a handle for tracking.initiateForkAsync(AgentInvoke invoke, Map<UUID, List> nodeInvokeIdToNewArgs) Asynchronously initiates a fork of an agent execution.initiateWithContext(AgentContext context, Object... args) Initiates an agent execution with context metadata.initiateWithContextAsync(AgentContext context, Object... args) Asynchronously initiates an agent execution with context metadata.<T> TSynchronously invokes an agent with the provided arguments.<T> CompletableFuture<T> invokeAsync(Object... args) Asynchronously invokes an agent with the provided arguments.<T> TinvokeWithContext(AgentContext context, Object... args) Synchronously invokes an agent with context metadata.<T> CompletableFuture<T> invokeWithContextAsync(AgentContext context, Object... args) Asynchronously invokes an agent with context metadata.booleanisAgentInvokeComplete(AgentInvoke invoke) Checks if an agent execution has completed.nextStep(AgentInvoke invoke) Gets the next execution step of an agent.nextStepAsync(AgentInvoke invoke) Asynchronously gets the next execution step of an agent.pendingHumanInputs(AgentInvoke invoke) Gets all pending human input requests for an agent execution.pendingHumanInputsAsync(AgentInvoke invoke) Asynchronously gets all pending human input requests for an agent execution.voidprovideHumanInput(HumanInputRequest request, String response) Provides a response to a human input request.provideHumanInputAsync(HumanInputRequest request, String response) Asynchronously provides a response to a human input request.voidremoveMetadata(AgentInvoke invoke, String key) Removes metadata from an agent execution.<T> Tresult(AgentInvoke invoke) Gets the final result of an agent execution.<T> CompletableFuture<T> resultAsync(AgentInvoke invoke) Asynchronously gets the final result of an agent execution.voidsetMetadata(AgentInvoke invoke, String key, boolean value) Sets metadata for an agent execution.voidsetMetadata(AgentInvoke invoke, String key, double value) Sets metadata for an agent execution.voidsetMetadata(AgentInvoke invoke, String key, float value) Sets metadata for an agent execution.voidsetMetadata(AgentInvoke invoke, String key, int value) Sets metadata for an agent execution.voidsetMetadata(AgentInvoke invoke, String key, long value) Sets metadata for an agent execution.voidsetMetadata(AgentInvoke invoke, String key, String value) Sets metadata for an agent execution.stream(AgentInvoke invoke, String node) Creates a stream for data emitted from a specific node.<T> AgentStreamstream(AgentInvoke invoke, String node, AgentClient.StreamCallback<T> callback) Creates a stream for data emitted from a specific node with a callback.streamAll(AgentInvoke invoke, String node) Creates a stream for data emitted from all invocations of a specific node.streamAll(AgentInvoke invoke, String node, AgentClient.StreamAllCallback<T> callback) Creates a stream for data emitted from all invocations of a specific node with a callback.streamSpecific(AgentInvoke invoke, String node, UUID nodeInvokeId) Creates a stream for data emitted from a specific node invocation.<T> AgentStreamstreamSpecific(AgentInvoke invoke, String node, UUID nodeInvokeId, AgentClient.StreamCallback<T> callback) Creates a stream for data emitted from a specific node invocation with a callback.
-
Method Details
-
invoke
Synchronously invokes an agent with the provided arguments. This method blocks until the agent execution completes and returns the final result. For long-running agents, consider using initiate() with result() for better control.- Parameters:
args- arguments to pass to the agent- Returns:
- the final result from the agent execution
-
invokeAsync
Asynchronously invokes an agent with the provided arguments. Returns a CompletableFuture that will complete with the agent's result. This allows for non-blocking agent execution and better resource utilization.- Parameters:
args- arguments to pass to the agent- Returns:
- future that completes with the agent result
-
invokeWithContext
Synchronously invokes an agent with context metadata. Metadata allows attaching custom key-value data to agent executions. Metadata is an additional optional parameter to agent execution, and is also used for analytics. Metadata can be accessed anywhere inside agents by calling getMetadata() within node functions.- Parameters:
context- context containing metadata for the executionargs- arguments to pass to the agent- Returns:
- the final result from the agent execution
-
invokeWithContextAsync
Asynchronously invokes an agent with context metadata.- Parameters:
context- context containing metadata for the executionargs- arguments to pass to the agent- Returns:
- future that completes with the agent result
-
initiate
Initiates an agent execution and returns a handle for tracking. This method starts an agent execution but doesn't wait for completion. Use the returned result handle with result(), nextStep(), or streaming methods to interact with the running agent.- Parameters:
args- arguments to pass to the agent- Returns:
- agent invoke handle for tracking and interacting with the execution
-
initiateAsync
Asynchronously initiates an agent execution and returns a CompletableFuture with a handle for tracking.- Parameters:
args- arguments to pass to the agent- Returns:
- future that completes with the agent invoke handle
-
initiateWithContext
Initiates an agent execution with context metadata.- Parameters:
context- context containing metadata for the executionargs- arguments to pass to the agent- Returns:
- agent invoke handle for tracking and interacting with the execution
-
initiateWithContextAsync
Asynchronously initiates an agent execution with context metadata.- Parameters:
context- context containing metadata for the executionargs- arguments to pass to the agent- Returns:
- future that completes with the agent invoke handle
-
fork
Synchronously forks an agent execution with new arguments for specific nodes. Forking creates new execution branches from an existing agent invocation. The nodeInvokeIdToNewArgs map specifies which nodes to fork and what new arguments to use for each fork. Node invoke IDs can be found in the trace UI.- Parameters:
invoke- the agent invoke handle to fork fromnodeInvokeIdToNewArgs- map from node invoke ID to new arguments for that node- Returns:
- the result from the forked execution
-
forkAsync
Asynchronously forks an agent execution with new arguments for specific nodes.- Parameters:
invoke- the agent invoke handle to fork fromnodeInvokeIdToNewArgs- map from node invoke ID to new arguments for that node- Returns:
- future that completes with the result from the forked execution
-
initiateFork
Initiates a fork of an agent execution and returns a handle for tracking.- Parameters:
invoke- the agent invoke to fork fromnodeInvokeIdToNewArgs- map from node invoke ID to new arguments for that node- Returns:
- agent invoke handle for the forked execution
-
initiateForkAsync
CompletableFuture<AgentInvoke> initiateForkAsync(AgentInvoke invoke, Map<UUID, List> nodeInvokeIdToNewArgs) Asynchronously initiates a fork of an agent execution.- Parameters:
invoke- the agent invoke handle to fork fromnodeInvokeIdToNewArgs- map from node invoke ID to new arguments for that node- Returns:
- future that completes with the agent invoke handle for the forked execution
-
nextStep
Gets the next execution step of an agent. The next execution step is either a human input request or an agent result. Check which one by checking if the returned object is an instance ofHumanInputRequestorAgentComplete. If the agent fails, it will throw an exception.- Parameters:
invoke- the agent invoke handle to get the next step for- Returns:
- the next execution step
-
nextStepAsync
Asynchronously gets the next execution step of an agent.- Parameters:
invoke- the agent invoke handle to get the next step for- Returns:
- future that completes with the next execution step
-
result
Gets the final result of an agent execution. This method blocks until the agent execution completes and returns the final result. If the agent fails, it will throw an exception.- Parameters:
invoke- the agent invoke handle to get the result for- Returns:
- the final result from the agent execution
-
resultAsync
Asynchronously gets the final result of an agent execution.- Parameters:
invoke- the agent invoke handle to get the result for- Returns:
- future that completes with the final result from the agent execution
-
isAgentInvokeComplete
Checks if an agent execution has completed.- Parameters:
invoke- the agent invoke handle to check- Returns:
- true if the agent execution is complete
-
setMetadata
Sets metadata for an agent execution. Note: For agent execution, only the metadata that was set at the start with the *WithContext functions is used.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
setMetadata
Sets metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
setMetadata
Sets metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
setMetadata
Sets metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
setMetadata
Sets metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
setMetadata
Sets metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to set metadata forkey- the metadata keyvalue- the metadata value
-
removeMetadata
Removes metadata from an agent execution.- Parameters:
invoke- the agent invoke handle to remove metadata fromkey- the metadata key to remove
-
getMetadata
Gets all metadata for an agent execution.- Parameters:
invoke- the agent invoke handle to get metadata for- Returns:
- map of metadata key-value pairs
-
stream
Creates a stream for data emitted from a specific node. The returned object can have close() called on it to immediately stop streaming.- Parameters:
invoke- the agent invoke handle to stream fromnode- the node name to stream data from- Returns:
- stream object for accessing chunks and controlling streaming
-
stream
Creates a stream for data emitted from a specific node with a callback.- Parameters:
invoke- the agent invoke handle to stream fromnode- the node name to stream data fromcallback- callback function for handling stream updates- Returns:
- stream object for accessing chunks and controlling streaming
-
streamSpecific
Creates a stream for data emitted from a specific node invocation.- Parameters:
invoke- the agent invoke to stream fromnode- the node name to stream data fromnodeInvokeId- the specific node invocation ID to stream from, which can be found in the trace UI.- Returns:
- stream object for accessing chunks and controlling streaming
-
streamSpecific
<T> AgentStream streamSpecific(AgentInvoke invoke, String node, UUID nodeInvokeId, AgentClient.StreamCallback<T> callback) Creates a stream for data emitted from a specific node invocation with a callback.- Parameters:
invoke- the agent invoke to stream fromnode- the node name to stream data fromnodeInvokeId- the specific node invocation ID to stream from, which can be found in the trace UI.callback- callback function for handling stream updates- Returns:
- stream object for accessing chunks and controlling streaming
-
streamAll
Creates a stream for data emitted from all invocations of a specific node. The returned object can have close() called on it to immediately stop streaming.- Parameters:
invoke- the agent invoke handle to stream fromnode- the node name to stream data from- Returns:
- stream object for accessing chunks grouped by invoke ID
-
streamAll
<T> AgentStreamByInvoke streamAll(AgentInvoke invoke, String node, AgentClient.StreamAllCallback<T> callback) Creates a stream for data emitted from all invocations of a specific node with a callback.- Parameters:
invoke- the agent invoke to stream fromnode- the node name to stream data fromcallback- callback function for handling stream updates- Returns:
- stream object for accessing chunks grouped by invoke ID
-
pendingHumanInputs
Gets all pending human input requests for an agent execution.- Parameters:
invoke- the agent invoke to get pending inputs for- Returns:
- list of pending human input requests
-
pendingHumanInputsAsync
Asynchronously gets all pending human input requests for an agent execution.- Parameters:
invoke- the agent invoke to get pending inputs for- Returns:
- future that completes with the list of pending human input requests
-
provideHumanInput
Provides a response to a human input request.- Parameters:
request- the human input request to respond toresponse- the response text
-
provideHumanInputAsync
Asynchronously provides a response to a human input request.- Parameters:
request- the human input request to respond toresponse- the response text- Returns:
- future that completes when the response is provided
-