JAgentBuilder

org.llm4s.javaapi.JAgentBuilder
final class JAgentBuilder

An agent under construction, from Llm4s.agentBuilder (#2476): its system prompt, tools, guardrails, context window and streaming, set from Java with Java types only.

LlmResult<JAgent> agent = Llm4s.agentBuilder("support", client)
   .systemPrompt("You are a support assistant.")
   .tools(tools)
   .inputGuardrails(List.of(JGuardrails.length(1, 10_000)))
   .outputGuardrails(List.of(JGuardrails.json()))
   .contextWindow(JContextWindow.lastMessages(20))
   .streaming(true)
   .build();

Immutable: every method returns a new builder, and each setting replaces the one set before. No method throws: a null argument, and anything build cannot make an agent of, is a failed result of build().

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

The agent, or a failed result naming the first problem: a null id, client or setting, a blank or invalid id, a null element in a list, two tools with one name, an invalid guardrail or context window, or tools the agent cannot offer together.

The agent, or a failed result naming the first problem: a null id, client or setting, a blank or invalid id, a null element in a list, two tools with one name, an invalid guardrail or context window, or tools the agent cannot offer together.

Attributes

What the agent sends the model of a conversation on each call; without one, it sends the whole conversation.

What the agent sends the model of a conversation on each call; without one, it sends the whole conversation.

Attributes

def inputGuardrails(guardrails: List[_ <: JGuardrail]): JAgentBuilder

Guardrails run in order on each turn's query before the model sees it; one that fails ends the turn BLOCKED, and the turn stores nothing.

Guardrails run in order on each turn's query before the model sees it; one that fails ends the turn BLOCKED, and the turn stores nothing.

Attributes

def outputGuardrails(guardrails: List[_ <: JOutputGuardrail]): JAgentBuilder

Guardrails run in order on each turn's final answer; one that fails ends the turn BLOCKED, and the answer is not kept.

Guardrails run in order on each turn's final answer; one that fails ends the turn BLOCKED, and the answer is not kept.

Attributes

def streaming(streaming: Boolean): JAgentBuilder

Whether the agent's model calls stream: then a JAgent.stream carries the answer's text deltas (AgentEvents.TextDelta()). Off by default.

Whether the agent's model calls stream: then a JAgent.stream carries the answer's text deltas (AgentEvents.TextDelta()). Off by default.

Attributes

def systemPrompt(prompt: String): JAgentBuilder

The system prompt, sent first on every model call of every turn.

The system prompt, sent first on every model call of every turn.

Attributes

def tools(tools: List[JTool]): JAgentBuilder

The tools the model may call, defined with JTool.builder or JTool.fromAnnotated.

The tools the model may call, defined with JTool.builder or JTool.fromAnnotated.

Attributes