Fluent DSL and Kotlin DSL for building autonomous agents with planning capabilities on the JVM, featuring annotation-based and programmatic configuration for agentic flows with Spring Boot integration
The Embabel Agent API provides pre-built tool implementations for common operations including file I/O, mathematics, system operations, and protocol integrations.
Tools for reading files and directories.
object FileReadTools {
/** Read file contents */
@LlmTool(description = "Read contents of a file")
fun readFile(
@LlmTool.Param(description = "Path to file")
path: String
): String
/** List files in directory */
@LlmTool(description = "List files in a directory")
fun listDirectory(
@LlmTool.Param(description = "Directory path")
directory: String
): List<String>
/** Get file metadata */
@LlmTool(description = "Get file information")
fun getFileInfo(
@LlmTool.Param(description = "File path")
path: String
): FileInfo
/** Check if file exists */
@LlmTool(description = "Check if file exists")
fun fileExists(
@LlmTool.Param(description = "File path")
path: String
): Boolean
}
data class FileInfo(
val name: String,
val size: Long,
val lastModified: Instant,
val isDirectory: Boolean,
val isReadable: Boolean,
val isWritable: Boolean
)FileReadTools Usage:
@Action(description = "Process file with LLM")
fun processFile(
filePath: String,
context: ActionContext
): FileAnalysis {
val fileTools = ToolObject.from(FileReadTools)
return context.promptRunner()
.withToolObject(fileTools)
.createObject<FileAnalysis>("""
Read the file at $filePath and analyze its contents.
Provide a summary and key findings.
""")
}Tools for writing and modifying files.
object FileWriteTools {
/** Write content to file */
@LlmTool(description = "Write content to a file")
fun writeFile(
@LlmTool.Param(description = "File path")
path: String,
@LlmTool.Param(description = "Content to write")
content: String
): Boolean
/** Append to file */
@LlmTool(description = "Append content to file")
fun appendToFile(
@LlmTool.Param(description = "File path")
path: String,
@LlmTool.Param(description = "Content to append")
content: String
): Boolean
/** Create directory */
@LlmTool(description = "Create a directory")
fun createDirectory(
@LlmTool.Param(description = "Directory path")
path: String
): Boolean
/** Delete file */
@LlmTool(description = "Delete a file")
fun deleteFile(
@LlmTool.Param(description = "File path")
path: String
): Boolean
/** Copy file */
@LlmTool(description = "Copy a file")
fun copyFile(
@LlmTool.Param(description = "Source path")
source: String,
@LlmTool.Param(description = "Destination path")
destination: String
): Boolean
/** Move file */
@LlmTool(description = "Move a file")
fun moveFile(
@LlmTool.Param(description = "Source path")
source: String,
@LlmTool.Param(description = "Destination path")
destination: String
): Boolean
}FileWriteTools Usage:
@Action(description = "Generate and save report")
fun generateReport(
data: Dataset,
outputPath: String,
context: ActionContext
): String {
val fileTools = ToolObject.from(FileWriteTools)
return context.promptRunner()
.withToolObject(fileTools)
.generateText("""
Analyze this dataset and write a report to $outputPath:
${data.summary}
""")
}General file utilities.
object FileTools {
/** Search for files by pattern */
@LlmTool(description = "Search for files matching pattern")
fun searchFiles(
@LlmTool.Param(description = "Directory to search")
directory: String,
@LlmTool.Param(description = "Pattern to match")
pattern: String
): List<String>
/** Get file content type */
@LlmTool(description = "Determine file content type")
fun getContentType(
@LlmTool.Param(description = "File path")
path: String
): String
/** Calculate file hash */
@LlmTool(description = "Calculate file hash")
fun calculateHash(
@LlmTool.Param(description = "File path")
path: String,
@LlmTool.Param(description = "Hash algorithm", required = false)
algorithm: String = "SHA-256"
): String
}Pattern-based file search.
class PatternSearch(
private val baseDirectory: String
) {
@LlmTool(description = "Search files by regex pattern")
fun searchByRegex(
@LlmTool.Param(description = "Regular expression pattern")
pattern: String
): List<SearchResult>
@LlmTool(description = "Search files by extension")
fun searchByExtension(
@LlmTool.Param(description = "File extension")
extension: String
): List<String>
@LlmTool(description = "Search file contents")
fun searchContents(
@LlmTool.Param(description = "Text to search for")
query: String
): List<SearchResult>
}
data class SearchResult(
val path: String,
val matchedContent: String?,
val lineNumber: Int?
)Directory-based file operations.
class LocalDirectory(
private val path: String
) {
@LlmTool(description = "List all files in directory")
fun listFiles(): List<String>
@LlmTool(description = "Get directory tree")
fun getTree(
@LlmTool.Param(description = "Maximum depth", required = false)
maxDepth: Int = 3
): DirectoryTree
@LlmTool(description = "Get directory statistics")
fun getStatistics(): DirectoryStats
}
data class DirectoryTree(
val path: String,
val children: List<DirectoryTree>
)
data class DirectoryStats(
val totalFiles: Int,
val totalDirectories: Int,
val totalSize: Long
)Content transformers for different file types.
object WellKnownFileContentTransformers {
val JSON_TRANSFORMER: FileContentTransformer
val XML_TRANSFORMER: FileContentTransformer
val YAML_TRANSFORMER: FileContentTransformer
val CSV_TRANSFORMER: FileContentTransformer
val MARKDOWN_TRANSFORMER: FileContentTransformer
}
interface FileContentTransformer {
fun transform(content: String): Any
fun format(obj: Any): String
}Track file operations for audit.
interface FileReadLog {
fun logRead(path: String, timestamp: Instant)
fun getReadHistory(): List<FileOperation>
}
interface FileChangeLog {
fun logChange(path: String, operation: OperationType, timestamp: Instant)
fun getChangeHistory(): List<FileOperation>
}
enum class OperationType {
READ,
WRITE,
DELETE,
MOVE,
COPY
}
data class FileOperation(
val path: String,
val operation: OperationType,
val timestamp: Instant,
val user: String?
)Mathematical computation tools.
object MathTools {
/** Evaluate mathematical expression */
@LlmTool(description = "Calculate mathematical expression")
fun calculate(
@LlmTool.Param(description = "Mathematical expression")
expression: String
): Double
/** Evaluate formula with variables */
@LlmTool(description = "Evaluate formula with variables")
fun evaluateFormula(
@LlmTool.Param(description = "Formula with variables")
formula: String,
@LlmTool.Param(description = "Variable values as JSON")
variables: String
): Double
/** Solve equation */
@LlmTool(description = "Solve mathematical equation")
fun solveEquation(
@LlmTool.Param(description = "Equation to solve")
equation: String
): List<Double>
/** Statistical calculations */
@LlmTool(description = "Calculate statistics")
fun calculateStats(
@LlmTool.Param(description = "Numbers as comma-separated values")
numbers: String
): Statistics
}
data class Statistics(
val mean: Double,
val median: Double,
val mode: Double?,
val standardDeviation: Double,
val min: Double,
val max: Double,
val count: Int
)MathTools Usage:
@Action(description = "Solve problem with math tools")
fun solveMathProblem(
problem: String,
context: ActionContext
): Solution {
val mathTools = ToolObject.from(MathTools)
return context.promptRunner()
.withToolObject(mathTools)
.createObject<Solution>("""
Solve this problem: $problem
Use the available math tools to perform calculations.
""")
}macOS automation tools.
object AppleScriptTools {
/** Execute AppleScript */
@LlmTool(description = "Execute AppleScript code")
fun executeScript(
@LlmTool.Param(description = "AppleScript code")
script: String
): String
/** Control application */
@LlmTool(description = "Control macOS application")
fun controlApp(
@LlmTool.Param(description = "Application name")
appName: String,
@LlmTool.Param(description = "Command to execute")
command: String
): String
/** Get system info */
@LlmTool(description = "Get macOS system information")
fun getSystemInfo(): SystemInfo
}
data class SystemInfo(
val osVersion: String,
val computerName: String,
val userName: String
)Model Context Protocol tool factory.
class McpToolFactory(
private val endpoint: String
) {
/** Create tools from MCP server */
fun createTools(): List<Tool>
/** Get available tools */
fun listAvailableTools(): List<ToolDefinition>
/** Connect to MCP server */
fun connect(): McpConnection
}
interface McpConnection {
fun invoke(toolName: String, parameters: Map<String, Any>): Any
fun close()
}MCP Tool Usage:
@Action(description = "Use MCP tools")
fun useMcpTools(
query: String,
context: ActionContext
): Result {
val mcpFactory = McpToolFactory("http://localhost:8080")
val mcpTools = mcpFactory.createTools()
return context.promptRunner()
.withTool(*mcpTools.toTypedArray())
.createObject<Result>(query)
}Group MCP tools for organization.
class McpToolGroup(
private val name: String,
private val tools: List<Tool>
) : ToolGroup {
@LlmTool(description = "List available MCP tools")
fun listTools(): List<String>
@LlmTool(description = "Invoke MCP tool by name")
fun invokeTool(
@LlmTool.Param(description = "Tool name")
name: String,
@LlmTool.Param(description = "Tool parameters as JSON")
parameters: String
): String
}Tool for agent invocation.
class AgentTool(
private val agent: Agent,
private val agentPlatform: AgentPlatform
) : Tool {
override fun call(input: String): Tool.Result {
val result = agentPlatform.executeAgent(agent, input, Any::class.java)
return Tool.Result.text(result.toString())
}
}Tool for achieving goals.
class GoalTool(
private val goal: Goal,
private val agentPlatform: AgentPlatform
) : Tool {
override fun call(input: String): Tool.Result {
// Execute agent to achieve goal
val result = achieveGoal(goal, input)
return Tool.Result.text(result)
}
}Factory for creating per-goal tools.
class PerGoalToolFactory(
private val agent: Agent
) {
fun createTools(): List<Tool> {
return agent.goals.map { goal ->
GoalTool(goal, agentPlatform)
}
}
}Factory for achievable goals tool group.
class AchievableGoalsToolGroupFactory(
private val agent: Agent
) : ToolGroupFactory {
override fun createToolGroup(): ToolGroup {
val goalTools = agent.goals
.filter { it.isAchievable() }
.map { goal -> GoalTool(goal, agentPlatform) }
return ToolGroup("achievable-goals", goalTools)
}
}Tool handoff utilities.
object Handoffs {
/** Create handoff to agent */
fun toAgent(agent: Agent): Tool
/** Create handoff to goal */
fun toGoal(goal: Goal): Tool
}Default callback tools for process interaction.
object DefaultProcessCallbackTools {
@LlmTool(description = "Request human approval")
fun requestApproval(
@LlmTool.Param(description = "What needs approval")
request: String
): Boolean
@LlmTool(description = "Ask question")
fun askQuestion(
@LlmTool.Param(description = "Question to ask")
question: String
): String
@LlmTool(description = "Report progress")
fun reportProgress(
@LlmTool.Param(description = "Progress message")
message: String
)
}Create custom tools for your domain.
@EmbabelComponent
class DatabaseTools(
private val dataSource: DataSource
) {
@LlmTool(description = "Query database")
fun query(
@LlmTool.Param(description = "SQL query")
sql: String
): List<Map<String, Any>> {
return jdbcTemplate.queryForList(sql)
}
@LlmTool(description = "Get table schema")
fun getSchema(
@LlmTool.Param(description = "Table name")
tableName: String
): TableSchema {
return schemaReader.read(tableName)
}
@LlmTool(description = "Execute stored procedure")
fun executeProcedure(
@LlmTool.Param(description = "Procedure name")
name: String,
@LlmTool.Param(description = "Parameters as JSON")
params: String
): Any {
return procedureExecutor.execute(name, parseParams(params))
}
}
data class TableSchema(
val tableName: String,
val columns: List<Column>
)
data class Column(
val name: String,
val type: String,
val nullable: Boolean,
val primaryKey: Boolean
)interface Tool {
fun call(input: String): Result
}
interface ToolGroup {
val name: String
val tools: List<Tool>
}
interface ToolGroupFactory {
fun createToolGroup(): ToolGroup
}
interface DirectoryBased {
val baseDirectory: String
}Install with Tessl CLI
npx tessl i tessl/maven-com-embabel-agent--embabel-agent-api@0.3.0docs