runTool

suspend fun FlowCollector<ChatEvent>.runTool(tools: List<AgentTool>, approver: ToolApprover, id: String, name: String, rawArgs: String): String(source)

Execute one tool call of an agent loop, emitting the tool events. Tools with AgentTool.requiresApproval wait for approver first: a denial (with the user's reason) goes back to the model, edited arguments replace the proposed ones. While the tool runs, what it reports through ToolCallContext (interim output, a nested agent run) is streamed as ChatEvent.ToolOutput (preliminary) and ChatEvent.SubagentUpdate.

Public for agent runtimes that run their own loop and plug into AI Elements (e.g. ai-elements-koog), so tool calls look and behave the same everywhere.

Return

the text fed back to the model.