Method InvokeAsync
InvokeAsync(string, CancellationToken)
Executes the tool with the provided JSON argument payload and returns a JSON payload result.
Task<string> InvokeAsync(string arguments, CancellationToken cancellationToken = default)
Parameters
arguments
stringA UTF-8 JSON string representing an object that should validate against InputSchema.
cancellationToken
CancellationTokenCancellation token propagated from the calling agent run.
Returns
Examples
var tool = new WeatherTool();
var args = new { location = "Toulouse, FR", includeForecast = true };
string input = JsonSerializer.Serialize(args);
string output = await tool.InvokeAsync(input, ct);
// feed 'output' back to the LLM as the tool result
Remarks
Error handling guidance:
- Throw ArgumentException for schema/validation errors.
- Throw HttpRequestException for network/API failures.
- Respect OperationCanceledException if
cancellationToken
is canceled.