Record Class AgenticServices.AgentConfigurator
- Enclosing class:
AgenticServices
The configurator is called for every AI agent and decision agent of the system, and for every agent
orchestrating subagents through a planner: a sequence, a loop, a conditional, a parallel or a parallel mapper
agent, a supervisor and a planner agent. It is called with a AgenticServices.DeclarativeAgentCreationContext, after the
declarative configuration of the agent has been applied and before the agent is built. The context provides
the builder of the agent through one of three methods, and the other two return null:
agentBuilder() for an AI agent, decisionAgentBuilder() for a decision agent and
agenticService() for an agent orchestrating subagents. So a configurator must check which builder it
received before using it, and do nothing with a context providing none of the builders it knows, since other
kinds of agents can be added to these. The agentInstanceFactory is applied to the same agents, and to
an A2A or MCP client agent whose type is a class, which cannot be created without it, while one whose type is
an interface is always a JDK proxy. What the factory must return for such an agent is described on
A2AClientBuilder.agentInstanceFactory(Function) and
McpClientBuilder.agentInstanceFactory(Function).
It is how an integration registers something on every such agent, like an AgentListener: a listener
is notified of the events of the agent it is registered on, and of the agents below it when it is inherited,
but never of the events of the agents containing it, like the model calls that a supervisor makes to choose
its subagents.
The helperObjectsResolver is called with the type of every agent that the system builds, 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 helperObjectsResolver 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.
The subAgentResolver is called with each type listed among the subagents of a declarative agent, and
returns the subagent to use for it, or null to let the system build it from that type. When it returns
an instance of a class with an @Agent or @HumanInTheLoop method, a non-AI agent or a
human-in-the-loop object, the helper objects of the subagent are that instance followed by the ones that the
helperObjectsResolver returns for the listed type, not for the class of the instance, which can be the
proxy of a container bean. Helper objects are compared by identity: an object returned by both resolvers, like
the bean of a container, counts once, while another instance of the same class is a second helper object, whose
helpers conflict with the ones of the first. When the subAgentResolver returns an agent that is built
already, like one created by an agent builder or by AgenticServices.humanInTheLoopBuilder(), the
helperObjectsResolver is not called for it: its helpers belong to whoever built it.
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
-