ContextualAgentEnvironment

Represents an AI agent environment that operates within the context of a specific agent framework.

This class acts as a decorator over an existing AIAgentEnvironment, augmenting operations with contextual processing using the provided AIAgentContext.

Metadata handling: when executeTool is called with a ToolCallMetadata argument, this environment collects metadata contributions from every feature that registered a handler via ai.koog.agents.core.feature.pipeline.AIAgentPipelineAPI.provideToolCallMetadata and merges them with the caller-supplied metadata. On key collision, the caller's value wins, so an explicit call-site override is never silently replaced by a feature contribution. After the merge, the framework injects the live AIAgentContext under AgentContextAwareTool.AgentContextKey; the framework's value always wins over caller and feature entries so a tool always observes the real context driving the current call. The merged metadata is then passed to the wrapped environment, which threads it into ai.koog.agents.core.tools.ToolBase.execute.

Parameters

environment

The underlying agent environment responsible for managing tool execution.

context

The context that augments the environment with additional behavioral and execution information.

Constructors

Link copied to clipboard
constructor(environment: AIAgentEnvironment, context: AIAgentContext)

Constructs a new instance of ContextualAgentEnvironment with a decorated environment and a contextual context.

Functions

Link copied to clipboard
open suspend override fun executeTool(toolCall: MessagePart.Tool.Call): ReceivedToolResult

Executes a tool call and returns its result.

open suspend override fun executeTool(toolCall: MessagePart.Tool.Call, metadata: ToolCallMetadata): ReceivedToolResult

Executes a tool call with caller-supplied metadata and returns its result.

Link copied to clipboard

Executes a batch of tool calls within the AI agent environment and processes their results.

Executes a batch of tool calls with shared caller-supplied metadata and returns their results.

Link copied to clipboard
open suspend override fun reportProblem(exception: Throwable)

Reports a problem that occurred within the environment.