Class AgentForge4jBootstrap.Builder
- Enclosing class:
- AgentForge4jBootstrap
AgentForge4j. Obtain via AgentForge4jBootstrap.defaults().
All with*(null) calls throw IllegalArgumentException immediately —
passing null is always a bug. To restore a default, build a new instance.
withLlmProvider(LlmProviderConfig) is additive across providers
and last-write-wins within a provider key. All other with* methods are last-write-wins.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theAgentForge4jfacade, assembling all components with defaults for any overrides not set.withAgentInvoker(AgentInvoker agentInvoker) Overrides theAgentInvokerused for agent and SPAR steps.withAgentRepository(AgentRepository agentRepository) Overrides the agent definition repository.withAgentsDir(Path agentsDir) Opts in to loading agents from the given filesystem directory at build time.withAllowPrivateNetworks(boolean allowPrivateNetworks) Lifts the outbound-egress guard's private/loopback/link-local/cloud-metadata blocks for HTTP and MCP streamable-HTTP tools.withArtifactValidators(List<ArtifactValidator> artifactValidators) Registers additionalArtifactValidators aVALIDATEstep may select by id.withCacheEnabled(boolean cacheEnabled) Enables or disables prompt-layer caching on the defaultAgentInvoker.Overrides the clock used for timestamps on state updates and events.withContextAggregators(List<ContextAggregator> contextAggregators) Registers additionalContextAggregators anAGGREGATEstep may select by id.withContextRenderer(ContextRenderer contextRenderer) Overrides the agent input context renderer.withEventRecorder(EventRecorder eventRecorder) Overrides the shared workflow event recorder.withFileSink(FileSink fileSink) Overrides whereCreateFileCommandcontent is written.withFileSinkPath(Path fileSinkPath) Overrides whereCreateFileCommandcontent is written.withIntegrationConfigLoader(IntegrationConfigLoader integrationConfigLoader) Overrides the integration definition loader.withIntegrationRepository(MutableIntegrationRepository integrationRepository) Overrides the integration repository that loaded definitions are saved into and the capability resolver reads from.withIntegrationsDir(Path integrationsDir) Opts in to loading integration definitions from top-level*.jsonfiles in the given directory at build time.withLlmCallObserver(LlmCallObserver llmCallObserver) Overrides the observer invoked after each completed LLM call.withLlmClientResolver(LlmClientResolver llmClientResolver) Overrides the LLM client resolver.withLlmCommandParser(LlmCommandParser llmCommandParser) Overrides the LLM command response parser.withLlmProvider(LlmProviderConfig config) Adds or replaces programmatic LLM provider configuration.Overrides the strategy for selecting an LLM provider from agent preferences.withLlmRetryPolicy(LlmRetryPolicy llmRetryPolicy) Configures the LLM retry policy.withLlmSecretResolver(LlmSecretResolver llmSecretResolver) Overrides theLlmSecretResolverused to resolve provider credential references.withLoadShippedAgents(boolean loadShippedAgents) Enables or disables loading shipped agents from the classpath.withLoadShippedWorkflows(boolean loadShippedWorkflows) Enables or disables loading shipped workflows from the classpath.withMaxNestingDepth(int maxNestingDepth) Sets the maximum nested workflow depth forwarded toWorkflowRuntimeBuilder.withModelTierResolver(ModelTierResolver modelTierResolver) Overrides the resolver that maps a capability tier to a concrete model per provider.withObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Overrides the JacksonObjectMapperused for configuration loading and LLM parsing.withPendingToolInvocationStore(PendingToolInvocationStore pendingToolInvocationStore) Overrides the pending tool invocation store.withRequirementResolver(RequirementResolver requirementResolver) Overrides the resolver consulted for declared workflow requirements at the run-start checkpoint and at deferred first use.withRunExecutionInterceptor(RunExecutionInterceptor runExecutionInterceptor) Registers a control interceptor fired before a run enters main execution and before each LLM call.withSecretResolver(SecretResolver secretResolver) Overrides the resolver that turns a secret-reference key into its live value at invoke time (for example an HTTP integration'ssecretHeaders).withToolExecutionOptions(ToolExecutionOptions toolExecutionOptions) Overrides the tool execution options (authoritative timeout, retries, backoff).withToolPolicy(ToolPolicy toolPolicy) Overrides the tool policy.withToolProviderFactory(ToolProviderFactory toolProviderFactory) Overrides the factory that realises integration definitions as tool providers.withToolProviderResolver(ToolProviderResolver toolProviderResolver) Overrides the capability resolver (for example a binding-aware resolver supplied by the embedding application).withToolProviders(List<ToolProvider> toolProviders) Provides pre-built tool providers (for example MCP servers) to expose to the runtime.withWorkflowEventLog(WorkflowEventLog workflowEventLog) Overrides the append-only workflow event log.withWorkflowRepository(WorkflowRepository workflowRepository) Overrides the workflow definition repository.withWorkflowsDir(Path workflowsDir) Opts in to loading workflows from the given filesystem directory at build time.withWorkflowStateRepository(WorkflowStateRepository workflowStateRepository) Overrides persistence for workflow state between drives.
-
Method Details
-
withClock
Overrides the clock used for timestamps on state updates and events.- Parameters:
clock- clock instance; must not benull- Returns:
- this builder
-
withObjectMapper
public AgentForge4jBootstrap.Builder withObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Overrides the JacksonObjectMapperused for configuration loading and LLM parsing.- Parameters:
objectMapper- mapper instance; must not benull- Returns:
- this builder
-
withAgentRepository
Overrides the agent definition repository.- Parameters:
agentRepository- repository instance; must not benull- Returns:
- this builder
-
withWorkflowRepository
Overrides the workflow definition repository.- Parameters:
workflowRepository- repository instance; must not benull- Returns:
- this builder
-
withWorkflowStateRepository
public AgentForge4jBootstrap.Builder withWorkflowStateRepository(WorkflowStateRepository workflowStateRepository) Overrides persistence for workflow state between drives.- Parameters:
workflowStateRepository- repository instance; must not benull- Returns:
- this builder
-
withWorkflowEventLog
Overrides the append-only workflow event log.- Parameters:
workflowEventLog- event log instance; must not benull- Returns:
- this builder
-
withLlmClientResolver
Overrides the LLM client resolver.- Parameters:
llmClientResolver- resolver instance; must not benull- Returns:
- this builder
-
withLlmRetryPolicy
Configures the LLM retry policy. WhenmaxAttempts > 1, the assembledLlmClientResolveris automatically wrapped withRetryingLlmClientResolverusing this policy.Has no effect if
withLlmClientResolver(LlmClientResolver)was also called — an explicit resolver is never wrapped automatically.When
maxAttempts <= 1the policy is stored but no wrapping occurs (one attempt means no retry).- Parameters:
llmRetryPolicy- retry policy; must not benull- Returns:
- this builder
-
withContextRenderer
Overrides the agent input context renderer.- Parameters:
contextRenderer- renderer instance; must not benull- Returns:
- this builder
-
withLlmCommandParser
Overrides the LLM command response parser.- Parameters:
llmCommandParser- parser instance; must not benull- Returns:
- this builder
-
withEventRecorder
Overrides the shared workflow event recorder.- Parameters:
eventRecorder- recorder instance; must not benull- Returns:
- this builder
-
withFileSink
Overrides whereCreateFileCommandcontent is written.- Parameters:
fileSink- file sink instance; must not benull- Returns:
- this builder
-
withFileSinkPath
Overrides whereCreateFileCommandcontent is written.- Parameters:
fileSinkPath- path used to create aLocalFileSinkinstance- Returns:
- this builder
-
withLlmProviderSelectionStrategy
public AgentForge4jBootstrap.Builder withLlmProviderSelectionStrategy(LlmProviderSelectionStrategy strategy) Overrides the strategy for selecting an LLM provider from agent preferences.- Parameters:
strategy- selection strategy; must not benull- Returns:
- this builder
-
withAgentInvoker
Overrides theAgentInvokerused for agent and SPAR steps.- Parameters:
agentInvoker- invoker instance; must not benull- Returns:
- this builder
-
withLlmCallObserver
Overrides the observer invoked after each completed LLM call.- Parameters:
llmCallObserver- observer instance; must not benull- Returns:
- this builder
-
withRunExecutionInterceptor
public AgentForge4jBootstrap.Builder withRunExecutionInterceptor(RunExecutionInterceptor runExecutionInterceptor) Registers a control interceptor fired before a run enters main execution and before each LLM call. Either hook may throwExecutionBlockedExceptionto block. Defaults to a no-op, so behaviour is unchanged when not set.- Parameters:
runExecutionInterceptor- interceptor instance; must not benull- Returns:
- this builder
-
withModelTierResolver
Overrides the resolver that maps a capability tier to a concrete model per provider. When not set, aConfigModelTierResolverbuilt from the shipped defaults merged with anyagentforge4j.llm.model-tiers.<provider>.<tier>overrides is used.- Parameters:
modelTierResolver- resolver instance; must not benull- Returns:
- this builder
-
withRequirementResolver
public AgentForge4jBootstrap.Builder withRequirementResolver(RequirementResolver requirementResolver) Overrides the resolver consulted for declared workflow requirements at the run-start checkpoint and at deferred first use. When not set, the runtime defaults to the in-processDefaultRequirementResolver(default-or-empty), preserving the fail-fast guarantee out of the box. The embedding application supplies a store-backed resolver here.- Parameters:
requirementResolver- resolver instance; must not benull- Returns:
- this builder
-
withArtifactValidators
public AgentForge4jBootstrap.Builder withArtifactValidators(List<ArtifactValidator> artifactValidators) Registers additionalArtifactValidators aVALIDATEstep may select by id. These are appended to the built-inagent-bundlevalidator (which is always present so shipped agent-bundle workflows keep working); a supplied validator that reuses an already-registered id fails fast at runtime assembly.- Parameters:
artifactValidators- validators to add; must not benull- Returns:
- this builder
-
withContextAggregators
public AgentForge4jBootstrap.Builder withContextAggregators(List<ContextAggregator> contextAggregators) Registers additionalContextAggregators anAGGREGATEstep may select by id. These are appended to the built-in aggregators discovered viaServiceLoader; a supplied aggregator that reuses an already-registered id fails fast at runtime assembly.- Parameters:
contextAggregators- aggregators to add; must not benull- Returns:
- this builder
-
withToolProviders
Provides pre-built tool providers (for example MCP servers) to expose to the runtime. Configuring any tool support enables the tool-execution chokepoint and registers theTOOL_INVOCATIONhandler; with none configured, tool invocation is unavailable and behaviour is unchanged.These providers are merged with any configured integrations source into the single
IntegrationToolProviderResolver; the two coexist unless they expose the same capability, which fails fast. Has no effect ifwithToolProviderResolver(ToolProviderResolver)is set — an explicit resolver is the sole resolver.Trust boundary. Providers supplied here are trusted embedder code: the
ToolSourceKindtheir descriptors declare is taken at face value by the secure defaultToolPolicy, so a provider that declares an in-process source is allowed by default. Supply a customToolPolicyto gate providers whose declared kind you do not control.- Parameters:
toolProviders- providers to expose; must not benull- Returns:
- this builder
-
withToolProviderResolver
public AgentForge4jBootstrap.Builder withToolProviderResolver(ToolProviderResolver toolProviderResolver) Overrides the capability resolver (for example a binding-aware resolver supplied by the embedding application). When set, it is the sole resolver andwithToolProviders(List)is not used to build one.- Parameters:
toolProviderResolver- resolver instance; must not benull- Returns:
- this builder
-
withToolPolicy
Overrides the tool policy. Defaults to the secure-by-default policy (SecureDefaultToolPolicy), which denies remote-network and local-process tools unless an explicit policy (ToolPolicy.allowAll()or a custom one) opts in.- Parameters:
toolPolicy- policy instance; must not benull- Returns:
- this builder
-
withPendingToolInvocationStore
public AgentForge4jBootstrap.Builder withPendingToolInvocationStore(PendingToolInvocationStore pendingToolInvocationStore) Overrides the pending tool invocation store. Defaults to an in-memory store.- Parameters:
pendingToolInvocationStore- store instance; must not benull- Returns:
- this builder
-
withToolExecutionOptions
public AgentForge4jBootstrap.Builder withToolExecutionOptions(ToolExecutionOptions toolExecutionOptions) Overrides the tool execution options (authoritative timeout, retries, backoff). Defaults toToolExecutionOptions.defaults().- Parameters:
toolExecutionOptions- options instance; must not benull- Returns:
- this builder
-
withAllowPrivateNetworks
Lifts the outbound-egress guard's private/loopback/link-local/cloud-metadata blocks for HTTP and MCP streamable-HTTP tools. Development only — enabling this disables the cloud-metadata-IP (SSRF) protection. Thehttp/httpsscheme allowlist still applies. Defaults tofalse(fail-closed).- Parameters:
allowPrivateNetworks- whether to allow private/loopback network targets- Returns:
- this builder
-
withIntegrationsDir
Opts in to loading integration definitions from top-level*.jsonfiles in the given directory at build time. Loaded definitions are saved into the integration repository and resolved into tool providers through the discoveredIntegrationToolProviderFactorycontributions, enabling tool support.Has no effect if
withToolProviderResolver(ToolProviderResolver)is also set — an explicit resolver is the sole resolver. Coexists withwithToolProviders(List): the two sources are merged into one resolver and only a shared capability fails fast.- Parameters:
integrationsDir- integrations root directory; must be an existing directory- Returns:
- this builder
-
withIntegrationConfigLoader
public AgentForge4jBootstrap.Builder withIntegrationConfigLoader(IntegrationConfigLoader integrationConfigLoader) Overrides the integration definition loader. When set, it is used instead of the filesystem loader overwithIntegrationsDir(Path).- Parameters:
integrationConfigLoader- loader instance; must not benull- Returns:
- this builder
-
withIntegrationRepository
public AgentForge4jBootstrap.Builder withIntegrationRepository(MutableIntegrationRepository integrationRepository) Overrides the integration repository that loaded definitions are saved into and the capability resolver reads from. Defaults to an in-memory repository.- Parameters:
integrationRepository- repository instance; must not benull- Returns:
- this builder
-
withToolProviderFactory
public AgentForge4jBootstrap.Builder withToolProviderFactory(ToolProviderFactory toolProviderFactory) Overrides the factory that realises integration definitions as tool providers. Defaults to theServiceLoaderToolProviderFactoryaggregating the discovered per-type contributions.- Parameters:
toolProviderFactory- factory instance; must not benull- Returns:
- this builder
-
withSecretResolver
Overrides the resolver that turns a secret-reference key into its live value at invoke time (for example an HTTP integration'ssecretHeaders). Defaults toEnvironmentSecretResolver, which reads process environment variables then system properties. An embedding application supplies its own implementation backed by its secret store.- Parameters:
secretResolver- resolver instance; must not benull- Returns:
- this builder
-
withMaxNestingDepth
Sets the maximum nested workflow depth forwarded toWorkflowRuntimeBuilder.- Parameters:
maxNestingDepth- maximum nesting depth (at least 1)- Returns:
- this builder
-
withAgentsDir
Opts in to loading agents from the given filesystem directory at build time.- Parameters:
agentsDir- agents root directory; must not benull- Returns:
- this builder
-
withWorkflowsDir
Opts in to loading workflows from the given filesystem directory at build time.- Parameters:
workflowsDir- workflows root directory; must not benull- Returns:
- this builder
-
withLoadShippedAgents
Enables or disables loading shipped agents from the classpath.- Parameters:
loadShippedAgents-trueto load shipped agents- Returns:
- this builder
-
withLoadShippedWorkflows
Enables or disables loading shipped workflows from the classpath.- Parameters:
loadShippedWorkflows-trueto load shipped workflows- Returns:
- this builder
-
withCacheEnabled
Enables or disables prompt-layer caching on the defaultAgentInvoker.- Parameters:
cacheEnabled-trueto enable prompt cache boundaries on LLM requests- Returns:
- this builder
-
withLlmProvider
Adds or replaces programmatic LLM provider configuration. Additive across provider keys; last-write-wins within the same provider key.- Parameters:
config- provider configuration; must not benull- Returns:
- this builder
-
withLlmSecretResolver
Overrides theLlmSecretResolverused to resolve provider credential references. The default (EnvSystemPropertyLlmSecretResolver) passes literal credentials through and resolvesenv:/sysprop:references from the process environment / system properties.- Parameters:
llmSecretResolver- resolver instance; must not benull- Returns:
- this builder
-
build
Builds theAgentForge4jfacade, assembling all components with defaults for any overrides not set.- Returns:
- immutable facade; never
null - Throws:
IllegalStateException- if assembly fails (e.g. loading throws)
-