Skip to content

LLM-based planners

LLM-based planners use LLMs to generate and evaluate plans. They operate on a string-based state and execute steps through LLM requests. String-based state means that the agent state is a single string. At every step, the agent accepts an initial state string and returns the final state string as the result.

Prerequisites

Ensure your environment and project meet the following requirements:

  • JDK 17+
  • Kotlin 2.2.0+
  • Gradle 8.0+ or Maven 3.8+

Add the Koog package as a dependency:

build.gradle.kts
dependencies {
    implementation("ai.koog:koog-agents:0.6.3")
}
build.gradle
dependencies {
    implementation 'ai.koog:koog-agents:0.6.3'
}
pom.xml
<dependency>
    <groupId>ai.koog</groupId>
    <artifactId>koog-agents-jvm</artifactId>
    <version>0.6.3</version>
</dependency>

Get an API key from an LLM provider or run a local LLM via Ollama. For more information, see Quickstart.

Examples on this page assume that you have set the OPENAI_API_KEY environment variable.

Koog provides two simple planners:

  • SimpleLLMPlanner generates a plan only once at the very beginning and then follows the plan until it is completed. To include replanning, extend SimpleLLMPlanner and override the assessPlan method, indicating when the agent should replan.
  • SimpleLLMWithCriticPlanner implements the assessPlan method that uses an LLM to check the validity of the plan via an LLM request and assess whether the agent should replan.

The following example shows how to create a simple planner agent using SimpleLLMPlanner:

// Create the planner
val planner = SimpleLLMPlanner()

// Wrap it in a planner strategy
val strategy = AIAgentPlannerStrategy(
    name = "simple-planner",
    planner = planner
)

// Configure the agent
val agentConfig = AIAgentConfig(
    prompt = prompt("planner") {
        system("You are a helpful planning assistant.")
    },
    model = OpenAIModels.Chat.GPT4o,
    maxAgentIterations = 50
)

// Create the planner agent
val agent = PlannerAIAgent(
    promptExecutor = simpleOpenAIExecutor(System.getenv("OPENAI_API_KEY")),
    strategy = strategy,
    agentConfig = agentConfig
)

suspend fun main() {
    // Run the agent with a task
    val result = agent.run("Create a plan to organize a team meeting")
    println(result)
}

Next steps