How to Execute a Wiki Search Tool in TencentDB Agent Memory

To execute a Wiki search tool in the TencentDB Agent Memory platform, first discover available tools via the GET /v3/tools/list endpoint, then invoke the wiki-search tool by sending a POST request to /v3/tools/call with your query and metadata payload.

The TencentDB Agent Memory repository exposes Wiki search functionality through a standardized tool interface defined in the Knowledge Service (MemoryKnowledge). This architecture allows agents to dynamically discover and execute search capabilities against indexed Wiki assets without hardcoding endpoint URLs.

Architecture and Source Code Locations

The Wiki search tool implementation spans multiple components in the TencentCloud/TencentDB-Agent-Memory repository (specifically the feat/server_team branch):

Execution Workflow

Step 1 – Discover the Tool

Before execution, retrieve the tool descriptor to confirm availability and required parameters:

curl -s https://ks.example.com/v3/tools/list

The response includes a JSON object describing the Wiki search capability:

{
  "name": "wiki-search",
  "description": "Search Wiki pages by keyword",
  "input_schema": {
    "type": "object",
    "properties": {
      "query": { "type": "string" }
    },
    "required": ["query"]
  }
}

Step 2 – Call the Tool

Send a POST request to /v3/tools/call with the tool name, input payload, and contextual metadata:

curl -s -X POST https://ks.example.com/v3/tools/call \
  -H "Content-Type: application/json" \
  -d '{
    "tool_name": "wiki-search",
    "input": { "query": "memory architecture" },
    "metadata": { "team_id": "team-1", "user_id": "user-123" }
  }'

The tool_name must match the identifier from the discovery step. The input object follows the schema defined in the tool descriptor, while metadata provides session context required by the Knowledge Service.

Step 3 – Handle the Response

The Knowledge Service returns a standardized envelopeformat regardless of internal success or failure:

{
  "code": 0,
  "message": "ok",
  "data": {
    "results": [
      {
        "title": "Memory Architecture Overview",
        "url": "/wiki/memory-architecture",
        "snippet": "Detailed explanation of agent memory systems...",
        "page_id": "page-456"
      }
    ]
  }
}

If the search fails, the data.isError flag is set to true and data.text contains the error description, even when the HTTP status code is 200.

Implementation Examples

Using the TypeScript Frontend Wrapper

The project provides a dedicated API module for tool execution:

import { knowledgeApi } from '@/lib/api/knowledge-api';

// Step 1: Discover
const tools = await knowledgeApi.toolsList();
const wikiTool = tools.find(t => t.name === 'wiki-search');
if (!wikiTool) throw new Error('Wiki search tool not available');

// Step 2: Execute
const result = await knowledgeApi.toolsCall({
  tool_name: wikiTool.name,
  input: { query: 'agent memory patterns' },
  metadata: { team_id: 'team-1', user_id: 'u123' }
});

// Step 3: Process results
if (result.isError) {
  console.error('Search failed:', result.text);
} else {
  console.log('Found pages:', result.data);
}

Using Python

from memory_core import KnowledgeClient

kc = KnowledgeClient(service_url="http://ks:8421/v3")

# Discover tools

tools = kc.tools_list()
wiki_tool = next(t for t in tools if t["name"] == "wiki-search")

# Execute Wiki search tool

resp = kc.tools_call(
    tool_name=wiki_tool["name"],
    input={"query": "LLM context window"},
    metadata={"team_id": "team-1", "user_id": "u42"}
)

# Check response envelope

if resp["data"]["isError"]:
    print(f"Error: {resp['data']['text']}")
else:
    for page in resp["data"]["results"]:
        print(f"{page['title']}: {page['url']}")

Error Handling Behavior

The Knowledge Service maintains a consistent response contract even when internal errors occur. Always inspect data.isError rather than relying solely on HTTP status codes. According to the implementation in MemoryKnowledge/src/routes/tools.ts, a system failure returns HTTP 500 with an envelope where data.isError is true, allowing clients to handle failures uniformly without parsing different response structures.

Summary

  • Two-step process: Execute a Wiki search tool by first calling /v3/tools/list for discovery, then /v3/tools/call for invocation.
  • Required parameters: Include tool_name (wiki-search), input (containing the query string), and metadata (with team_id and user_id).
  • Source locations: Tool routing resides in MemoryKnowledge/src/routes/tools.ts and search logic in MemoryKnowledge/src/routes/wiki.ts.
  • Response format: All results return in a standardized envelope with code, message, and data fields; check data.isError for application-level failures.
  • Multi-language support: Available via raw HTTP, TypeScript wrappers in MemoryPanel, or Python SDK with identical JSON schemas.

Frequently Asked Questions

What endpoints are required to execute a Wiki search tool?

You must use GET /v3/tools/list to retrieve the tool schema and confirm availability, followed by POST /v3/tools/call to submit your search query. Both endpoints are implemented in MemoryKnowledge/src/routes/tools.ts.

Where is the Wiki search logic implemented in the codebase?

The tool call routing and endpoint definitions are in MemoryKnowledge/src/routes/tools.ts, while the actual search execution against the Wiki index occurs in MemoryKnowledge/src/routes/wiki.ts. The tool registration happens in MemoryProxy/src/injection/injectors/knowledge-tools-injector.ts.

How do I handle errors when calling the Wiki search tool?

Check the data.isError boolean field in the response envelope. Unlike standard REST APIs that rely on HTTP status codes, this platform returns HTTP 200 with data.isError: true when the tool execution fails internally, providing error details in data.text.

Can I execute the Wiki search tool without using the frontend wrapper?

Yes. While MemoryPanel/web/src/lib/api/knowledge-api.ts provides a convenient TypeScript abstraction, you can execute the tool using any HTTP client (cURL, Python requests, etc.) by directly calling the /v3/tools/call endpoint with the proper JSON payload structure.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →