Skip to main content

Agent DSL

Aigentic DSL​

Aigentic provides a powerful and intuitive Kotlin DSL (Domain-Specific Language) for building and configuring AI agents. The DSL is designed to be expressive, type-safe, and easy to use, allowing you to create sophisticated AI agents with minimal boilerplate code.

Core Components​

The Aigentic agent DSL consists of several key components:

  • Agents - Creating and configuring agents
  • Providers - Connecting to LLM providers
  • Tools - Extending agents with custom capabilities

Agent Building​

The core of the Aigentic DSL is the agent function, which allows you to create and configure AI agents:


@AigenticParameter
data class Answer(val message: String)

@AigenticParameter
data class AnswerSavedResult(val result: String)

// Using generic types to specify the output type
agent<String, Answer> {

// Configure your provider of choice
openAIModel {
apiKey("<your-api-key>")
modelIdentifier(OpenAIModelIdentifier.GPT5_4Mini)
}

// Configure the task for the agent
task("Answer questions about Kotlin Multiplatform") {
addInstruction("Provide concise and accurate answers")
}

// Define more context
context {
addText("<Additional information about Kotlin Multiplatform>")
}

// Add capabilities
addTool(name = "saveAnswer", description = "Saves the answer to the database") { input: Answer ->
AnswerSavedResult("Answer saved successfully: ${input.message}")
}
}

This fluent API makes it easy to configure various aspects of your agent, including the LLM model to use, system prompts, and tools.

Model Integration​

Aigentic's DSL provides a consistent interface for working with different LLM providers:

agent<String, Answer> {
// OpenAI model
openAIModel {
apiKey("YOUR_API_KEY")
modelIdentifier(OpenAIModelIdentifier.GPT5_5)
}
// ...
}

agent<String, Answer> {
// Gemini model
geminiModel {
apiKey("YOUR_API_KEY")
modelIdentifier(GeminiModelIdentifier.Gemini3_5Flash)
}
// ...
}

agent<String, Answer> {
// Ollama model
ollamaModel {
apiUrl("http://localhost:11434/v1/")
modelIdentifier(OpenAIModelIdentifier.Custom("llama3"))
}
// ...
}

Tool Definition​

Aigentic provides functions for defining custom tools that extend your agent's capabilities. You can use addTool to inline a tool directly into the agent, or create a reusable tool using createTool.

@AigenticParameter
data class WeatherRequest(val location: String)
@AigenticParameter
data class WeatherResponse(val temperature: Double, val conditions: String)

val weatherTool = createTool<WeatherRequest, WeatherResponse>(
name = "getWeather",
description = "Get the current weather for a location"
) { request ->
weatherService.getWeather(request.location)
}