diff --git a/kong/plugins/ai-prompt-decorator/filters/decorate-prompt.lua b/kong/plugins/ai-prompt-decorator/filters/decorate-prompt.lua index df0ad052b9180..525c08223631d 100644 --- a/kong/plugins/ai-prompt-decorator/filters/decorate-prompt.lua +++ b/kong/plugins/ai-prompt-decorator/filters/decorate-prompt.lua @@ -6,6 +6,7 @@ -- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] local new_tab = require("table.new") +local deep_copy = require("kong.tools.table").deep_copy local ai_plugin_ctx = require("kong.llm.plugin.ctx") local _M = { @@ -36,6 +37,9 @@ local function execute(request, conf) local prepend = conf.prompts.prepend or EMPTY local append = conf.prompts.append or EMPTY + -- ensure we don't modify the original request + request = deep_copy(request) + local old_messages = request.messages local new_messages = new_tab(#append + #prepend + #old_messages, 0) request.messages = new_messages @@ -84,4 +88,4 @@ function _M:run(conf) return true end -return _M \ No newline at end of file +return _M