Reference Agents
RunnerConfig
Settings of a ToolRunner. Start from
RunnerConfig.default[IO] and adjust.
Reference#
RunnerConfig[F]#
final case class RunnerConfig[F[_]] private (
maxIterations: Int,
maxConcurrency: Int,
eagerInputStreaming: Boolean,
options: RequestOptions,
beforeTool: ContentBlock.ToolUse => F[ToolDecision],
onToolError: (ContentBlock.ToolUse, Throwable) => F[ContentBlock.ToolResult],
beforeRequest: (Int, MessageRequest) => F[MessageRequest]
)
def default[F[_]](implicit F: cats.Applicative[F]): RunnerConfig[F]
Limits#
def withMaxIterations(n: Int): RunnerConfig[F]
def withMaxConcurrency(n: Int): RunnerConfig[F]
def withEagerInputStreaming(on: Boolean): RunnerConfig[F]
def withRequestOptions(o: RequestOptions): RunnerConfig[F]
withMaxIterations: the most requests one run may make; 25 by default. Reaching it ends the run withMaxIterations.withMaxConcurrency: how many tools run at the same time; 8 by default.withEagerInputStreaming: streams tool arguments as they are generated; on by default.withRequestOptions: theRequestOptionsof every request the run makes.
Hooks#
def withBeforeTool(f: ContentBlock.ToolUse => F[ToolDecision]): RunnerConfig[F]
def withOnToolError(f: (ContentBlock.ToolUse, Throwable) => F[ContentBlock.ToolResult]): RunnerConfig[F]
def withBeforeRequest(f: (Int, MessageRequest) => F[MessageRequest]): RunnerConfig[F]
withBeforeTool: decides each call before it runs: allow it, deny it with a reason, replace its result or abort the run.withOnToolError: turns a tool's exception into the result the model sees. By default, the exception's class and message.withBeforeRequest: rewrites each request before it is sent. The iteration number starts at 1.
sealed trait ToolDecision extends Product with Serializable
case object Allow extends ToolDecision
final case class Deny(reason: String) extends ToolDecision
final case class Replace(result: ToolResultContent) extends ToolDecision
final case class Abort(reason: String) extends ToolDecision
Caveats
beforeToolis called for each call in turn, before any tool runs, so anAbortstops the run before anything has happened.- The default
onToolErrorsends the exception message to the model: keep secrets out of exception messages, or replace it.
Usage#
Asking before a tool runs#
RunnerConfig.default[IO]
.withMaxIterations(10)
.withBeforeTool(call => if (call.name == "delete_file") askHuman(call) else IO.pure(ToolDecision.Allow))
Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.