# How Agents Discover and Use LLM-Wiki Capabilities in TencentDB-Agent-Memory

> Discover how agents find and use LLM-Wiki capabilities via the Knowledge Tools Injector. Learn how TencentDB-Agent-Memory leverages prompt context for efficient knowledge retrieval.

- Repository: [Tencent Cloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
- Tags: deep-dive
- Published: 2026-08-29

---

**Agents discover LLM-Wiki capabilities through the Knowledge Tools Injector, which queries the kernel knowledge API, filters results by capability flags, and injects a structured `<knowledge_tools>` block into the prompt context.**

The TencentDB-Agent-Memory repository implements a sophisticated capability discovery system that allows AI agents to dynamically access wiki-based knowledge sources during conversations. This mechanism relies on the **Memory Proxy** service to transparently fetch, filter, and expose LLM-Wiki resources without requiring manual configuration by end users.

## Discovery Phase: Fetching Knowledge Assets

When a conversation session initializes, the agent must first identify which wiki resources are available for the current team or specific agent identity.

### Querying the Core Knowledge API

The discovery process begins in the **Knowledge Tools Injector** located at [`MemoryProxy/src/injection/injectors/knowledge-tools-injector.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/injection/injectors/knowledge-tools-injector.ts). This component instantiates a `CoreKnowledgeClient` and calls the `listKnowledge` method to retrieve bound knowledge assets.

The client makes an HTTP request to the kernel endpoint `/v3/knowledge/list`, passing the `teamId` and optional `serviceId` (space identifier). According to the implementation in [`MemoryProxy/src/knowledge/core-client.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/knowledge/core-client.ts) (lines 47-55), the response includes assets of type `"wiki"` or `"code-graph"`, each containing critical metadata:

- **`service_url`**: The endpoint for wiki operations
- **`knowledge_id`**: Unique identifier for the wiki resource
- **`summary`**: Description used by the LLM to determine relevance
- **`repo_slug`**: Optional repository context

### Capability Filtering with AssetCapabilityFlags

Not all agents are permitted to use wiki capabilities. The injector applies **AssetCapabilityFlags** to enforce access control through the `filterResourcesByCapabilities` function (lines 87-96 in the injector).

If the `llm_wiki` flag is set to `false`, wiki items are excluded from the results before injection. This check ensures compliance with tenant-specific capability configurations defined in [`MemoryProxy/src/tdai/capabilities.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/tdai/capabilities.ts).

## Injection Phase: Rendering the knowledge_tools Block

Once filtered, the usable wiki resources are serialized into an XML-like structure that the LLM can parse.

The `renderKnowledgeToolsBlock` function (lines 39-74) constructs a `<knowledge_tools>` block containing individual `<knowledge>` tags for each wiki entry. This block includes:

- The `knowledge_id` for tool routing
- The `about` attribute (summary) to help the LLM decide when to invoke the tool
- Tenant context derived from the session's `space_id`

The rendered block is appended to the system prompt, providing the agent with the necessary context to interact with wiki services.

## Usage Phase: Agent Interaction Workflow

With the `<knowledge_tools>` block in context, the agent follows a two-step workflow to retrieve information.

### Listing Available Tools

Before querying content, the agent calls **tools/list** to discover wiki-specific operations (search, read_page, etc.). This request must include the `x-tdai-service-id` header set to the session's `space_id`, as shown in the request template in the injector (lines 11-15).

```typescript
// Agent-side tool discovery
const tools = await fetch(`http://knowledge-host:8421/v3/tools/list`, {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'x-tdai-service-id': spaceId,
    'x-conversation-id': sessionId
  },
  body: JSON.stringify({ knowledge_id: 'my-wiki-id' })
});

```

### Executing Wiki Queries

The agent invokes **tools/call** with the `knowledge_id` and selected tool name. The LLM determines the appropriate timing for these calls based on the `about` descriptions provided in the injected block.

```bash
curl -sSk -X POST http://knowledge-host:8421/v3/tools/call \
  -H 'content-type: application/json' \
  -H 'x-tdai-service-id: my-space-id' \
  -H 'x-conversation-id: <session-id>' \
  -d '{"knowledge_id":"my-wiki-id","tool_name":"search","params":{"query":"design rationale"}}'

```

## Configuration and Default Behavior

The LLM-Wiki capability is **enabled by default** (`llm_wiki: true`) in the proxy's capability definition at [`MemoryProxy/src/tdai/capabilities.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/tdai/capabilities.ts) (lines 5-7). Administrators can disable the feature globally or per-agent by setting the runtime configuration key `llm_wiki.enabled` to `false`.

This configuration-driven approach allows the Memory Proxy to support heterogeneous agent fleets where some participants have wiki access while others operate with restricted toolsets.

## Summary

- **Discovery** occurs via `CoreKnowledgeClient.listKnowledge` querying `/v3/knowledge/list` to retrieve wiki assets bound to the team or agent.
- **Filtering** respects `AssetCapabilityFlags.llm_wiki`, excluding wiki resources when the flag is disabled.
- **Injection** renders a structured `<knowledge_tools>` block through `renderKnowledgeToolsBlock`, providing metadata and routing headers.
- **Usage** follows a standard `tools/list` → `tools/call` pattern, requiring the `x-tdai-service-id` header for tenant isolation.
- **Configuration** defaults to enabled但可以 toggled via `llm_wiki.enabled` in capabilities settings.

## Frequently Asked Questions

### How does an agent know which wiki resources are available?

The agent receives a pre-filtered list through the `<knowledge_tools>` block injected by the Memory Proxy. This block is populated by the Knowledge Tools Injector after querying the kernel knowledge service and applying capability flags, as implemented in [`MemoryProxy/src/injection/injectors/knowledge-tools-injector.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/injection/injectors/knowledge-tools-injector.ts).

### What determines whether an agent can use LLM-Wiki capabilities?

Access is controlled by the `llm_wiki` property within `AssetCapabilityFlags`. If this boolean flag is set to `false` for a specific agent or tenant, the `filterResourcesByCapabilities` function removes wiki items from the knowledge list before they reach the prompt context.

### How does the agent route requests to the correct wiki service?

Each wiki resource includes a `service_url` and requires the `x-tdai-service-id` header derived from the session's `space_id`. The agent uses these values when calling `tools/list` and `tools/call` endpoints at `http://knowledge-host:8421/v3/`, ensuring requests reach the correct tenant-scoped knowledge service.