Skip to content

Commit 1a1ab28

Browse files
committed
feat(hooks): apply ModifiedInput from pre-tool hooks to tool call arguments
The pre-tool hook system already supported returning updated_input via hook_specific_output, and the executor populated Result.ModifiedInput. However, the runtime never applied it back to toolCall.Function.Arguments before execution, making input-rewriting hooks (like RTK) ineffective. Marshal ModifiedInput to JSON and overwrite the tool call arguments when a pre-tool hook provides modified input. Assisted-By: cagent
1 parent 6621ea9 commit 1a1ab28

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/runtime/runtime.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,8 +1837,19 @@ func (r *LocalRuntime) runTool(ctx context.Context, tool tools.Tool, toolCall to
18371837
events <- HookBlocked(toolCall, tool, result.Message, a.Name())
18381838
r.addToolErrorResponse(ctx, sess, toolCall, tool, events, a, "Tool call blocked by hook: "+result.Message)
18391839
return
1840-
case result.SystemMessage != "":
1841-
events <- Warning(result.SystemMessage, a.Name())
1840+
default:
1841+
if result.SystemMessage != "" {
1842+
events <- Warning(result.SystemMessage, a.Name())
1843+
}
1844+
if result.ModifiedInput != nil {
1845+
updated, merr := json.Marshal(result.ModifiedInput)
1846+
if merr != nil {
1847+
slog.Warn("Failed to marshal modified tool input from hook", "tool", toolCall.Function.Name, "error", merr)
1848+
} else {
1849+
slog.Debug("Pre-tool hook modified tool input", "tool", toolCall.Function.Name)
1850+
toolCall.Function.Arguments = string(updated)
1851+
}
1852+
}
18421853
}
18431854
}
18441855

0 commit comments

Comments
 (0)