continueWithToolResult static method

Future<ToolCallingResult> continueWithToolResult(
  1. String originalPrompt,
  2. ToolResult toolResult, {
  3. ToolCallingOptions? options,
})

Continue generation after manual tool execution.

Use this when autoExecute is false and you've executed tools manually.

originalPrompt The original user prompt toolResult Result from manual tool execution options Tool calling options

Implementation

static Future<ToolCallingResult> continueWithToolResult(
  String originalPrompt,
  ToolResult toolResult, {
  ToolCallingOptions? options,
}) async {
  final opts = options ?? const ToolCallingOptions();
  final tools = opts.tools ?? getRegisteredTools();
  final toolsJson = toolsToJson(tools);

  final resultJson = toolResult.result != null
      ? toolResultToJsonString(toolResult.result!)
      : '{"error": "${toolResult.error ?? 'Unknown error'}"}';

  final followupPrompt = DartBridgeToolCalling.shared.buildFollowupPrompt(
    originalPrompt: originalPrompt,
    toolsPrompt: opts.keepToolsAvailable
        ? DartBridgeToolCalling.shared.formatToolsPrompt(toolsJson)
        : null,
    toolName: toolResult.toolName,
    toolResultJson: resultJson,
    keepToolsAvailable: opts.keepToolsAvailable,
  );

  // Continue with the follow-up
  return generateWithTools(followupPrompt, options: opts);
}