Creating a thread
You can create a thread in a mutation or action. If you create it in an action, it will also return athread (see below) and you can start calling LLMs and
generating messages. If you specify a userId, the thread will be associated with
that user and messages will be saved to the user’s history.
Generating a message in a thread
You can generate a message in a thread via the agent functions:agent.generateText, agent.generateObject, agent.streamText, and
agent.streamObject. Any agent can generate a message in a thread created by
any other agent.
Continuing a thread using the thread object from agent.continueThread
You can also continue a thread by creating an agent-specific thread object,
either when calling agent.createThread or agent.continueThread from within
an action. This allows calling methods without specifying those parameters each
time.
thread from continueThread or createThread (available in actions only)
is a Thread object, which has convenience methods that are thread-specific:
thread.getMetadata()to get theuserId,title,summaryetc.thread.updateMetadata({ patch: { title, summary, userId} })to update the metadatathread.generateText({ prompt, ... })- equivalent toagent.generateText(ctx, { threadId }, { prompt, ... })thread.streamText({ prompt, ... })- equivalent toagent.streamText(ctx, { threadId }, { prompt, ... })thread.generateObject({ prompt, ... })- equivalent toagent.generateObject(ctx, { threadId }, { prompt, ... })thread.streamObject({ prompt, ... })- equivalent toagent.streamObject(ctx, { threadId }, { prompt, ... })
Deleting threads
You can delete threads by theirthreadId.
Asynchronously (from a mutation or action):
userId.