Agent Planning and Retrieval Augmentation: A Practical Guide for AI Agents

    This guide explains how to integrate web retrieval into AI agent planning rather than treating search as a fallback. It covers the core retrieval capabilities agents need, a layered architecture that declares evidence requirements during task decomposition, query rewriting strategies, source filtering and time-window control, evidence evaluation and conflict resolution, engineering practices such as caching and observability, and common anti-patterns to avoid. Readers will learn how to build agents that stay reliable, controllable, and traceable in real business scenarios where knowledge keeps changing.

    1. Background: Knowledge Has Boundaries, Tasks Do Not

    The parametric knowledge of large language models has a fixed training cutoff, while real business tasks often demand information that is true right now: newly published standards, just-updated prices, events that happened moments ago. If an agent relies only on internal memory, two typical defects appear: facts go stale, and conclusions cannot be traced to a source. A more subtle problem is the “confident error” — the model delivers unverifiable conclusions in fluent language, leaving users unable to judge credibility.

    As a result, the engineering focus for agents is shifting from “stronger generation” to “more controllable retrieval and verification.” Web retrieval capability is not simply attaching a search box to a model; it requires a retrieval strategy, an evidence evaluation strategy, and a result constraint strategy designed around the task goal.

    2. Capability Abstraction: Four Foundational Capabilities for Web Retrieval

    Abstracted as a general technical capability, web retrieval breaks down into layers:

    1. Real-time fact acquisition: Issue external queries on demand during reasoning to obtain currently available information fragments.
    2. Source verification and citation: Annotate key information with its source so conclusions are traceable and auditable.
    3. Source credibility filtering: Filter evidence by dimensions such as authoritativeness, site type, and content format.
    4. Time range constraints: Limit the publication window of evidence to prevent old information from contaminating new conclusions.
    5. Automatic query rewriting: Rewrite colloquial, ambiguous user phrasing into queries better suited to retrieval systems.

    These capabilities form the foundation of “retrieval augmentation.” In related practice at Baidu AI Cloud, they are typically designed as a standard adapter layer between the agent orchestration layer and external information sources.

    3. Architecture: Where Retrieval Fits in the Plan

    A common mistake is treating retrieval as a “failure fallback”: let the model answer first, then search if it cannot. A more robust approach brings retrieval into the planning (Plan) stage, carried out alongside task decomposition.

    The recommended layered structure:

    • Intent understanding layer: Identify the task type (factual, comparative, operational) and decide whether external information is needed.
    • Planning layer: Break the task into sub-questions, annotating each with “needs evidence,” “evidence time window,” and “source preference.”
    • Retrieval execution layer: Issue multiple queries in parallel, applying rewriting, filtering, and deduplication.
    • Evidence evaluation layer: Score fragments for relevance, detect conflicts, and validate timeliness.
    • Generation and citation layer: Answer using only evidence that passes evaluation, and output a citation list.

    Illustrative pseudocode:

    1. plan = planner.decompose(task)
    2. for node in plan.nodes:
    3. if node.needs_evidence:
    4. queries = rewriter.expand(node.question) # query rewriting
    5. docs = retriever.search(
    6. queries,
    7. time_range=node.time_window, # time constraint
    8. source_policy=node.source_policy # source filtering
    9. )
    10. node.evidence = evaluator.rank_and_check(docs)
    11. answer = generator.compose(plan, cite=True)

    The key point: retrieval conditions should be declared explicitly during planning, not decided on the fly during generation. This significantly improves both explainability and reproducibility.

    4. Automatic Query Rewriting: The Ceiling on Recall Quality

    User input is often unsuitable for direct retrieval: it contains references (“it,” “this one”), omits the subject, or mixes multiple intents. Rewriting strategies can include:

    • Coreference resolution and context completion: Fill in missing subjects using conversation history.
    • Intent splitting: Break “compare the latest plans for A and B” into two independent queries.
    • Term normalization: Map colloquial expressions to standard domain terminology.
    • Multi-path expansion: Generate queries at different granularities (broad recall plus precise targeting), run them in parallel, and fuse the results.

    Note that rewriting must preserve the original constraints (time, region, target) and avoid “rewriting your way off the topic.” In practice, keep the original query as one path and retrieve with it alongside the rewritten queries.

    5. Source Filtering and Time Control

    Source filtering is not simply “trust only authoritative sites”; it means configuring the policy according to the task’s risk level:

    Task risk Source policy Time window
    Low (chitchat, creative work) Permissive Unrestricted
    Medium (industry updates) Prefer mainstream media and official channels Last 3–12 months
    High (compliance, medical, financial) Official releases and authoritative institutions only Last 30 days, with human review when necessary

    Time control must be combined with content semantics: for regulations, look at the “effective date”; for events, the “occurrence date”; for products, the “update date.” Filtering by crawl time alone introduces bias.

    6. Evidence Evaluation and Conflict Handling

    Multi-path recall inevitably produces redundancy and contradictions. A three-step process is recommended:

    1. Deduplication and clustering: Merge same-source content by semantic similarity.
    2. Conflict detection: When conclusions for the same sub-question disagree, flag the conflict and prefer the source with better authoritativeness and timeliness.
    3. Confidence threshold: When evidence strength falls below the threshold, the agent should explicitly express uncertainty rather than forcing a conclusion.

    This step is the core of traceability. Retrieval augmentation without an evaluation layer merely moves noise from the internet into the context.

    7. Engineering Implementation

    • Caching and cost control: Build a semantic cache for high-frequency queries to reduce repeated external calls.
    • Observability: Log the query, filter conditions, matched sources, and scores for each retrieval to support post-mortem analysis.
    • Failure degradation: When external retrieval is unavailable, fall back to “internal knowledge only, with explicitly stated limitations.”
    • Permissions and compliance: Set access policies for restricted content to avoid unauthorized retrieval.
    • Evaluation loop: Build an evaluation set with ground-truth answers, measuring recall quality, citation accuracy, and answer faithfulness separately.

    For cloud implementation, you can combine a container platform to host retrieval services, a message queue to decouple asynchronous crawling, object storage to keep evidence snapshots, and logging plus monitoring with alerting for observability. These are general product categories, making them portable across environments.

    8. Common Anti-Patterns

    • Answering before searching, which anchors the model on a wrong conclusion.
    • Keeping a single source, with no cross-validation.
    • Filtering time by crawl time only, ignoring business effective dates.
    • Over-rewriting, losing the original qualifiers.
    • Citations that do not match the body text, producing “fake citations.”

    9. Conclusion

    Making an agent “able to get online” is only the starting point. The real engineering value lies in making retrieval part of planning: declare evidence needs during task decomposition, apply rewriting and filtering during execution, complete evaluation and conflict resolution before generation, and output verifiable citations. Built along this path, an agent can remain reliable, controllable, and traceable in real business settings where knowledge keeps changing.