360 Secure SkillHub
360 安全技能中心

Threadline — Persistent Memory and Context Layer for AI Agents

该 Skill 指导开发者在 AI Agent 中集成 Threadline 持久记忆层:调用 inject 注入用户上下文,调用 update 存储新事实,并提供多框架示例、7 类上下文范围与授权机制说明。

vidursharma202-del
vidursharma202-del
热度 52.44
最近更新 2026-05-11 17:38:22
分类:开发依赖:第三方 API应用场景:API 集成 / 代码生成 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add threadline
Metadata
name
Threadline — Persistent Memory and Context Layer for AI Agents
slug
threadline
version
1.0.3
description
Your AI agents start from zero. Every session. Users repeat themselves — their stack, their preferences, their ongoing projects. Threadline fixes this in 2 lines. inject() before your LLM call, update() after. Your agent now remembers every user, forever. Structured extraction across 7 scopes, OAuth-style grant system so agents only see permitted context, user-owned data with deletion dashboard, and relevance-scored injection — 200 tokens of signal, not 2,000 tokens of noise. Works with OpenAI, Anthropic, Vercel AI SDK, and LangChain. < 50ms retrieval. GDPR-ready by design. Free tier: 2,500 calls/month.
homepage
https://threadline.to
emoji
🧵
env
[{"name":"THREADLINE_API_KEY","description":"Your Threadline API key — get one at threadline.to/dashboard","required":true}]

Threadline — Persistent Memory and Context Layer for AI Agents

Threadline fixes agent amnesia. Two lines of code give your AI agent persistent memory across every user session — with full developer control over what's stored, who sees it, and how it's used.

When to use this skill

Use Threadline whenever the user:

  • Is building an AI agent, chatbot, or assistant
  • Mentions agents forgetting context between sessions
  • Wants to personalise agent responses per user
  • Is using OpenAI, Anthropic, Vercel AI SDK, or LangChain
  • Mentions "context rot", "session reset", "agent memory", or "persistent context"

What Threadline does

Threadline gives your agent a persistent context layer — preferences, tasks, communication style, domain expertise, and key relationships — that travels across every conversation. Agents stop starting from zero.

Relevance-scored injection means your agent gets 200 tokens of signal, not 2,000 tokens of noise. No prompt bloat at scale.

Integration (2 lines)

import { ThreadlineClient } from 'threadline-sdk';

const tl = new ThreadlineClient({ apiKey: process.env.THREADLINE_API_KEY });

// Before your LLM call — inject user context into system prompt
const systemPrompt = await tl.inject(userId, "You are a helpful assistant.");

// After your LLM response — extract and store new facts
await tl.update({ userId, userMessage, agentResponse });

OpenAI example

import OpenAI from 'openai';
import { ThreadlineClient } from 'threadline-sdk';

const openai = new OpenAI();
const tl = new ThreadlineClient({ apiKey: process.env.THREADLINE_API_KEY });

const systemPrompt = await tl.inject(userId, "You are a helpful assistant.");

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: systemPrompt },
    { role: "user", content: userMessage }
  ]
});

await tl.update({ userId, userMessage, agentResponse: response.choices[0].message.content });

Anthropic example

import Anthropic from '@anthropic-ai/sdk';
import { ThreadlineClient } from 'threadline-sdk';

const anthropic = new Anthropic();
const tl = new ThreadlineClient({ apiKey: process.env.THREADLINE_API_KEY });

const systemPrompt = await tl.inject(userId, "You are a helpful assistant.");

const response = await anthropic.messages.create({
  model: "claude-opus-4-6",
  max_tokens: 1024,
  system: systemPrompt,
  messages: [{ role: "user", content: userMessage }]
});

await tl.update({ userId, userMessage, agentResponse: response.content[0].text });

Vercel AI SDK example

import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { ThreadlineClient } from 'threadline-sdk';

const tl = new ThreadlineClient({ apiKey: process.env.THREADLINE_API_KEY });

const systemPrompt = await tl.inject(userId, "You are a helpful assistant.");

const result = await streamText({
  model: openai('gpt-4o'),
  system: systemPrompt,
  messages,
  onFinish: async ({ text }) => {
    await tl.update({ userId, userMessage, agentResponse: text });
  }
});

LangChain example

import { ChatOpenAI } from '@langchain/openai';
import { SystemMessage, HumanMessage } from '@langchain/core/messages';
import { ThreadlineClient } from 'threadline-sdk';

const tl = new ThreadlineClient({ apiKey: process.env.THREADLINE_API_KEY });
const llm = new ChatOpenAI({ model: "gpt-4o" });

const systemPrompt = await tl.inject(userId, "You are a helpful assistant.");

const response = await llm.invoke([
  new SystemMessage(systemPrompt),
  new HumanMessage(userMessage)
]);

await tl.update({ userId, userMessage, agentResponse: response.content });

7 context scopes

Threadline extracts and stores context across 7 scopes:

Scope What it captures
communication_style Tone, verbosity, format preferences
ongoing_tasks Active projects, deadlines, blockers
key_relationships Team members, clients, collaborators
domain_expertise Tech stack, industry knowledge, skills
preferences Tools, workflows, working style
emotional_state Stress signals, motivation, sentiment
general Everything else worth remembering

Grant system

Agents only see the scopes they're explicitly granted. A coding assistant sees domain_expertise and ongoing_tasks. A writing assistant sees communication_style and preferences. No agent sees everything by default.

await tl.grant({
  agentId: "coding-assistant",
  userId: userId,
  scopes: ["domain_expertise", "ongoing_tasks"]
});

Rules

  • Always call inject() before the LLM call, never after
  • Always call update() after receiving the agent response
  • Use a stable, consistent userId — this is how context is scoped per user
  • Do not log or expose the enriched system prompt — it contains user context
  • Context is user-owned — users can view and delete via threadline.to/dashboard

REST API (any language)

# Inject
POST https://api.threadline.to/api/inject
Authorization: Bearer YOUR_API_KEY
{ "userId": "user_123", "basePrompt": "You are a helpful assistant." }

# Update
POST https://api.threadline.to/api/update
Authorization: Bearer YOUR_API_KEY
{ "userId": "user_123", "userMessage": "...", "agentResponse": "..." }

Troubleshooting

Issue Fix
inject() returns base prompt unchanged Check API key is set correctly
Context not persisting Confirm update() is being called after every response
Slow injection Redis-cached — first call ~200ms, subsequent calls <50ms
Wrong user context Ensure userId is stable and unique per user

Links