Agents
AI agents are autonomous systems that can reason, make decisions, interact with the environment, and take actions to achieve a specific goal. In Koog, an AI agent is more than just a wrapper around an LLM; it is a structured, type-safe state machine designed for the JVM ecosystem.
Koog agents are built around the following core concepts:
- A prompt executor manages and executes prompts, enabling the agent to interact with LLMs for reasoning and decision-making.
- A strategy defines the agent's workflow. It can be in the form of a directed graph, a function, or a planner. See Agent types.
- An agent can use tools to interact with external data sources and services.
- You can extend and enhance the functionality of AI agents using features.
Tip
For information about creating and running a minimal agent, see Quickstart.
Agent types
Depending on the task you need to perform, Koog provides several agent types:
- Basic agents are ideal for simple tasks that don't require any custom logic. These agents implement a predefined strategy that works for most common use cases.
- Graph-based agents provide full control and flexibility of the agent's workflow, state management, and visualization.
- Functional agents enable you to quickly prototype custom logic as a function with access to the agent's context.
- Planner agents can autonomously plan and execute multistep tasks through iterative cycles until they reach a desired final state.
Agent configuration
Agent configuration defines the agent's execution parameters, including the initial prompt, language model, and iteration limits.
Tip
For information about creating and running a minimal agent, see Quickstart.
For simple agents, besides the mandatory prompt executor and language model, you can specify the initial system prompt and some other parameters directly in the agent constructor:
val agent = AIAgent(
promptExecutor = simpleOpenAIExecutor(System.getenv("YOUR_API_KEY")),
llmModel = OpenAIModels.Chat.GPT4o,
systemPrompt = "You are a helpful assistant.",
temperature = 0.7,
maxIterations = 10
)
Alternatively, you can create an instance of AIAgentConfig
to define the agent's behavior and parameters more granularly, then pass it to the agent constructor.
This enables you to define complex prompts with multiple messages,
conversation history, LLM parameters, and additional execution parameters.
val agentConfig = AIAgentConfig(
prompt = prompt(
id = "assistant",
params = LLMParams(
temperature = 0.7
)
) {
system("You are a helpful assistant.")
},
model = OpenAIModels.Chat.GPT4o,
maxAgentIterations = 10
)
val agent = AIAgent(
promptExecutor = simpleOpenAIExecutor(System.getenv("OPENAI_API_KEY")),
agentConfig = agentConfig
)
Here are the parameters of AIAgentConfig:
-
promptdefines the initial prompt and LLM parameters. -
modelspecifies the language model with which the agent interacts. You can use one of the predefined models or create a custom model configuration. -
maxAgentIterationslimits the maximum number of steps the agent can take before it terminates. Each step is a node in the agent's workflow. -
missingToolsConversionStrategydefines a strategy for handling missing tools during agent execution. -
responseProcessorcan be used to define a custom response processor. For example, it can moderate and validate the response content, change the response format, or log the response.