Record Class AgenticServices.AgentConfigurator
- Enclosing class:
AgenticServices
The configurator is called for every agent of the system, AI agents and decision agents alike, with
a AgenticServices.DeclarativeAgentCreationContext. For an AI agent its agentBuilder() is set and its
decisionAgentBuilder() is null, for a decision agent it is the other way round, so a
configurator must check which builder it received before using it. The agentInstanceFactory is
applied to both kinds of agents.
The helperObjectsResolver is called with the type of every agent of the system, the root agent and
each nested agent, and returns its helper objects: the objects whose instance methods, annotated with
the declarative annotations like @ExitCondition or @ChatModelSupplier, configure the agent
instead of, or next to, the static methods of the agent type. It can return null or an empty list for
an agent without helper objects. It is how a dependency injection container provides the helpers of an agent
as methods of a managed bean, typically an instance of the agent type itself.
The resolver is called once for each agent, when the agentic system is built. The returned objects are then shared by all the invocations of the agent, also by the ones running at the same time, so they must be thread-safe, or be proxies finding the current instance at each call, like the client proxies of the normal-scoped beans of a CDI container. Their annotated methods are found and invoked through reflection, on the class of each object, its superclasses and its interfaces. They can have any visibility but private, and cannot be final unless their class is final too: a container invokes them through the proxy of its bean, which cannot override such methods, so they would run on the proxy, without its injected fields, while no proxy subclasses a final class. A helper method declared by the agent type itself that is not static needs one of the helper objects to be invoked on, an instance of its declaring class, typically the agent bean: the agentic system fails to build otherwise, instead of skipping the helper silently.
Create a configurator with builder(), setting only the hooks needed: the constructors are kept, but
each hook added to the record adds a positional component to them.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionAgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator) AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory) AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory, Supplier<Object> defaultMemoryIdSupplier) AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory, Supplier<Object> defaultMemoryIdSupplier, Function<Class<?>, List<?>> helperObjectsResolver) Creates an instance of aAgentConfiguratorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theagentInstanceFactoryrecord component.builder()A builder of a configurator: every hook is optional, and theconfiguratordoes nothing by default.Returns the value of theconfiguratorrecord component.Returns the value of thedefaultMemoryIdSupplierrecord component.empty()final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.helperObjects(Class<?> agentType) The helper objects of the given agent type returned by thehelperObjectsResolver, or an empty list when there is no resolver or it returns nothing.Returns the value of thehelperObjectsResolverrecord component.Returns the value of thesubAgentResolverrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
AgentConfigurator
-
AgentConfigurator
public AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory) -
AgentConfigurator
public AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory, Supplier<Object> defaultMemoryIdSupplier) -
AgentConfigurator
public AgentConfigurator(Consumer<AgenticServices.DeclarativeAgentCreationContext<?>> configurator, Function<Class<?>, Object> subAgentResolver, Function<InternalAgent, Object> agentInstanceFactory, Supplier<Object> defaultMemoryIdSupplier, Function<Class<?>, List<?>> helperObjectsResolver) Creates an instance of aAgentConfiguratorrecord class.- Parameters:
configurator- the value for theconfiguratorrecord componentsubAgentResolver- the value for thesubAgentResolverrecord componentagentInstanceFactory- the value for theagentInstanceFactoryrecord componentdefaultMemoryIdSupplier- the value for thedefaultMemoryIdSupplierrecord componenthelperObjectsResolver- the value for thehelperObjectsResolverrecord component
-
-
Method Details
-
empty
-
builder
A builder of a configurator: every hook is optional, and theconfiguratordoes nothing by default. -
helperObjects
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
configurator
Returns the value of theconfiguratorrecord component.- Returns:
- the value of the
configuratorrecord component
-
subAgentResolver
-
agentInstanceFactory
Returns the value of theagentInstanceFactoryrecord component.- Returns:
- the value of the
agentInstanceFactoryrecord component
-
defaultMemoryIdSupplier
-
helperObjectsResolver
-