Help us shape the future of Go! Take the 2026 Go Developer Survey

patchtoolcalls

package
v0.9.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package patchtoolcalls provides a middleware that patches dangling tool calls in the message history.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a new patch tool calls middleware with the given configuration.

The middleware scans the message history before each model invocation and inserts placeholder tool messages for any tool calls that don't have corresponding responses.

func NewTyped added in v0.9.0

NewTyped creates a new generic patch tool calls middleware.

The middleware scans the message history before each model invocation and inserts placeholder tool messages for any tool calls that don't have corresponding responses.

Types

type Config

type Config struct {
	// PatchedContentGenerator is an optional custom function to generate the content
	// of patched tool messages as a plain string.
	//
	// Deprecated: Use PatchedToolResultGenerator instead, which receives the original
	// tool-call arguments and can return either plain Content or an EnhancedTool
	// ToolResult. Kept for backward compatibility; ignored when
	// PatchedToolResultGenerator is set.
	//
	// Parameters:
	//   - ctx: the context for the operation
	//   - toolName: the name of the tool that was called
	//   - toolCallID: the id of the tool call
	//
	// Returns:
	//   - string: the content to use for the patched tool message
	//   - error: any error that occurred during generation
	PatchedContentGenerator func(ctx context.Context, toolName, toolCallID string) (string, error)

	// PatchedToolResultGenerator generates a patched tool result for a dangling tool call.
	// It is preferred over PatchedContentGenerator when both are set.
	//
	// Return PatchedToolResult.Content for plain text, or PatchedToolResult.ToolResult
	// for EnhancedTool-style multimodal results. The two fields are mutually exclusive.
	//
	// Parameters:
	//   - ctx: the context for the operation
	//   - toolName: the name of the tool that was called
	//   - toolCallID: the id of the tool call
	//   - toolArgument: the original tool-call arguments (Text is the JSON arguments string)
	//
	// Returns:
	//   - *PatchedToolResult: the patched tool result to insert into history
	//   - error: any error that occurred during generation
	PatchedToolResultGenerator func(
		ctx context.Context,
		toolName string,
		toolCallID string,
		toolArgument *schema.ToolArgument,
	) (*PatchedToolResult, error)
}

Config defines the configuration options for the patch tool calls middleware.

type PatchedToolResult added in v0.9.14

type PatchedToolResult struct {
	Content    string
	ToolResult *schema.ToolResult
}

PatchedToolResult is the value returned by PatchedToolResultGenerator.

Content and ToolResult are mutually exclusive:

  • Content: plain-text tool message (typical for InvokableTool users)
  • ToolResult: EnhancedTool-style result (text and/or multimodal parts)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL