How to Generate a Skill Listing for Prompt Injection with TencentDB Agent Memory
Use the POST /v3/skill/listing endpoint via SkillClient.listing() to retrieve a markdown-formatted skill catalog that you can inject into LLM prompts, respecting team and agent isolation boundaries.
The TencentDB Agent Memory SDK provides a specialized interface for generating skill listings that enable dynamic prompt injection in LLM applications. When building agent systems, you need to inform the model about available tools without hardcoding descriptions or maintaining manual documentation. This guide demonstrates how to generate a skill listing for prompt injection using the official Python SDK, leveraging isolation defaults and character budgeting to optimize token usage for downstream models.
Understanding the Skill Listing Endpoint
The skill listing endpoint (POST /v3/skill/listing) generates the <available_skills> block that can be injected into prompts to give LLMs a catalog of invocable skills. According to the TencentDB-Agent-Memory source code, the system combines isolation defaults with runtime parameters to ensure secure, context-aware skill visibility.
The endpoint accepts two primary parameters:
query– Optional string to filter skills by name or descriptionchar_budget– Integer limiting the rendered markdown block size to prevent token overflow
The server returns a JSON payload containing a listing field with pre-formatted markdown. This block respects the same isolation rules (team, agent, user boundaries) used throughout the memory system, ensuring you only expose skills authorized for the current execution context.
Generating Skill Listings with the SDK
The SDK implements this functionality in SkillClient.listing for synchronous operations and AsyncSkillClient.listing for asynchronous workflows. Both methods follow the same parameter signature but differ in their execution model.
Synchronous Usage
Initialize the client with your endpoint credentials and isolation defaults, then call listing() to retrieve the markdown block:
from tencentdb_agent_memory.v3 import SkillClient
# Initialise the client with credentials and default isolation IDs
skills = SkillClient(
endpoint="https://memory.tencentyun.com",
api_key="sk-…", # Keep this secret
service_id="mem-abc",
team_id="team-1",
agent_id="agent-coder",
user_id="user-42"
)
# Generate a listing – limit to 1500 characters and filter by keyword
resp = skills.listing(query="code", char_budget=1500)
# The rendered markdown block ready for prompt injection
skill_listing_md = resp.get("listing", "")
print("=== Skill Listing ===")
print(skill_listing_md)
Setting query="code" narrows results to skills matching that term, while char_budget=1500 caps the output size to conserve context window space in downstream LLM APIs.
Asynchronous Usage
For high-throughput applications, use AsyncSkillClient with identical parameters:
import asyncio
from tencentdb_agent_memory.v3 import AsyncSkillClient
async def make_listing():
async with AsyncSkillClient(
endpoint="https://memory.tencentyun.com",
api_key="sk-…",
service_id="mem-abc",
team_id="team-1",
agent_id="agent-coder",
user_id="user-42"
) as skills:
resp = await skills.listing(char_budget=2000) # No query → full list
return resp.get("listing", "")
listing_md = asyncio.run(make_listing())
print(listing_md)
The async client mirrors the synchronous API exactly, ensuring consistent behavior across both execution models.
Injecting Skills into LLM Prompts
Once you generate the skill listing, concatenate it with your user message to create an augmented prompt:
def build_prompt(user_message: str, skill_listing: str) -> str:
# Concatenate listing before user message to establish available tools
return f"{skill_listing}\nUser: {user_message}\nAssistant:"
# Example usage
user_msg = "How can I refactor this Python function?"
prompt = build_prompt(user_msg, skill_listing_md)
# Send `prompt` to your LLM provider (OpenAI, Claude, etc.)
Placing the skill listing at the beginning of the prompt establishes the tool context before the user query, helping the model recognize when to invoke specific skills during response generation.
Implementation Details in the Source Code
The SDK handles several critical operations before sending requests to the /v3/skill/listing endpoint. In /sdk/memory-core/python/tencentdb_agent_memory/v3/skill_client.py, the listing method (lines 514-531) performs three key steps:
-
Merging isolation defaults – The
_SkillDefaults.mergemethod (lines 85-115) combines team, agent, and user IDs supplied at client construction with any per-call overrides, ensuring consistent security boundaries. -
Stripping empty values – The
_strip_nonehelper (lines 57-59) removesNoneentries from the request payload before serialization, preventing invalid JSON from reaching the server. -
POST construction – The method assembles the final request body containing the optional
queryandchar_budgetparameters, then transmits via the internal HTTP stub tohttps://memory.tencentyun.com/v3/skill/listing.
These implementation details ensure that your skill listings respect the same visibility permissions enforced by the memory system's server-side logic.
Summary
- The
POST /v3/skill/listingendpoint generates markdown-formatted skill catalogs designed specifically for prompt injection scenarios. - Both
SkillClient.listing()andAsyncSkillClient.listing()supportqueryfiltering andchar_budgetlimits to optimize token usage. - Isolation defaults (team_id, agent_id, user_id) set during client initialization automatically propagate to listing requests, ensuring secure skill visibility.
- The response's
listingfield contains ready-to-inject markdown that you can concatenate with user messages before sending to LLM providers. - Source code in
skill_client.pyhandles parameter merging and sanitization through_SkillDefaults.mergeand_strip_nonehelpers.
Frequently Asked Questions
What is the maximum character budget for a skill listing?
The char_budget parameter accepts any positive integer value, but you should align it with your target LLM's context window limitations. For GPT-4-class models, budgets between 1500-4000 characters typically leave sufficient room for user queries and response generation while providing comprehensive skill descriptions.
How does skill isolation work in the listing endpoint?
The SDK automatically applies isolation rules defined during client initialization. As implemented in skill_client.py lines 85-115, the _SkillDefaults.merge method combines team_id, agent_id, and user_id values, ensuring the server only returns skills visible within those specific boundaries. This prevents cross-contamination of tools between different teams or user sessions.
Can I filter skills by category when generating a listing?
Yes, use the query parameter to filter skills by name or description keywords. While the SDK does not expose explicit category filters, semantic matching in the backend processes natural language queries to return relevant subsets of your skill registry.
Is the async client implementation identical to the sync version?
Functionally yes. AsyncSkillClient.listing() accepts identical parameters and returns the same response structure as SkillClient.listing(). The implementation differs only in using async with context managers and await syntax for non-blocking I/O operations, as shown in the source code's parallel method definitions.
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 →