Class ToolCall
Represents a tool invocation request emitted by a language model.
public sealed class ToolCall
- Inheritance
-
ToolCall
- Inherited Members
Examples
Example: Processing tool calls from agent execution
using LMKit.Agents;
using LMKit.Agents.Tools;
var result = await agent.RunAsync("What's the weather in Paris?");
// Inspect which tools were called during execution
if (result.ToolCalls != null && result.ToolCalls.Count > 0)
{
Console.WriteLine($"Agent made {result.ToolCalls.Count} tool call(s):");
foreach (ToolCall call in result.ToolCalls)
{
Console.WriteLine($" Tool: {call.Name}");
Console.WriteLine($" ID: {call.Id}");
Console.WriteLine($" Arguments: {call.ArgumentsJson}");
Console.WriteLine();
}
}
Remarks
When a language model decides to use a tool, it emits a tool call containing the tool's name and the arguments to pass. The ToolCall class captures this information so the agent runtime can locate the tool in the registry and invoke it.
Lifecycle:
- Model generates a tool call with name and arguments
- Runtime parses the output into a ToolCall instance
- Runtime looks up the tool by Name in the registry
- Runtime invokes the tool with ArgumentsJson
- Tool result is associated back using Id for correlation
Correlation:
The Id property enables correlation between tool calls and their results,
which is important when multiple tools are called in a single turn. Always include the
same Id in the corresponding ToolCallResult.
Properties
- ArgumentsJson
Gets the JSON arguments to pass to the tool.
- Id
Gets the unique identifier for this tool call within a turn.
- Name
Gets the name of the tool to invoke.