Send Retool AI query response to Chat when triggering AI from a query

Hi,

I have built an ai agent that receives one of two inputs:

  1. A question with queried data
  2. a follow-up without the data

currently the logic for LLMprompt (input for my retoolAI)

// Check if it's a follow-up prompt
const isFollowUp = IsFollowUp.value;

// Compose prompt
const prompt = isFollowUp
  ? `Follow-up Question: ${chat1.lastMessage}\n\nAnswer the question based only on the prior conversation.`
  : `You will be provided a prompt, Customer Name, datasource(s), and metadata providing descriptions of each column. Follow the prompt exactly as outlined with an emphasis on the format and only using the provided knowledge. Do not hallucinate.

Customer Name: ${customer_selector.selectedLabel}
Prompt to answer: ${chat1.lastMessage}
Data to use:
${JSON.stringify(dataTable.data)}

Column Descriptions for Context:
${MetadataMarkdown.value}
`;

// ✅ Log the prompt to the console for debugging
console.log("📤 Prompt sent to IntelligenceEngine:", prompt);

// Return the prompt
return prompt;

Now my issue is, the only way to get the Retool AI response in chat window is if you trigger the AI directly on send of chat. I need to trigger a script that triggers LLMPrompt to construct the new prompt with chat1.lastmessage and on success triggers retool AI query after.

When I attempt this, my issue is that the response is not sent to Chat1 window.

Anyone have any suggestions?