Class AgenticServices

java.lang.Object
dev.langchain4j.agentic.AgenticServices

public class AgenticServices extends Object
Provides static factory methods to create and configure various types of agent services.
  • Method Details

    • setWorkflowAgentsBuilder

      public static void setWorkflowAgentsBuilder(WorkflowAgentsBuilder workflowAgentsBuilder)
      Explicitly set a WorkflowAgentsBuilder.
    • agentBuilder

      public static UntypedAgentBuilder agentBuilder()
      Creates an agent builder for untyped agents.
      Returns:
      a new UntypedAgentBuilder instance
    • agentBuilder

      public static <T> AgentBuilder<T, AgentBuilder<T,?>> agentBuilder(Class<T> agentServiceClass)
      Creates an agent builder for the given agent service class.
      Parameters:
      agentServiceClass - the class of the agent service
      Returns:
      a new AgentBuilder instance
    • decisionAgentBuilder

      @Experimental public static <T> DecisionAgentBuilder<T> decisionAgentBuilder(Class<T> agentServiceClass)
      Creates a builder for a decision agent: an agent whose implementation is a single call to a DecisionModel instead of a chat model. The agent is defined by a Decision Service interface whose method also carries @Agent: its arguments are read from the AgenticScope and sent to the decision model as the input, its return type defines the question(s), and the typed answer is written to the output key. See DecisionAgentBuilder for the details.
      Parameters:
      agentServiceClass - the decision agent interface
      Returns:
      a new DecisionAgentBuilder instance
      Since:
      1.23.0
    • humanInTheLoopBuilder

      public static HumanInTheLoop.HumanInTheLoopBuilder humanInTheLoopBuilder()
      Creates a builder for an agent implementing the human-in-the-loop pattern.
    • sequenceBuilder

      public static SequentialAgentService<UntypedAgent> sequenceBuilder()
      Creates a builder for an untyped agent implementing a workflow sequence of its subagents.
    • sequenceBuilder

      public 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.
      Parameters:
      agentServiceClass - the class of the agent service
    • parallelBuilder

      public static ParallelAgentService<UntypedAgent> parallelBuilder()
      Creates a builder for an untyped agent implementing a parallel workflow of its subagents.
    • parallelBuilder

      public 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.
      Parameters:
      agentServiceClass - the class of the agent service
    • parallelMapperBuilder

      public static ParallelMapperService<UntypedAgent> parallelMapperBuilder()
      Creates a builder for an untyped agent implementing a parallel mapper workflow that creates multiple instances of the same sub-agent, one per item in a collection.
    • parallelMapperBuilder

      public static <T> ParallelMapperService<T> parallelMapperBuilder(Class<T> agentServiceClass)
      Creates a builder for an agent implementing a parallel mapper workflow that creates multiple instances of the same sub-agent, one per item in a collection, and can be invoked in a strongly typed way through the provided agent service interface.
      Parameters:
      agentServiceClass - the class of the agent service
    • loopBuilder

      public static LoopAgentService<UntypedAgent> loopBuilder()
      Creates a builder for an untyped agent implementing a loop workflow of its subagents.
    • loopBuilder

      public 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.
      Parameters:
      agentServiceClass - the class of the agent service
    • conditionalBuilder

      public static ConditionalAgentService<UntypedAgent> conditionalBuilder()
      Creates a builder for an untyped agent implementing a conditional workflow of its subagents.
    • conditionalBuilder

      public 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.
      Parameters:
      agentServiceClass - the class of the agent service
    • supervisorBuilder

      public static SupervisorAgentService<SupervisorAgent> 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

      public 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. This is useful for building complex agentic systems where one agent oversees the execution of others.
      Parameters:
      agentServiceClass - the class of the agent service
    • plannerBuilder

      public static PlannerBasedService<UntypedAgent> plannerBuilder()
      Creates a builder for a customizable planner agent service.
    • plannerBuilder

      public static <T> PlannerBasedService<T> plannerBuilder(Class<T> agentServiceClass)
      Creates a builder for a customizable planner agent service.
      Parameters:
      agentServiceClass - the class of the agent service
    • a2aBuilder

      public static A2AClientBuilder<UntypedAgent> a2aBuilder(String a2aServerUrl)
      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

      public static A2AClientBuilder<UntypedAgent> a2aBuilder(String a2aServerUrl, String tenant)
      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
      tenant - the A2A agent tenant
      Returns:
      a new A2AClientBuilder instance
    • a2aBuilder

      public 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. This is useful for building agentic systems that communicate with remote agents.
      Parameters:
      a2aServerUrl - the URL of the A2A server
      agentServiceClass - the class of the agent service
      Returns:
      a new A2AClientBuilder instance
    • a2aBuilder

      public static <T> A2AClientBuilder<T> a2aBuilder(String a2aServerUrl, String tenant, Class<T> agentServiceClass)
      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
      tenant - the A2A agent tenant
      agentServiceClass - the class of the agent service
      Returns:
      a new A2AClientBuilder instance
    • createAgenticSystem

      public static <T> T createAgenticSystem(Class<T> agentServiceClass)
      Creates an instance of an agentic system defined through the declarative API.
      Parameters:
      agentServiceClass - the class of the agent service
    • createAgenticSystem

      public 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.
      Parameters:
      agentServiceClass - the class of the agent service
      chatModel - the ChatModel used by default for all agents participating in this agentic system
    • createAgenticSystem

      public static <T> T createAgenticSystem(Class<T> agentServiceClass, AgenticServices.AgentConfigurator agentConfigurator)
      Creates an instance of an agentic system defined through the declarative API.
      Parameters:
      agentServiceClass - the class of the agent service
      agentConfigurator - 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, AgenticServices.AgentConfigurator 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 service
      chatModel - the ChatModel used by default for all agents participating in this agentic system
      agentConfigurator - A callback to tweak the configuration of each agent created in this agentic system
    • createBuiltInAgentExecutor

      public static AgentExecutor createBuiltInAgentExecutor(Class<?> agentServiceClass)
    • agentAction

      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

      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
    • nonAiAgentBuilder

      Creates a builder for a non-AI agent whose logic is a function of the AgenticScope. Unlike an agentAction, the resulting agent can be given a name, a description, typed input keys and an output key, so that it can also be used as a subagent of a supervisor or of any other planner that relies on this metadata.
      Parameters:
      function - the function computing the agent's result from the AgenticScope
      Returns:
      a new NonAiAgentBuilder instance