@threadlessai/sdk
v0.2.0
Published
Threadless AI: memory for agents. Decorate every model call, report every reply.
Maintainers
Readme
@threadlessai/sdk
Threadless AI: memory for agents. Decorate every model call, report every reply.
npm install @threadlessai/sdkSet THREADLESS_API_KEY (a tl_live_… or tl_test_… project key), or pass apiKey.
Chat Completions
import OpenAI from 'openai';
import { Threadless } from '@threadlessai/sdk';
const openai = new OpenAI();
const threadless = new Threadless();
const { id: memoryId } = await threadless.memories.create(); // one per conversation
let newMessages: any[] = [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hi, I am planning a kitchen install.' },
];
for (;;) {
const request = await threadless.chat.decorate(memoryId, newMessages, {
model: 'gpt-5',
tools: yourTools, // decorate adds the two memory functions
});
const reply = await openai.chat.completions.create(request as any);
threadless.chat.report(memoryId, reply);
const message = reply.choices[0].message;
if (!message.tool_calls?.length) break;
newMessages = message.tool_calls.map((call: any) => ({
role: 'tool',
tool_call_id: call.id,
// The memory functions are answered by answer(call); decorate fills in what memory holds.
content: threadless.chat.answer(call) ?? runYourTool(call),
}));
}Responses works the same way through threadless.responses.
The memory functions
Decorate adds two functions to every request's tools, so the model works with its own memory:
assistant_memory: the model searches and walks everything said in this conversation, including what has left live context.memory_note: the model writes facts down when part of the history is about to leave live context.
Your tool loop answers both with answer(call), which returns undefined for your own tools. The next decorate puts the memory's result in place of the answer, so your code never handles it. When we cannot be reached, decorate falls back to the local tail and a memory call's output says memory is unavailable.
Setup for agents: https://threadlessai.com/setup · Docs: https://threadlessai.com/docs
License
Proprietary. See LICENSE: use is limited to calling the Threadless AI service under its Terms of Service.
