Skip to content

[FEATURE]: add tool.execute.error hook to handle tool call errors #10027

@kynnyhsap

Description

@kynnyhsap

Problem

The plugin system has hooks for tool.execute.before and tool.execute.after, allowing plugins to intercept and modify tool inputs/outputs. However, there's no way to hook into tool errors.

When a tool throws an error, plugins cannot:

  • Log or track the error
  • Modify the error message to be more helpful
  • Recover from known errors by returning a fallback result

Use Case

Sometimes you know exactly what an error means and want to handle it gracefully. For example:

  • A file read fails because the file doesn't exist - you might want to return a friendly message instead of a stack trace
  • An API call hits a rate limit - you might want to modify the error to suggest waiting
  • A known transient error occurs - you might want to return a cached/fallback result

Proposed Solution

Add a tool.execute.error hook that fires when tool execution throws:

"tool.execute.error"?: (
  input: { tool: string; sessionID: string; callID: string; args: any },
  output: { 
    error: Error
    result?: { title: string; output: string; metadata: any }
  },
) => Promise<void>

Plugins could either:

  1. Modify output.error to change the error that gets thrown
  2. Set output.result to return a successful result instead of throwing

Example Usage

export default {
  hooks: {
    "tool.execute.error": async (input, output) => {
      console.error(`Tool ${input.tool} failed:`, output.error.message)

      // Option 1: Modify error message
      if (output.error.message.includes("rate limit")) {
        output.error = new Error("Service temporarily unavailable, please try again")
      }

      // Option 2: Recover from error by providing a result
      if (input.tool === "read" && output.error.message.includes("not found")) {
        output.result = {
          title: "File not found",
          output: `The file ${input.args.filePath} does not exist.`,
          metadata: {}
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions