Class DeclarativeUtil
java.lang.Object
dev.langchain4j.agentic.declarative.DeclarativeUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic AgentConditionactivationCondition(AgentHelpers helpers) Reads the activation condition of the given agent: the method annotated withActivationConditionwithout a value, static on the agent type or an instance method of one of its helper objects.static voidstatic <T> Function<AgenticScope, T> agenticScopeFunction(Class<?> agentType, HelperMethod functionMethod, Class<T> targetClass) Creates a function invoking the given helper method of the given agent type, a static method of the type or an instance method of a helper object: its parameters supported by a registeredSupplierParameterResolverare resolved, the others are read from theAgenticScope, and arenullwhen the function is applied without one.static Predicate<AgenticScope> agenticScopePredicate(Class<?> agentType, HelperMethod predicateMethod) static AgentListeneragentListener(AgentHelpers helpers) static voidbuildAgentFeatures(AgentHelpers helpers, AgenticService<?, ?> builder) Applies to the builder of a workflow, planner or supervisor agent the helpers common to every kind of them: theBeforeCall, theErrorHandler, theAgentListenerSupplierand theActivationConditionwithout value.static voidbuildListener(AgentHelpers helpers, Consumer<AgentListener> listenerRegistration) Applies theAgentListenerSupplierhelper of the given agent, if any, to the given listener registration of its builder, which composes the listener with the ones already registered.static voidcheckNoDecisionSuppliers(AgentHelpers helpers) Checks that the given agent, built as an agent of another kind, has no helper method annotated withDecisionModelSupplierorDecisionThresholdSupplier, which would be silently ignored.static voidcheckReturnType(Method method, Class<?> expected) Checks that the given method can return an instance of the expected type: its return type must be a subtype or a supertype, likeObject, of the expected one.static voidconfigureAgent(Class<?> agentType, AgentBuilder<?, ?> agentBuilder) Applies the static helper methods of the given agent type to its builder, when the builder is created programmatically: the chat model is left to the builder, and a non-static helper is an error, since the builder has no helper objects.static voidconfigureAgent(Class<?> agentType, ChatModel chatModel, AgentBuilder<?, ?> agentBuilder, AgenticServices.AgentConfigurator agentConfigurator) static voidconfigureDecisionAgent(Class<?> agentType, DecisionAgentBuilder<?> builder) static voidconfigureDecisionAgent(Class<?> agentType, DecisionAgentBuilder<?> builder, AgenticServices.AgentConfigurator agentConfigurator) Applies the declarative configuration of the given decision agent type to its builder: theDecisionModelSupplier, theDecisionThresholdSupplier, theAgentListenerSupplierand theActivationCondition, static on the type or instance methods of its helper objects, and the agent configurator.static voidconfigureOutput(AgentHelpers helpers, AgenticService<?, ?> builder) static intframeworkParameterCount(Class<?> agentType, Method method) static List<SupplierParameterResolver> static <T> TinvokeStatic(Method method, Object... args) static <T> TinvokeSupplierWithResolvers(Class<?> agentType, HelperMethod helper, Class<T> targetClass) Invokes a supplier method, a static method of the agent type or an instance method of a helper object: all its parameters must be provided by the registeredSupplierParameterResolvers.static booleanisDecisionAgent(Class<?> agentType) Whether the given type is a decision agent: an interface whose@Agentmethod is annotated with@Decide, or which declares aDecisionModelSuppliermethod.parallelExecutor(AgentHelpers helpers) static Optional<HelperMethod> predicateHelper(AgentHelpers helpers, Class<? extends Annotation> annotation) Selects the condition helper method annotated with the given annotation, a static method of the agent type or an instance method of a helper object.static Optional<HelperMethod> predicateHelper(AgentHelpers helpers, Class<? extends Annotation> annotation, Predicate<Method> filter) Selects the condition helper method annotated with the given annotation and matching the given filter, a static method of the agent type or an instance method of a helper object.selectMethod(Class<?> agentServiceClass, Predicate<Method> methodSelector) staticMethodsAnnotatedWith(Class<?> type, Class<? extends Annotation> annotation) The static methods annotated with the given annotation declared by the given type, its superclasses and its interfaces.
-
Method Details
-
configureAgent
Applies the static helper methods of the given agent type to its builder, when the builder is created programmatically: the chat model is left to the builder, and a non-static helper is an error, since the builder has no helper objects. -
configureAgent
public static void configureAgent(Class<?> agentType, ChatModel chatModel, AgentBuilder<?, ?> agentBuilder, AgenticServices.AgentConfigurator agentConfigurator) -
isDecisionAgent
Whether the given type is a decision agent: an interface whose@Agentmethod is annotated with@Decide, or which declares aDecisionModelSuppliermethod. -
configureDecisionAgent
-
configureDecisionAgent
public static void configureDecisionAgent(Class<?> agentType, DecisionAgentBuilder<?> builder, AgenticServices.AgentConfigurator agentConfigurator) Applies the declarative configuration of the given decision agent type to its builder: theDecisionModelSupplier, theDecisionThresholdSupplier, theAgentListenerSupplierand theActivationCondition, static on the type or instance methods of its helper objects, and the agent configurator.- Throws:
AgenticSystemConfigurationException- if the type also declares aChatModelSupplieror aStreamingChatModelSupplier
-
checkNoDecisionSuppliers
Checks that the given agent, built as an agent of another kind, has no helper method annotated withDecisionModelSupplierorDecisionThresholdSupplier, which would be silently ignored.- Throws:
AgenticSystemConfigurationException- if it has
-
checkReturnType
Checks that the given method can return an instance of the expected type: its return type must be a subtype or a supertype, likeObject, of the expected one.- Throws:
IllegalArgumentException- if it cannot
-
invokeStatic
-
configureOutput
-
predicateHelper
public static Optional<HelperMethod> predicateHelper(AgentHelpers helpers, Class<? extends Annotation> annotation) Selects the condition helper method annotated with the given annotation, a static method of the agent type or an instance method of a helper object.- Throws:
IllegalArgumentException- if the selected method doesn't return a boolean
-
predicateHelper
public static Optional<HelperMethod> predicateHelper(AgentHelpers helpers, Class<? extends Annotation> annotation, Predicate<Method> filter) Selects the condition helper method annotated with the given annotation and matching the given filter, a static method of the agent type or an instance method of a helper object.- Throws:
IllegalArgumentException- if the selected method doesn't return a boolean
-
buildAgentFeatures
Applies to the builder of a workflow, planner or supervisor agent the helpers common to every kind of them: theBeforeCall, theErrorHandler, theAgentListenerSupplierand theActivationConditionwithout value. -
activationCondition
Reads the activation condition of the given agent: the method annotated withActivationConditionwithout a value, static on the agent type or an instance method of one of its helper objects. AnActivationConditionwith a value is allowed only on aConditionalAgent, where it selects the subagents to activate, and where a condition without value is not allowed.- Returns:
- the activation condition of the agent, or
nullwhen it has none - Throws:
AgenticSystemConfigurationException- if there is more than one such method, if it doesn't return a boolean, or if a condition with a value is declared on a class that is not a conditional agent
-
staticMethodsAnnotatedWith
public static Set<Method> staticMethodsAnnotatedWith(Class<?> type, Class<? extends Annotation> annotation) The static methods annotated with the given annotation declared by the given type, its superclasses and its interfaces. -
parallelExecutor
-
buildListener
public static void buildListener(AgentHelpers helpers, Consumer<AgentListener> listenerRegistration) Applies theAgentListenerSupplierhelper of the given agent, if any, to the given listener registration of its builder, which composes the listener with the ones already registered. -
agentListener
- Returns:
- the listener returned by the
AgentListenerSupplierhelper of the given agent, ornullwhen it has none
-
selectMethod
-
agenticScopePredicate
public static Predicate<AgenticScope> agenticScopePredicate(Class<?> agentType, HelperMethod predicateMethod) -
frameworkParameterCount
- Returns:
- the number of parameters of the given method that are not provided by a registered
SupplierParameterResolver
-
invokeSupplierWithResolvers
public static <T> T invokeSupplierWithResolvers(Class<?> agentType, HelperMethod helper, Class<T> targetClass) Invokes a supplier method, a static method of the agent type or an instance method of a helper object: all its parameters must be provided by the registeredSupplierParameterResolvers.- Throws:
AgenticSystemConfigurationException- if a parameter is not supported by any resolver
-
agenticScopeFunction
public static <T> Function<AgenticScope, T> agenticScopeFunction(Class<?> agentType, HelperMethod functionMethod, Class<T> targetClass) Creates a function invoking the given helper method of the given agent type, a static method of the type or an instance method of a helper object: its parameters supported by a registeredSupplierParameterResolverare resolved, the others are read from theAgenticScope, and arenullwhen the function is applied without one. -
addSupplierParameterResolver
-
getSupplierParameterResolvers
-