How to Automatically Extract Skills from Conversation Turns in TencentDB-Agent-Memory
The TencentDB-Agent-Memory repository provides a fully automated pipeline that transforms raw conversation turns into structured skill records through the /v3/skill/extract endpoint, requiring no manual intervention when extraction thresholds are met.
The Skill API enables downstream agents to discover and reuse capabilities learned from historical interactions. This article explains the end-to-end flow—from message normalization to LLM-based extraction—based on the actual source code implementation in the TencentDB-Agent-Memory repository.
Understanding the Skill Extraction Pipeline
The automatic extraction process begins with message normalization and configuration-driven triggering. Every conversation turn that satisfies the defined thresholds in ExtractionConfig initiates the pipeline without explicit developer intervention.
Message Normalization and Types
Before extraction, conversation messages are normalized to the SkillExtractMessage shape. According to sdk/memory-core/typescript/src/v3/skill-types.ts (lines 272-287), this structure requires role and content fields, with an optional timestamp. The SkillExtractRequest type wraps these messages alongside required identifiers (user_id, team_id, agent_id) to ensure proper routing and access control.
Extraction Configuration
The ExtractionConfig defined in MemoryProxy/src/types.ts (lines 474-638) acts as the gatekeeper for the extraction process. This configuration determines:
- Whether automatic extraction is enabled for specific conversation types
- Which extractors to invoke (e.g.,
skill,tdai-memory) - Thresholds that must be met before firing the extraction request
When conditions are satisfied, the proxy layer automatically forwards the normalized messages to the Skill Client.
The Extraction Flow
The pipeline moves through three distinct phases: client-side validation and triggering, server-side LLM processing, and persistent storage. Each phase is implemented in separate modules to maintain clean separation between transport, business logic, and data layers.
Step 1: Triggering via the Skill Client
The Skill Client (sdk/memory-core/typescript/src/v3/skill-client.ts, lines 370-390) serves as the primary interface for extraction requests. When invoked, the client performs strict validation through validateRequiredStrings and validateMessages to ensure all identifiers and message formats meet API requirements.
The client then issues a POST request to /v3/skill/extract. Depending on the mode option (async or synchronous), this operates as either fire-and-forget or blocking call. The SkillClient.extract() method accepts a SkillExtractRequest containing the normalized message array and execution options.
Step 2: Core Processing and LLM Extraction
Inside the core service, MemoryCore/src/gateway/skill-handlers.ts (lines 90-115) implements the /v3/skill/extract endpoint. Upon receiving the payload, the handler builds an archive payload and delegates processing to the Skill Core Sink (MemoryCore/src/core/skill/conversation-add/skill-core-sink.ts).
The sink executes the LLM-based extractor configured via skill-config.ts (lines 147-150). This component analyzes the conversation context to identify structured skill items—including commands, intents, or tool calls—and converts natural language into actionable skill definitions.
Step 3: Persistence and Retrieval
Extracted skill items are stored in the Skill Store (MemoryKnowledge/src/store/llm-binding-store.ts), making them immediately queryable through standard Skill API endpoints (/v3/skill/list, /v3/skill/get). This persistence layer ensures that skills learned from one conversation become available to future sessions and other agents within the same team.
Implementation Examples
Triggering Extraction from a Node.js Client
Use the official SDK to initiate skill extraction after a conversation turn:
import { SkillClient } from '@tencentdb/memory-core';
// Initialize the client with required identifiers
const client = new SkillClient({
baseUrl: 'https://api.tencentsvc.com',
user_id: 'u-123',
team_id: 't-456',
agent_id: 'a-789',
});
// Build messages from the conversation turn
const messages = [
{ role: 'user', content: 'Can you create a MySQL table for sales?' },
{ role: 'assistant', content: 'Sure, what columns do you need?' },
];
// Fire-and-forget asynchronous extraction
await client.extract({
messages,
options: { mode: 'async' },
});
Retrieving Extracted Skills
After asynchronous processing completes, fetch the structured skill details:
import { SkillClient } from '@tencentdb/memory-core';
const skillId = 'skill-abc123';
const detail = await client.get({ skill_id: skillId });
console.log('Extracted skill:', detail);
Direct HTTP API Integration
For custom pipelines or non-Node.js environments, call the REST endpoint directly:
import fetch from 'node-fetch';
const payload = {
user_id: 'u-123',
team_id: 't-456',
agent_id: 'a-789',
messages: [
{ role: 'user', content: 'What is the current quota?' }
],
options: { mode: 'async' }
};
await fetch('https://api.tencentsvc.com/v3/skill/extract', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
Summary
- Automatic extraction is governed by
ExtractionConfiginMemoryProxy/src/types.ts, which evaluates every conversation turn against predefined thresholds. - The Skill Client (
skill-client.ts) validates messages and issues requests to the/v3/skill/extractendpoint. - Core processing occurs in
skill-handlers.tsandskill-core-sink.ts, where LLM-based extractors analyze conversations to produce structured skill items. - Persistence happens in
llm-binding-store.ts, enabling retrieval via standard Skill API methods likegetandlist. - The entire pipeline supports both asynchronous (fire-and-forget) and synchronous execution modes depending on application requirements.
Frequently Asked Questions
What triggers automatic skill extraction in the TencentDB-Agent-Memory system?
Automatic extraction triggers when a conversation turn satisfies the conditions defined in ExtractionConfig (MemoryProxy/src/types.ts). This configuration evaluates factors like message count, content patterns, and enabled extractor types (skill, tdai-memory). When thresholds are met, the proxy layer automatically invokes the Skill Client without requiring manual API calls.
What validation does the Skill Client perform before extraction?
The Skill Client (skill-client.ts) runs validateRequiredStrings to verify that user_id, team_id, and agent_id are present and non-empty. It also executes validateMessages to ensure every message in the SkillExtractRequest conforms to the SkillExtractMessage interface defined in skill-types.ts, checking for valid role and content fields.
Where are extracted skills stored and how are they retrieved?
Extracted skills persist in the Skill Store (MemoryKnowledge/src/store/llm-binding-store.ts). You can retrieve them using the Skill Client's get method (for specific skill IDs) or list method (for querying multiple skills). The storage layer makes skills available across conversation sessions and accessible to other agents sharing the same team_id.
Can skill extraction run synchronously or only asynchronously?
The system supports both modes. When calling client.extract(), set options.mode to 'async' for fire-and-forget processing (recommended for production) or omit the mode for synchronous execution where the API waits for the LLM extraction to complete before returning. The asynchronous mode prevents blocking your application during LLM processing.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →