TypedAgent

org.llm4s.agent.delegation.TypedAgent
See theTypedAgent companion object
@Experimental
final class TypedAgent[I, O]

A subagent's definition (design 4.44): an agent that takes a typed input I and gives back a typed report O, run on a thread of its own, with a fresh conversation, its own tools and middleware only, and nothing of its parent's (rule 15). A parent offers it with AgentBuilder.withSubagents, which compiles it with bind at the parent's build(); BoundAgent.run runs one with no parent.

Only typed data crosses (rule 17): the parent sends I, rendered as the child's first user message - by default a TaskRequest's description as it is, any other input as its canonical JSON under one line naming the subagent (withInputText replaces that) - and gets back O, decoded from the child's answer. For a TypedAgent.text subagent the answer itself is the report; otherwise the child answers in O's schema (AgentBuilder.withOutput).

A definition holds clients and functions, not data: it is immutable, and every with* returns a new one. Its id ([a-zA-Z0-9_-]{1,52}) and description (not blank) are checked when it is bound.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def bind(parentClient: LLMClient, runtime: GraphRuntime, tracing: Option[Tracing]): Result[BoundAgent[I, O]]

Compiles the definition onto runtime, calling parentClient unless withModel set a client, and tracing to the parent's tracing (rule 16: a child never has tracing of its own; design 4.47). Refuses an invalid id, a blank description, and whatever AgentBuilder.build() refuses for the child.

Compiles the definition onto runtime, calling parentClient unless withModel set a client, and tracing to the parent's tracing (rule 16: a child never has tracing of its own; design 4.47). Refuses an invalid id, a blank description, and whatever AgentBuilder.build() refuses for the child.

Attributes

def id: AgentId

The subagent's id: its agent id, and the subagent_type or the task_<id> tool name the parent model uses.

The subagent's id: its agent id, and the subagent_type or the task_<id> tool name the parent model uses.

Attributes

def withFailure(policy: ChildFailure): TypedAgent[I, O]

What the parent does when the child fails; ChildFailure.Report by default.

What the parent does when the child fails; ChildFailure.Report by default.

Attributes

def withHarness(profile: HarnessProfile): TypedAgent[I, O]

The child's own harness (AgentBuilder.withHarness), over the child's own thread.

The child's own harness (AgentBuilder.withHarness), over the child's own thread.

Attributes

def withInputText(render: I => String): TypedAgent[I, O]

Renders the input as the child's first user message, replacing the default (see the class description).

Renders the input as the child's first user message, replacing the default (see the class description).

Attributes

def withMaxSteps(n: Int): TypedAgent[I, O]

Model calls per child turn (AgentBuilder.withMaxSteps); at the limit the task is refused StepLimitReached.

Model calls per child turn (AgentBuilder.withMaxSteps); at the limit the task is refused StepLimitReached.

Attributes

def withMiddleware(middleware: AgentMiddleware*): TypedAgent[I, O]

Appends middleware to the child's own stack, in order.

Appends middleware to the child's own stack, in order.

Attributes

def withModel(client: LLMClient, options: CompletionOptions): TypedAgent[I, O]

The client and options the child calls; by default the client of the agent it is bound to, with default options.

The client and options the child calls; by default the client of the agent it is bound to, with default options.

Attributes

def withStreaming(): TypedAgent[I, O]

Streams the child's model answers (AgentBuilder.withStreaming), so a parent subscription made with nested = true sees the child's AgentEvents.TextDeltas as they arrive (design 4.47). Off by default.

Streams the child's model answers (AgentBuilder.withStreaming), so a parent subscription made with nested = true sees the child's AgentEvents.TextDeltas as they arrive (design 4.47). Off by default.

Attributes

def withSystemPrompt(prompt: String): TypedAgent[I, O]

The child's system prompt; refused beside withHarness, as AgentBuilder.withSystemPrompt is.

The child's system prompt; refused beside withHarness, as AgentBuilder.withSystemPrompt is.

Attributes

def withTools(tools: ToolSet): TypedAgent[I, O]

The child's own tools, replacing any set before. It has no other tool of its parent's (rule 15).

The child's own tools, replacing any set before. It has no other tool of its parent's (rule 15).

Attributes

Concrete fields

val description: String