M
MastraAI•5d ago
flippyhead

Get threadId associated with agent memory

I have a workflow that calls an agent with memory, configured to generate a thread title. How can I get access to the threadId automatically created for that agent once it's been used?
2 Replies
_roamin_
_roamin_•4d ago
Hey @flippyhead ! The only way to do that at the moment is to create the thread beforehand, like this:
const newThread = await memory.createThread({
resourceId: "user-123",
})

// then use the new thread id to call the agent
const result = await agent.stream('...', {
memory: {
resource: "user-123",
thread: newThread.id
}
})
const newThread = await memory.createThread({
resourceId: "user-123",
})

// then use the new thread id to call the agent
const result = await agent.stream('...', {
memory: {
resource: "user-123",
thread: newThread.id
}
})
flippyhead
flippyheadOP•4d ago
@Romain ok thanks. Consider this my vote for returning that value somewhere in the response 😉

Did you find this page helpful?