Class AgenticServices
java.lang.Object
dev.langchain4j.agentic.AgenticServices
Provides static factory methods to create and configure various types of agent services.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static interface
static final record
-
Method Summary
Modifier and TypeMethodDescriptionstatic A2AClientBuilder
<UntypedAgent> a2aBuilder
(String a2aServerUrl) Creates a builder for an A2A client that can be used to interact with agents over the A2A protocol.static <T> A2AClientBuilder
<T> a2aBuilder
(String a2aServerUrl, Class<T> agentServiceClass) Creates a builder for an A2A client that can be used to interact with agents over the A2A protocol.static AgenticServices.AgentAction
Wraps a runnable into an agent action that can be executed within the context of an agent.Wraps a consumer of the AgenticScope into an agent action that can be executed within the context of an agent.static <T> AgentBuilder
<T> agentBuilder
(Class<T> agentServiceClass) Creates an agent builder for the given agent service class.static ConditionalAgentService
<UntypedAgent> Creates a builder for an untyped agent implementing a conditional workflow of its subagents.static <T> ConditionalAgentService
<T> conditionalBuilder
(Class<T> agentServiceClass) Creates a builder for an agent implementing a conditional workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.static <T> T
createAgenticSystem
(Class<T> agentServiceClass) Creates an instance of an agentic system defined through the declarative API.static <T> T
createAgenticSystem
(Class<T> agentServiceClass, ChatModel chatModel) Creates an instance of an agentic system defined through the declarative API and using the provided ChatModel.static <T> T
createAgenticSystem
(Class<T> agentServiceClass, ChatModel chatModel, Consumer<AgenticServices.DeclarativeAgentCreationContext> agentConfigurator) Creates an instance of an agentic system defined through the declarative API and using the provided ChatModel.static <T> T
createAgenticSystem
(Class<T> agentServiceClass, Consumer<AgenticServices.DeclarativeAgentCreationContext> agentConfigurator) Creates an instance of an agentic system defined through the declarative API.Creates a builder for an agent implementing the human-in-the-loop pattern.static LoopAgentService
<UntypedAgent> Creates a builder for an untyped agent implementing a loop workflow of its subagents.static <T> LoopAgentService
<T> loopBuilder
(Class<T> agentServiceClass) Creates a builder for an agent implementing a loop workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.static ParallelAgentService
<UntypedAgent> Creates a builder for an untyped agent implementing a parallel workflow of its subagents.static <T> ParallelAgentService
<T> parallelBuilder
(Class<T> agentServiceClass) Creates a builder for an agent implementing a parallel workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.static SequentialAgentService
<UntypedAgent> Creates a builder for an untyped agent implementing a workflow sequence of its subagents.static <T> SequentialAgentService
<T> sequenceBuilder
(Class<T> agentServiceClass) Creates a builder for an agent implementing a workflow sequence of its subagents that can be invoked in a strongly typed way through the provided agent service interface.static void
setWorkflowAgentsBuilder
(WorkflowAgentsBuilder workflowAgentsBuilder) Explicitly set a WorkflowAgentsBuilder.Creates a builder for a supervisor agent service that can be used to manage and supervise other agents.static <T> SupervisorAgentService
<T> supervisorBuilder
(Class<T> agentServiceClass) Creates a builder for a supervisor agent service that can be used to manage and supervise other agents.
-
Method Details
-
setWorkflowAgentsBuilder
Explicitly set a WorkflowAgentsBuilder. -
agentBuilder
Creates an agent builder for the given agent service class.- Parameters:
agentServiceClass
- the class of the agent service- Returns:
- a new AgentBuilder instance
-
humanInTheLoopBuilder
Creates a builder for an agent implementing the human-in-the-loop pattern. -
sequenceBuilder
Creates a builder for an untyped agent implementing a workflow sequence of its subagents. -
sequenceBuilder
Creates a builder for an agent implementing a workflow sequence of its subagents that can be invoked in a strongly typed way through the provided agent service interface.- Parameters:
agentServiceClass
- the class of the agent service
-
parallelBuilder
Creates a builder for an untyped agent implementing a parallel workflow of its subagents. -
parallelBuilder
Creates a builder for an agent implementing a parallel workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.- Parameters:
agentServiceClass
- the class of the agent service
-
loopBuilder
Creates a builder for an untyped agent implementing a loop workflow of its subagents. -
loopBuilder
Creates a builder for an agent implementing a loop workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.- Parameters:
agentServiceClass
- the class of the agent service
-
conditionalBuilder
Creates a builder for an untyped agent implementing a conditional workflow of its subagents. -
conditionalBuilder
Creates a builder for an agent implementing a conditional workflow of its subagents that can be invoked in a strongly typed way through the provided agent service interface.- Parameters:
agentServiceClass
- the class of the agent service
-
supervisorBuilder
Creates a builder for a supervisor agent service that can be used to manage and supervise other agents. This is useful for building complex agentic systems where one agent oversees the execution of others. -
supervisorBuilder
Creates a builder for a supervisor agent service that can be used to manage and supervise other agents. This is useful for building complex agentic systems where one agent oversees the execution of others.- Parameters:
agentServiceClass
- the class of the agent service
-
a2aBuilder
Creates a builder for an A2A client that can be used to interact with agents over the A2A protocol. This is useful for building agentic systems that communicate with remote agents.- Parameters:
a2aServerUrl
- the URL of the A2A server- Returns:
- a new A2AClientBuilder instance
-
a2aBuilder
Creates a builder for an A2A client that can be used to interact with agents over the A2A protocol. This is useful for building agentic systems that communicate with remote agents.- Parameters:
a2aServerUrl
- the URL of the A2A serveragentServiceClass
- the class of the agent service- Returns:
- a new A2AClientBuilder instance
-
createAgenticSystem
Creates an instance of an agentic system defined through the declarative API.- Parameters:
agentServiceClass
- the class of the agent service
-
createAgenticSystem
Creates an instance of an agentic system defined through the declarative API and using the provided ChatModel.- Parameters:
agentServiceClass
- the class of the agent servicechatModel
- the ChatModel used by default for all agents participating in this agentic system
-
createAgenticSystem
public static <T> T createAgenticSystem(Class<T> agentServiceClass, Consumer<AgenticServices.DeclarativeAgentCreationContext> agentConfigurator) Creates an instance of an agentic system defined through the declarative API.- Parameters:
agentServiceClass
- the class of the agent serviceagentConfigurator
- A callback to tweak the configuration of each agent created in this agentic system
-
createAgenticSystem
public static <T> T createAgenticSystem(Class<T> agentServiceClass, ChatModel chatModel, Consumer<AgenticServices.DeclarativeAgentCreationContext> agentConfigurator) Creates an instance of an agentic system defined through the declarative API and using the provided ChatModel.- Parameters:
agentServiceClass
- the class of the agent servicechatModel
- the ChatModel used by default for all agents participating in this agentic systemagentConfigurator
- A callback to tweak the configuration of each agent created in this agentic system
-
agentAction
public static AgenticServices.AgentAction agentAction(AgenticServices.AgentAction.NonThrowingRunnable runnable) Wraps a runnable into an agent action that can be executed within the context of an agent.- Parameters:
runnable
- the runnable to be executed- Returns:
- an AgentAction that encapsulates the runnable
-
agentAction
public static AgenticServices.AgenticScopeAction agentAction(AgenticServices.AgenticScopeAction.NonThrowingConsumer<AgenticScope> consumer) Wraps a consumer of the AgenticScope into an agent action that can be executed within the context of an agent.- Parameters:
consumer
- the consumer to be executed- Returns:
- an AgentAction that encapsulates the consumer
-