provideToolCallMetadata

abstract fun provideToolCallMetadata(feature: AIAgentFeature<*, *>, handle: suspend (eventContext: ToolCallStartingContext) -> Map<String, Any?>)(source)

Registers a handler that contributes metadata for every tool call.

The handler fires before the tool executes, receives the same ToolCallStartingContext used by interceptToolCallStarting, and returns a Map<String, Any?> of values to merge into the metadata threaded into ai.koog.agents.core.tools.Tool.execute.

Use this to attach cross-cutting per-call context (trace span id, correlation id, feature flags) without expanding the tool's argument schema. Return an empty map to contribute nothing.

Merge precedence (documented in ai.koog.agents.core.environment.ContextualAgentEnvironment): caller-supplied metadata wins over feature contributions on key collision.