The Message type represents a single message in a conversation history. It’s used with the previousMessages parameter to provide explicit conversation context to the AI.
The Message type is used in the previousMessages array parameter to provide conversation history:
import { ThredClient } from '@thred-apps/thred-js';const client = new ThredClient({ apiKey: process.env.THRED_API_KEY!,});const response = await client.answer({ message: 'What features should I look for?', previousMessages: [ { role: 'user', content: 'I need a CRM for my small business', }, { role: 'assistant', content: 'I recommend looking at HubSpot or Salesforce for small businesses. Both offer great features and scalability.', }, ],});
Build a conversation with alternating user and assistant messages:
const conversationHistory = [ { role: 'user', content: 'What project management tools do you recommend?', }, { role: 'assistant', content: 'I recommend Asana, Trello, or Monday.com for project management.', }, { role: 'user', content: 'Which one is best for remote teams?', }, { role: 'assistant', content: 'Monday.com is particularly well-suited for remote teams due to its robust collaboration features.', },];// Continue the conversationconst response = await client.answer({ message: 'Does it integrate with Slack?', previousMessages: conversationHistory,});
const messages: Message[] = [];// Add user messagemessages.push({ role: 'user', content: 'What are the best productivity apps?',});// Add assistant responsemessages.push({ role: 'assistant', content: 'Popular productivity apps include Notion, Todoist, and Evernote...',});// Continue conversation with contextconst response = await client.answer({ message: 'Which one is best for note-taking?', previousMessages: messages,});// Add the new response to historymessages.push( { role: 'user', content: 'Which one is best for note-taking?' }, { role: 'assistant', content: response.response });
Keep conversation history focused on relevant context. Very long conversation histories may impact performance and exceed token limits.
Always alternate between user and assistant roles. The SDK expects a valid conversation flow.
The previousMessages parameter provides explicit control over conversation context, while conversationId allows the API to manage context automatically. Choose the approach that best fits your use case.