Skip to content

Retrieval policy

When Should an AI Agent Query a Knowledge Base?

Use a query-or-skip policy so AI agents retrieve authoritative knowledge when needed without repeatedly loading irrelevant documents into context.

Qi-Xuan LuUpdated 5 min read

Article packet

01

Workflows

02

Developers operating AI agents over documentation that is consulted repeatedly across tasks or sessions

03

5 min read

01

Query when the answer depends on current, private, project-specific, or citable evidence.

02

Skip retrieval when the exact authoritative source is already in context or the task does not depend on the corpus.

03

Use an index to choose a source, then open the smallest exact passage needed to verify the answer.

01

Quick answer

An AI agent should query a knowledge base when the task depends on current, organization-specific, private, or citable information that is not already available in its context. It should skip retrieval for greetings, fixed control flow, or a task whose exact authoritative source is already open. When retrieval is needed, inspect a compact index first, load the smallest relevant page, and return to the cited source for consequential claims.

Wenlan keeps Sources, atomic knowledge, and maintained Pages separate. An agent can recall a narrow topic or open a relevant Page, inspect its citations, and return to the current source instead of replaying a whole archive; Wenlan does not replace direct code, test, policy, or document verification.

02

When this problem appears

Always injecting a document collection adds irrelevant text, latency, and attention pressure. Never retrieving forces the agent to guess or repeatedly rediscover project decisions. The useful boundary is a reproducible task-level policy, not a promise that every retrieval saves a fixed number of tokens.

03

Use this query-or-skip decision policy

Classify the task before searching, then increase context only when the previous layer cannot support the answer. The slash-command example requires the Wenlan Codex plugin: install it and run /setup once. The wenlan connect codex command configures only the MCP connection; MCP-only clients should call Wenlan recall and inspect the Page results it returns. Use the local wenlan pages <topic> CLI when you need to list or open Pages without the plugin.

  • Query: the answer depends on current project facts, private material, organizational policy, exact numbers, or a citation.
  • Pre-retrieve: every valid answer must use one controlled source, such as a compliance rule or operating procedure.
  • Let the agent decide: only some requests in the workflow need the corpus, and the tool description states its scope and exclusions.
  • Skip: the task is a greeting, static routing step, deterministic operation, or the exact authoritative file is already open.
  • Progressively disclose: inspect titles, paths, abstracts, or a maintained index before loading the full page or document.
  • Verify: open the exact cited passage for important claims and mark unavailable evidence unknown rather than filling the gap from memory.
  • Measure: record retrieved tokens, latency, answer quality, and failed searches on your own workload; do not reuse another system's savings percentage as a guarantee.

Retrieve a narrow topic, then inspect its maintained page

# Wenlan plugin:
/recall <topic>
/pages <topic>

# MCP-only client: call Wenlan recall and inspect returned Page results.
# Local CLI for Page listing or opening:
wenlan pages <topic>

04

What to check next

Smaller context is not automatically better. A skipped lookup can save tokens and still produce a wrong answer; an eager lookup can add irrelevant chunks and reduce focus. Keep the authoritative source boundary explicit and measure retrieval behavior with representative tasks.

Side-by-side

Practical dimensions. Where Retrieval action leads, we say so.

DimensionWenlanRetrieval action
Current, private, or citable factQuery a narrow topic, then open the cited current source.Query
Mandatory controlled evidencePre-retrieve the required source and keep later source access available.Pre-retrieve
Exact authoritative file already openRead and verify that file directly; do not add a redundant search.Skip retrieval
Large or unfamiliar corpusInspect the index or maintained page before loading exact source sections.Progressive disclosure

Test one retrieval boundary

Connect Wenlan, choose one repeated project question, and compare always-load, query-on-demand, and direct-source workflows without assuming a token-saving result.

FAQ

Should an AI agent query the knowledge base for every question?+
No. Always-on retrieval is appropriate only when every answer must use a controlled source. Otherwise expose a clearly scoped tool and let the workflow or agent query only when the task depends on that corpus.
Does a knowledge base guarantee lower token cost?+
No. A compact index and selective retrieval can reduce repeated document reading, but embeddings, tool calls, returned chunks, and failed searches also cost time or tokens. Measure the complete workflow on your own tasks.