#Why getThreadMessages returns only user messages but no bit messages?

4 messages · Page 1 of 1 (latest)

sacred tapir
#
export const getThreadMessages = query({
  args: { threadId: v.string() },
  handler: async (ctx, { threadId }) => {
    return await ctx.runQuery(components.agent.messages.getThreadMessages, {
      threadId,
    });
  },
});
weak oxideBOT
#

Hi @sacred tapir. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, there's no indication that getThreadMessages would return only user messages and exclude bot messages. The function getThreadMessages should return all messages associated with a given thread ID.

Looking at the code you provided:

export const getThreadMessages = query({
  args: { threadId: v.string() },
  handler: async (ctx, { threadId }) => {
    return await ctx.runQuery(components.agent.messages.getThreadMessages, {
      threadId,
    });
  },
});

This query is simply passing the threadId to the Agent component's getThreadMessages function, which should return all messages in that thread.

According to the documentation, the Agent component stores threads, messages, and steps separately, and you can query them by thread, status, and whether they're tool calls or not AI Agents with Built-in Memory.

If you're only seeing user messages, there could be a few possibilities:

  1. The bot messages might not have been saved yet (they might be pending)
  2. There might be filtering happening in the underlying components.agent.messages.getThreadMessages implementation
  3. You might need to configure the agent to save bot messages

You can try specifying additional options when fetching messages, such as:

return await ctx.runQuery(
  components.agent.messages.getThreadMessages, 
  { threadId, limit: 100 }
);

Also, check your agent configuration to ensure saveOutputMessages is set to true (which is the default):

const supportAgent = new Agent(components.agent, {
  // other options...
  storageOptions: {
    saveAllInputMessages: false, // default
    saveOutputMessages: true, // default
  },
});
#

If you're still having issues, you might want to check if there are any pending messages that haven't been completed yet, or if there's any filtering happening in your UI code.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: