AIAgentRunSession

Represents a session for running an ai.koog.agents.core.agent.AIAgent.

An AIAgentRunSession encapsulates a single execution lifecycle of an AI agent, providing a controlled environment for running the agent's strategy with specific input and context. Each session is independent and manages its own execution state, pipeline coordination, and resource lifecycle.

Sessions are typically created through ai.koog.agents.core.agent.AIAgentBase.createSession and can be reused for multiple sequential executions. The session handles:

  • Pipeline preparation and feature initialization

  • Strategy execution with proper error handling

  • Event notifications at each execution stage

  • Resource cleanup after execution completes

Parameters

Input

the type of input data required by the agent's strategy.

Output

the type of output data produced by the agent's strategy.

TContext

the type of context used during execution, extending AIAgentContext.

See also

Functions

Link copied to clipboard
abstract fun context(): TContext

Returns the context for the current AI agent execution session. The context provides access to essential details such as environment, input, execution state, configuration, and other metadata required for the AI agent's operations.

Link copied to clipboard

Retrieves a feature from the AIAgentRunSession.pipeline associated with this session using the specified key.

Link copied to clipboard

Retrieves a feature from the AIAgentRunSession.pipeline associated with this session using the specified key or throws an exception if it is not available.

Link copied to clipboard
abstract fun pipeline(): AIAgentPipeline?

Returns the pipeline associated with this session. The pipeline becomes available after the first call to run with a pipeline parameter.

Link copied to clipboard
abstract suspend fun run(input: Input): Output

Executes the agent pipeline with the given context and input, producing an output.