Agent Skills Retrieval: Finding the Right Skill Throughout the Task Lifecycle

    This article explains why retrieving Agent Skills only once at the start of a task is insufficient for complex workflows, and how shifting to step-by-step retrieval solves execution-time capability gaps. You will learn how to construct distinguishable queries from the agent's internal state, what signals a retriever needs to identify the skill required at the current step, and a practical engineering checklist covering trigger conditions, deduplication, reproducibility, and acceptance rules. The article also outlines how general-purpose cloud capabilities can support this architecture.

    1. The Starting Problem: A Single Goal Hides Execution-Time Uncertainty

    When you ask an AI agent to handle a composite task such as “read papers, generate diagrams, and produce a report,” the initial instruction is often just one sentence. The system retrieves two skills, “literature reading” and “report writing,” and appears well prepared. But once execution begins, failures rarely come from a missing skill. They come from the details: font substitution during vector export shifts the layout; a table with merged cells breaks when parsed as a standard 2D structure; the finished draft still needs pagination and figure numbering validated against a target template.

    None of these difficulties appear in the original request, because the user does not know about them in advance. This is the core tension of skill retrieval: the user provides a goal, while the missing capabilities surface gradually during execution.

    2. Why Retrieving Once at the Beginning Is Not Enough

    Skills typically bundle operating instructions, executable scripts, examples, and supporting resources into a single capability unit. They define what steps a class of tasks should follow, which tools to call, and how to self-check results. For a skill to work, two conditions must hold: it must be found correctly, and it must be applied correctly.

    One-shot recall based on the initial request works when the requirement boundary is clear, such as a fixed-format document conversion where the relevant skill is determined at the first step. Complex tasks are different: the real structure of a file, an error code returned by an interface, or whether the previous step actually completed can all rewrite the knowledge requirement for the next step.

    “Find a skill that can write a report” and “find a skill that can correctly read this kind of merged cell” serve the same end goal, but their retrieval needs are far apart. The starting point of a query should therefore move from “restating the whole task” to “expressing the specific gap at the current step.”

    3. What Progressive Loading Solves, and What It Does Not

    Progressive loading (load the skill index first, expand the full text only when needed) reduces context usage, not the timing of retrieval. If the loading trigger is still bound to the task entry point, gaps that emerge during execution can only be handled by the model pushing forward blindly, trial and error, or waiting for the user to intervene again. Think of it as moving books into a library but only allowing borrowing at the moment you walk in.

    A schematic comparison of the two flows:

    1. One-shot retrieval: query(user goal) -> skill set -> execute to the end
    2. Step-wise retrieval: execute one step -> observe state -> query(current gap) -> load skill -> continue

    4. Constructing Queries for the Current Step

    The key engineering point is turning “internal state” into a searchable query. Available signals include the current subgoal, the previous step’s output and errors, the list of already loaded skills (for deduplication), and the task’s explicit constraints (template, format, acceptance criteria).

    1. def build_query(state):
    2. return "\n".join([
    3. f"Current subgoal: {state.subgoal}",
    4. f"Last step result: {state.last_artifact_summary}",
    5. f"Error message: {state.error or 'none'}",
    6. f"Loaded skills: {', '.join(state.loaded) or 'none'}",
    7. f"Hard constraints: {state.constraints}",
    8. ])

    The point is that the query must be “distinguishable”: a merged-cell parsing failure should recall table-structure handling skills, not report-writing skills again.

    5. The Retriever Must Understand What the Agent Lacks Right Now

    Generic text similarity does not match this need. Execution-time queries are short, contain few terms, and are mixed with error stacks, which differs markedly from the distribution of skill descriptions. A workable training approach is to build samples from execution traces: inject a known gap at a given step, treat the skill that actually solves the problem at that step as a positive example, and treat skills with the same goal but different granularity as hard negatives. This teaches the retriever to distinguish “goal-relevant” from “usable right now.”

    6. Combining with General-Purpose Baidu AI Cloud Capabilities

    In practice, you usually do not need to build all the infrastructure yourself: skills and resources can live in object storage, skill invocation and state transitions can be decoupled with a message queue, the runtime can be hosted on a container platform, and the quality of the retrieval and execution pipeline can be observed through logging services and monitoring alerts. The general-purpose capabilities offered by Baidu AI Cloud in these categories can serve as a candidate foundation for such an architecture.

    7. Engineering Checklist and Common Pitfalls

    • Trigger conditions: define explicit “gap signals” (errors, validation failures, non-compliant artifacts) before retrieving, and avoid querying at every step.
    • Deduplication and budget: cap the total number of skills and the expansion depth to prevent context bloat.
    • Reproducibility: fix random seeds and retrieval parameters, and retain traces for retrospection.
    • Acceptance up front: express acceptance criteria such as pagination, fonts, and numbering as machine-checkable rules rather than leaving them to the model’s discretion.

    8. Conclusion

    The next competitive edge of a skill system lies not in how many skills are installed, but in whether the right one can be found at the right moment. Turning retrieval from a one-shot action at the task entry into a continuous action that advances with execution, and making the retriever understand the real gaps that appear during execution, is the key to stability in complex tasks. Combined with observable and verifiable engineering constraints, this turns occasional failures into controllable problems.