invokeTool method

Future<String?> invokeTool(
  1. int sessionId,
  2. String toolName, [
  3. Map<String, dynamic> arguments = const {}
])

Plays the model calling toolName on sessionId with arguments, and returns what the native host would hand back to the model: the tool's result as JSON, null when it yielded nothing, or {"error": ...} when the tool body threw.

Dispatch, argument decoding and error encoding all go through the same LocalAiToolRegistry the native host uses, so a tool loop tested here is tested against the real rules: a tool is reachable only from the session it was registered on, and throws UnknownToolException otherwise.

Implementation

Future<String?> invokeTool(
  int sessionId,
  String toolName, [
  Map<String, dynamic> arguments = const {},
]) {
  calls.add('invokeTool');
  toolCalls.add(
    FakeToolCall(
      sessionId: sessionId,
      toolName: toolName,
      arguments: arguments,
    ),
  );
  return _tools.invoke(sessionId, toolName, jsonEncode(arguments));
}