Skip to content

Agent Configuration Reference

All fields available on Agent.builder().

FieldTypeRequiredDefaultDescription
roleStringYesThe agent’s role/title. Used in prompts and logging.
goalStringYesThe agent’s primary objective. Included in the system prompt.
backgroundStringNonullPersona context for the system prompt. Omitted when null or blank.
toolsList<Object>No[]Tools available to this agent. Each entry must implement AgentTool or have @Tool-annotated methods.
llmChatModelYesAny LangChain4j ChatModel.
allowDelegationbooleanNofalseWhen true, a delegate tool is auto-injected at execution time.
verbosebooleanNofalseWhen true, prompts and LLM responses are logged at INFO level.
maxIterationsintNo25Maximum number of tool-call iterations before the agent is forced to produce a final answer. Must be greater than zero.
responseFormatStringNo""Extra formatting instructions appended to the system prompt.

The following validations are applied at build() time:

  • role must not be null or blank
  • goal must not be null or blank
  • llm must not be null
  • maxIterations must be greater than zero
  • Each tool must implement AgentTool or have at least one @Tool-annotated method

Agent agent = Agent.builder()
.role("Senior Research Analyst")
.goal("Find accurate, well-structured information on any topic")
.background("You are a veteran researcher with 15 years of technology industry experience.")
.tools(List.of(new WebSearchTool()))
.llm(model)
.allowDelegation(true)
.verbose(false)
.maxIterations(25)
.responseFormat("Always structure your response with clear headings.")
.build();

Agent is an immutable value object. Use toBuilder() to create modified copies:

Agent verboseAgent = agent.toBuilder().verbose(true).build();