Overview
AIAgent is the main orchestrator for executing AI agent workflows. It manages strategies, tools, features, and LLM communication through a flexible, extensible architecture.
AIAgent is an
expect class with platform-specific implementations for JVM, JS, and other Kotlin multiplatform targets.Class Definition
Type Parameters
The type of input the AI agent will process
The type of output the AI agent will produce
Properties
Unique identifier for the AI agent instance
The configuration for the AI agent, including prompt setup, model settings, and iteration limits
Methods
run
Executes the AI agent with the given input and retrieves the resulting output.The input for the agent to process
Optional session identifier for tracking execution
The output produced by the agent after processing the input
createSession
Creates a new session for executing the agent with custom lifecycle management.Optional session identifier
A session instance for independent agent execution with state tracking
Factory Methods
Graph-based Agent
Create an agent with a graph-based execution strategy:Executor responsible for processing prompts and interacting with the language model
Configuration for the AI agent
The strategy for executing the agent’s graph logic
Registry of tools available for use by the agent
Unique identifier for the agent. Random UUID will be generated if null
Clock instance for time-related operations
Lambda expression to install additional features in the agent’s feature context
Functional Agent
Create an agent with a functional execution strategy:Quick Configuration
Create an agent with model and processor directly:The specific large language model to be used
Processor for handling the model’s responses
Optional system prompt for the agent
Model temperature, typically ranging from 0.0 to 1.0
Number of response choices to generate
Maximum number of iterations the agent is allowed to perform
Builder Pattern
Get a builder for fluent agent configuration:Usage Examples
Basic Graph Agent
Agent with Features
Using Builder
Session Management
Related Types
- AIAgentStrategy - Defines agent execution logic
- AIAgentEnvironment - Tool execution context
- ToolRegistry - Tool management
- AIAgentFeature - Extensible capabilities
Source Reference
Defined in:agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/AIAgent.kt