AgentBuilder

org.llm4s.agent.AgentBuilder
See theAgentBuilder companion object
final class AgentBuilder

An agent's settings, immutable: every with* returns a new builder, and build compiles it, with every agent reachable through its handoffs, into an Agent. Start one with Agent.builder.

Tools, middleware, prompt and step limit belong to the agent, not to a run: the compiled graph's version covers them, so a thread is only ever continued by the graph it ran on. The runtime and tracing are the root's: a handoff target's are ignored.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def build(): Result[Agent]

Compiles this agent and every agent reachable through handoffs into one graph. Refuses an invalid id, a maxSteps below 1, a handoff whose id is invalid or differs from its target's, an id-only handoff (Handoff.toId) to an id no builder of the family defines, one id defined by two builders with different settings - their handoff targets compared too - and whatever org.llm4s.agent.graph.toolloop.ToolLoop.build refuses: tool name clashes, invalid tool schemas, keys the loop owns, handoffs to self or twice to one target.

Compiles this agent and every agent reachable through handoffs into one graph. Refuses an invalid id, a maxSteps below 1, a handoff whose id is invalid or differs from its target's, an id-only handoff (Handoff.toId) to an id no builder of the family defines, one id defined by two builders with different settings - their handoff targets compared too - and whatever org.llm4s.agent.graph.toolloop.ToolLoop.build refuses: tool name clashes, invalid tool schemas, keys the loop owns, handoffs to self or twice to one target.

Attributes

The options every model call of this agent is made with; their tools are replaced by the agent's.

The options every model call of this agent is made with; their tools are replaced by the agent's.

Attributes

def withHandoffs(handoffs: Handoff*): AgentBuilder

Appends handoffs to the agent's handoffs, in order.

Appends handoffs to the agent's handoffs, in order.

Attributes

def withMaxSteps(n: Int): AgentBuilder

Model calls per turn, at least 1; at the limit the turn ends StepLimitReached.

Model calls per turn, at least 1; at the limit the turn ends StepLimitReached.

Attributes

Appends middleware to the agent's stack, in order. The root agent's run-boundary hooks guard the whole family: its beforeAgent runs on every turn's query, before the active agent's own, and its afterAgent on every final answer, after the answering agent's own - so a org.llm4s.agent.graph.middleware.GuardrailMiddleware on the root still applies after a handoff. A handoff target's boundary hooks apply only while it is active, and model and tool wrappers (wrapModelCall, wrapToolCall) only to the agent they are given to.

Appends middleware to the agent's stack, in order. The root agent's run-boundary hooks guard the whole family: its beforeAgent runs on every turn's query, before the active agent's own, and its afterAgent on every final answer, after the answering agent's own - so a org.llm4s.agent.graph.middleware.GuardrailMiddleware on the root still applies after a handoff. A handoff target's boundary hooks apply only while it is active, and model and tool wrappers (wrapModelCall, wrapToolCall) only to the agent they are given to.

Attributes

The runtime the agent's threads live on; by default a new GraphRuntime.inMemory per build. A runtime keeps every thread - a one-shot Agent.run's too - until Agent.forget removes it.

The runtime the agent's threads live on; by default a new GraphRuntime.inMemory per build. A runtime keeps every thread - a one-shot Agent.run's too - until Agent.forget removes it.

Attributes

def withSystemPrompt(prompt: String): AgentBuilder

Sent first on every model call of this agent; never stored in the thread's history.

Sent first on every model call of this agent; never stored in the thread's history.

Attributes

The agent's tools, replacing any set before, checked with the set's validator.

The agent's tools, replacing any set before, checked with the set's validator.

Attributes

The registry's tools, replacing any set before, each adapted with org.llm4s.agent.graph.tool.AgentTool.fromToolFunction; build checks them as a org.llm4s.agent.graph.tool.ToolSet.

The registry's tools, replacing any set before, each adapted with org.llm4s.agent.graph.tool.AgentTool.fromToolFunction; build checks them as a org.llm4s.agent.graph.tool.ToolSet.

Attributes

Traces each run's events, as graph.* custom events, to tracing.

Traces each run's events, as graph.* custom events, to tracing.

Attributes