PlaybookTool

A tool with conditional tool unlocking that uses an LLM to orchestrate sub-tools.

Unlike com.embabel.agent.api.tool.agentic.simple.SimpleAgenticTool which makes all tools available immediately, a PlaybookTool allows tools to be progressively unlocked based on conditions such as:

  • Prerequisites: unlock after other tools have been called

  • Artifacts: unlock when certain artifact types are produced

  • Blackboard: unlock based on process state

  • Custom predicates: unlock based on arbitrary conditions

This provides more predictable LLM behavior by guiding it through a structured sequence of available tools.

Usage

// Kotlin curried syntax
PlaybookTool("researcher", "Research and analyze topics")
.withTools(searchTool, fetchTool) // always available
.withTool(analyzeTool)(searchTool) // unlocks after search
.withTool(summarizeTool)(analyzeTool) // unlocks after analyze

// Java fluent syntax
new PlaybookTool("researcher", "Research and analyze topics")
.withTools(searchTool, fetchTool)
.withTool(analyzeTool).unlockedBy(searchTool)
.withTool(summarizeTool).unlockedBy(analyzeTool);

Parameters

definition

Tool definition (name, description, input schema)

metadata

Optional tool metadata

llm

LLM to use for orchestration. It is good practice to provide

unlockedTools

Tools that are always available

lockedTools

Tools with unlock conditions

systemPromptCreator

Create prompt for the LLM to use, given context and input

maxIterations

Maximum number of tool loop iterations

Constructors

Link copied to clipboard
constructor(name: String, description: String)

Create a playbook tool with the given name and description.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val definition: Tool.Definition
Link copied to clipboard
open override val llm: <Error class: unknown class>
Link copied to clipboard

Number of conditionally-locked tools.

Link copied to clipboard
open override val maxIterations: Int
Link copied to clipboard
open override val metadata: Tool.Metadata
Link copied to clipboard

Number of always-unlocked tools.

Functions

Link copied to clipboard
open override fun call(input: String): Tool.Result

Execute the tool with JSON input.

Link copied to clipboard
inline fun <T : Any> Tool.requireType(message: String? = null): Tool

Wrap this tool to require a value of type T before execution (reified).

fun <T : Any> Tool.requireType(type: Class<T>, messageProvider: (String) -> String? = { null }): Tool

Wrap this tool to require a value of type T before execution.

Link copied to clipboard
fun Tool.toSpringToolCallback(): <Error class: unknown class>

Extension function to convert an Embabel Tool to a Spring AI ToolCallback.

Link copied to clipboard
inline fun <T : Tool> Tool.unwrapAs(): T?

Unwrap a tool to find a specific type, or return null if not found.

Link copied to clipboard

Wrap this tool to conditionally await before execution.

Link copied to clipboard
fun Tool.withConfirmation(messageProvider: (String) -> String): Tool

Wrap this tool to always require confirmation before execution.

Link copied to clipboard
open fun withDescription(newDescription: String): Tool

Create a new tool with a different description. Useful for providing context-specific descriptions while keeping the same functionality.

Link copied to clipboard
fun Tool.withEventPublication(agentProcess: AgentProcess, action: Action?, llmOptions: <Error class: unknown class>): Tool

Extension function to wrap a Tool with event publication.

Link copied to clipboard
open override fun withLlm(llm: <Error class: unknown class>): PlaybookTool

Create a copy with different LLM options.

Link copied to clipboard
open override fun withMaxIterations(maxIterations: Int): PlaybookTool

Create a copy with a different max iterations limit.

Link copied to clipboard
open fun withName(newName: String): Tool

Create a new tool with a different name. Useful for namespacing tools when combining multiple tool sources.

Link copied to clipboard
open fun withNote(note: String): Tool

Create a new tool with an additional note appended to the description. Useful for adding context-specific hints to an existing tool.

Link copied to clipboard
open override fun withParameter(parameter: Tool.Parameter): PlaybookTool

Create a copy with an additional parameter in the definition.

Link copied to clipboard

Create a copy with a fixed system prompt. This is a convenience method that delegates to withSystemPrompt with a creator.

Create a copy with a dynamic system prompt creator. The creator receives the execution context and input string.

Link copied to clipboard

Begin registration of a tool with unlock conditions. Returns a ToolRegistration that can be used with curried syntax or fluent API.

Link copied to clipboard

Register a class whose @LlmTool methods become available as tools when a single instance of that type is returned as an artifact.

Register a class that can contribute @LlmTool methods when a single instance is retrieved. Kotlin-friendly version using reified type parameter.

inline fun <T : Any> withToolChainingFrom(noinline predicate: (T, AgentProcess?) -> Boolean): PlaybookTool

Register a class with a predicate. Kotlin-friendly version using reified type parameter.

open override fun <T : Any> withToolChainingFrom(type: Class<T>, predicate: DomainToolPredicate<T>): PlaybookTool

Register a domain class with a predicate to control when its @LlmTool methods are exposed.

Link copied to clipboard

Enable auto-discovery of chained tools from any returned artifact.

Link copied to clipboard
open override fun withToolObject(toolObject: Any): PlaybookTool

Create a copy with tools extracted from an object with @LlmTool methods. If the object has no @LlmTool methods, returns this unchanged.

Link copied to clipboard
fun withTools(vararg tools: Tool): PlaybookTool

Add tools that are always available (no unlock conditions).