BoundAgent

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

A TypedAgent compiled onto a runtime by TypedAgent.bind: what the task tools run, and what run runs with no parent - from a graph node, or a test.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def id: AgentId

The subagent's id.

The subagent's id.

Attributes

def recover(ref: ChildRef, config: RunConfig): Result[TaskOutcome[O]]

Continues the failed or interrupted standalone run ref names - a Refused(Failed)'s child - with config, re-running only failed or unstarted work, as Agent.recover does; its outcome maps as run's does. A delegated child's ref is refused, as for resume; so is a thread with nothing to recover (GraphError.NothingToRecover).

Continues the failed or interrupted standalone run ref names - a Refused(Failed)'s child - with config, re-running only failed or unstarted work, as Agent.recover does; its outcome maps as run's does. A delegated child's ref is refused, as for resume; so is a thread with nothing to recover (GraphError.NothingToRecover).

Attributes

def resume(ref: ChildRef, answers: Map[InterruptId, Value], config: RunConfig): Result[TaskOutcome[O]]

Answers some of the pending interrupts of the suspended standalone run ref names - a TaskOutcome.Suspended's child - as Agent.resume takes them, and continues it with config; its outcome maps as run's does. A delegated child's ref is refused (ValidationError): its parent continues it (rule 19). The runtime's refusals - an answer to an interrupt that is not pending (GraphError.InvalidResume), a thread not suspended - come back unchanged, as does a cancellation; either way the thread stays, for another call.

Answers some of the pending interrupts of the suspended standalone run ref names - a TaskOutcome.Suspended's child - as Agent.resume takes them, and continues it with config; its outcome maps as run's does. A delegated child's ref is refused (ValidationError): its parent continues it (rule 19). The runtime's refusals - an answer to an interrupt that is not pending (GraphError.InvalidResume), a thread not suspended - come back unchanged, as does a cancellation; either way the thread stays, for another call.

Attributes

def run(input: I, config: RunConfig): Result[TaskOutcome[O]]

Runs the subagent once, on a new top-level thread of its runtime, with config, and returns its outcome: its report, the refusal its status or its typed answer's failure gives, or its suspension. The thread, named by the outcome's child.threadId (depth 0, no tool call), stays in the runtime until deleted; resume continues a suspended one. A run that fails with work left to recover is Refused(Failed), its child naming the failed run, for recover. Any other failure - a cancellation included - is Left, which names no thread, so that thread is forgotten once its run has ended (as for Agent.run(query)).

Runs the subagent once, on a new top-level thread of its runtime, with config, and returns its outcome: its report, the refusal its status or its typed answer's failure gives, or its suspension. The thread, named by the outcome's child.threadId (depth 0, no tool call), stays in the runtime until deleted; resume continues a suspended one. A run that fails with work left to recover is Refused(Failed), its child naming the failed run, for recover. Any other failure - a cancellation included - is Left, which names no thread, so that thread is forgotten once its run has ended (as for Agent.run(query)).

For tests and one-off calls: a recoverable graph node calls the thread-id overload instead, since this one, run again after a crash, starts another thread and runs the subagent - its model calls and effects - twice.

Attributes

def run(threadId: ThreadId, input: I, config: RunConfig): Result[TaskOutcome[O]]

Runs the subagent on the caller-chosen top-level thread threadId, starting or reattaching to it as the task tools do for a child (design 4.44, #2077), so running it again with the same id never runs the subagent twice. A graph node derives threadId from its own replay-stable key, and calls this overload, not the fresh-thread one: after a crash its replay finds the first run's thread. The thread's latest checkpoint decides:

Runs the subagent on the caller-chosen top-level thread threadId, starting or reattaching to it as the task tools do for a child (design 4.44, #2077), so running it again with the same id never runs the subagent twice. A graph node derives threadId from its own replay-stable key, and calls this overload, not the fresh-thread one: after a crash its replay finds the first run's thread. The thread's latest checkpoint decides:

  • none: the subagent is started with input and config, its outcome mapped as the fresh-thread run's is.
  • Running (a run that failed, or crashed, with work left): it is recovered, as recover does, re-running only failed or unstarted work. A thread whose run is live - in this runtime, or holding its claim in another - is waited on, with backoff, for up to twice the runtime's claim lifetime, then GraphError.ThreadBusy is Left.
  • Suspended: its Suspended outcome, nothing run; answer it with resume.
  • Completed or Failed: the outcome its terminal checkpoint records, rebuilt as a run's is, nothing run.

The thread is the call: its first checkpoint records a digest of the rendered input (as a child's records its input), and one found at threadId is reattached only if it is this agent's and was started by this overload with the same input; another agent's thread, one started with other input or not by this overload, is refused (ValidationError), so an id collision never returns another run's outcome (#2086). A delegated child's thread is refused (ValidationError) too: its parent continues it (rule 19). Unlike the fresh-thread overload, a Left forgets nothing: the caller can name the thread, and its next call reattaches to it.

Attributes

def run(threadId: ThreadId, input: I): Result[TaskOutcome[O]]

run on the caller-chosen thread threadId, with the default config.

run on the caller-chosen thread threadId, with the default config.

Attributes

Concrete fields

val definition: TypedAgent[I, O]