Annotation Interface HumanInTheLoop
Marks a method as a human-in-the-loop agent. The method can be invoked to get input or feedback from a human during the execution of a workflow.
The annotated method can have any number of parameters, which will be provided by the workflow context when the method is invoked.
Parameters resolved through a
SupplierParameterResolver are not read from the workflow context and are not inputs of the agent.
Example:
public interface AudienceRetriever {
@HumanInTheLoop(description = "Generate a story based on the given topic", outputKey = "audience", async = true)
static String request(@V("topic") String topic) {
request.set("Which audience for topic " + topic + "?");
return System.console().readLine();
}
}
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIf true, the agent will be invoked in an asynchronous manner, allowing the workflow to continue without waiting for the agent's result.Description of the agent.Name of the agent.Key of the output variable that will be used to store the result of the agent's invocation.Strongly typed key of the output variable that will be used to store the result of the agent's invocation.Description of the agent.
-
Element Details
-
name
String nameName of the agent. If not provided, method name will be used.- Returns:
- name of the agent.
- Default:
""
-
value
String valueDescription of the agent. This is an alias of thedescriptionattribute, and it is possible to use either. It should be clear and descriptive to allow language model to understand the agent's purpose and its intended use.- Returns:
- description of the agent.
- Default:
""
-
description
String descriptionDescription of the agent. This is an alias of thevalueattribute, and it is possible to use either. It should be clear and descriptive to allow language model to understand the agent's purpose and its intended use.- Returns:
- description of the agent.
- Default:
""
-
outputKey
String outputKeyKey of the output variable that will be used to store the result of the agent's invocation.- Returns:
- name of the output variable.
- Default:
""
-
typedOutputKey
Strongly typed key of the output variable that will be used to store the result of the agent's invocation. It enforces type safety when retrieving the output from the agent's state and can be used in alternative to theoutputKey()attribute. Note that only one of those two attributes can be used at a time.- Returns:
- class representing the typed output variable.
- Default:
dev.langchain4j.agentic.Agent.NoTypedKey.class
-
async
boolean asyncIf true, the agent will be invoked in an asynchronous manner, allowing the workflow to continue without waiting for the agent's result. The result is awaited only where it is read: by another agent taking it as an argument, or by the output function or output key of the agentic system.When nothing reads the result, the call to the agentic system returns while the agent is still running, and the result or the failure of the agent is then reported only to its
AgentListener. The next call on the same memory id waits for these agents to complete before it starts.- Returns:
- true if the agent should be invoked in an asynchronous manner, false otherwise.
- Default:
false
-