Class DeclarativeUtil
java.lang.Object
dev.langchain4j.agentic.declarative.DeclarativeUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic AgentConditionactivationCondition(Class<?> agentClass) Reads the activation condition of the agent declared by the given class or interface: the static method annotated withActivationConditionwithout a value.static voidstatic <T> Function<AgenticScope, T> agenticScopeFunction(Class<?> agentType, Method functionMethod, Class<T> targetClass) Creates a function invoking the given static method declared on, or inherited by, the given agent type: its parameters supported by a registeredSupplierParameterResolverare resolved, the others are read from theAgenticScope, and arenullwhen the function is applied without one.static <T> Function<AgenticScope, T> agenticScopeFunction(Method functionMethod, Class<T> targetClass) static Predicate<AgenticScope> agenticScopePredicate(Class<?> agentType, Method predicateMethod) static Predicate<AgenticScope> agenticScopePredicate(Method predicateMethod) static voidbuildAgentFeatures(Class<?> agentServiceClass, AgenticService<?, ?> builder) static voidcheckNoDecisionSuppliers(Class<?> agentType) Checks that the given type, built as an agent of another kind, declares no 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) 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 interface to its builder: theDecisionModelSupplier, theDecisionThresholdSupplier, theAgentListenerSupplier, theActivationConditionand the agent configurator.static <T> voidconfigureOutput(Class<T> agentServiceClass, AgenticService<?, ?> builder) static intframeworkParameterCount(Class<?> agentType, Method method) static List<SupplierParameterResolver> static <T> TinvokeStatic(Method method, Object... args) static <T> TinvokeSupplierWithResolvers(Class<?> agentType, Method method, Class<T> targetClass) Invokes a static supplier method: 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(Class<?> agentServiceClass) predicateMethod(Class<?> agentServiceClass, Predicate<Method> methodSelector) Selects the static condition method matching the given selector.selectMethod(Class<?> agentServiceClass, Predicate<Method> methodSelector)
-
Method Details
-
configureAgent
-
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 interface to its builder: theDecisionModelSupplier, theDecisionThresholdSupplier, theAgentListenerSupplier, theActivationConditionand the agent configurator.- Throws:
AgenticSystemConfigurationException- if the interface also declares aChatModelSupplieror aStreamingChatModelSupplier
-
checkNoDecisionSuppliers
Checks that the given type, built as an agent of another kind, declares no method annotated withDecisionModelSupplierorDecisionThresholdSupplier, which would be silently ignored.- Throws:
AgenticSystemConfigurationException- if it does
-
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
-
predicateMethod
-
buildAgentFeatures
-
activationCondition
Reads the activation condition of the agent declared by the given class or interface: the static method annotated withActivationConditionwithout a value. 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
-
parallelExecutor
-
selectMethod
-
agenticScopePredicate
-
agenticScopePredicate
public static Predicate<AgenticScope> agenticScopePredicate(Class<?> agentType, Method 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, Method method, Class<T> targetClass) Invokes a static supplier method: 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(Method functionMethod, Class<T> targetClass) -
agenticScopeFunction
public static <T> Function<AgenticScope, T> agenticScopeFunction(Class<?> agentType, Method functionMethod, Class<T> targetClass) Creates a function invoking the given static method declared on, or inherited by, the given agent type: its parameters supported by a registeredSupplierParameterResolverare resolved, the others are read from theAgenticScope, and arenullwhen the function is applied without one. -
addSupplierParameterResolver
-
getSupplierParameterResolvers
-