Handoff

org.llm4s.agent.Handoff
See theHandoff companion object
final case class Handoff(id: String, target: Option[AgentBuilder], transferReason: Option[String], preserveContext: Boolean)

A transfer an agent's model may make to another agent of its family. build() compiles the root and every agent reachable through handoffs into one graph, keyed by agent id. The model is offered the handoff as a tool named handoff_to_<id>; calling it, as the only call of its message, moves the conversation to the target, which stays active - the next turn starts with it

  • until it hands off again.

The target is either a builder (Handoff.to, Handoff.of), which brings that agent into the family, or an agent id alone (Handoff.toId), which names an agent some builder of the family defines. Builders are immutable, so a cycle - the specialist handing back to the agent that handed to it - names the earlier agent by id:

val physics = Agent.builder("physics", client)
 .withSystemPrompt("You are a physicist.")
 .withHandoffs(Handoff.toId("triage", "Questions that are not about physics"))
val triage = Agent.builder("triage", client)
 .withHandoffs(Handoff.to("physics", physics, "Requires physics expertise"))
 .build()

Value parameters

id

the target's agent id, [a-zA-Z0-9_-]{1,52}; build() refuses one that differs from target's, and an id-only target no builder of the family defines

preserveContext

when false, the target is sent only the user's last question before the transfer and the transfer onwards; the stored history is unchanged either way

target

the agent to hand off to, or None when it is named by id alone

transferReason

offered to the model in the handoff tool's description

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def handoffId: String

The handoff tool's name: handoff_to_<id>, stable across processes.

The handoff tool's name: handoff_to_<id>, stable across processes.

Attributes

def handoffName: String

Human-readable name for this handoff.

Human-readable name for this handoff.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product