Agent Skills vs. Function Calling: A Source-Code Perspective

    This article examines how agent skills are implemented at the source-code level and how they differ from function calling. Using the code structure of a typical AI coding tool as a reference, it breaks down the seven-step tool execution pipeline, explains how skills act as prompt injectors that return structured instructions instead of business results, and compares inline injection with forked execution. It also covers skill discovery, budget control, and practical guidance for building custom skills and governable agent architectures.

    1. Why Skills Need a Source-Code Perspective

    As AI coding tools and general-purpose agent frameworks evolve quickly, many developers still understand “tool calling” only through API documentation: the model emits structured parameters, the system executes them, and the result is returned. Once a higher-level abstraction such as a “Skill” appears, documentation alone struggles to explain a key behavior—after invoking a skill, the model does not receive a one-time execution result. Instead, it receives a set of instructions describing what to do next.

    This article uses the source-code structure of a representative AI coding tool (a type of implementation often discussed in public research material) as a reference, abstracts it into a general engineering pattern, and answers two questions: how skills are implemented in code, and how they differ from function calling in mechanism.

    2. The Function-Calling Skeleton: A Strict Seven-Step Pipeline

    In a typical implementation, every tool follows a unified interface. The core fields usually include:

    1. interface Tool<Input> {
    2. name: string;
    3. description: string;
    4. inputSchema: ZodSchema<Input>; // Structured parameter constraints
    5. checkPermissions?: (ctx) => Promise<boolean>;
    6. call: (input: Input, ctx) => Promise<ToolResult>;
    7. }

    Tools are merged with default values and user-defined configuration through a builder function, then converted by a serialization function into a JSON Schema that the model can recognize, and sent along with the request. The model sees only three things: the name, a natural-language description, and the parameter structure.

    When the model decides to use a tool, it outputs a tool_use block, and the system enters the execution pipeline, which typically includes seven steps:

    1. Schema validation of the parameters;
    2. Custom business validation;
    3. Pre-hook;
    4. Permission check;
    5. Actual execution;
    6. Mapping the result into a message the conversation can consume;
    7. Post-hook.

    In essence, this is a clean request → response loop: the result is written back into the conversation history, and the model continues reasoning. Tool registration is usually handled by a unified assembly function that merges built-in tools with external extensions, deduplicates them by name, and gives built-in tools priority to avoid nondeterministic behavior caused by naming conflicts.

    3. What Skills Really Are: Prompt Injectors Wrapped as Tools

    On the model side, a skill also appears as “a callable tool.” On the execution side, however, it does not produce a business result. Instead, it returns a user message marked with metadata (commonly isMeta: true in the source code) whose content is a structured playbook: goals, constraints, steps, cautions, and acceptance criteria.

    The key difference is that a skill’s return value does not go through the regular tool-result channel. It is injected into the conversation as “instruction context.” Once the model reads it, it begins invoking the actual tools one by one to complete the task. A skill is therefore a meta-level orchestrator, while function calling is an execution-level executor.

    4. Two Execution Modes: Inline Injection and Forked Execution

    Inline mode: the playbook is injected into the current session, and the main model performs the steps itself. The advantage is context continuity and the ability to adjust at any time based on feedback. The drawback is that it consumes the main context budget, and long workflows may squeeze out critical information.

    Fork mode: the skill runs in a separate sub-session, and the main session receives only a final summary and references to artifacts. The advantage is context isolation, noise control, and easier parallelism. The drawback is reduced visibility into the intermediate process for the main model, which must be compensated for with structured returns.

    Engineering guidance: use inline mode for short workflows with strong interaction; use fork mode for long workflows that can run in parallel and whose results can be compressed.

    5. An Execution Trace: The Abstract Flow of a Commit Task

    1. The model invokes the commit skill;
    2. The skill returns a playbook: check status first, review the diff, generate a commit message, then perform the commit;
    3. The model calls the status-query tool and the diff-reading tool in sequence;
    4. The model generates the message according to the specification and calls the commit tool;
    5. Permission checks and hooks intervene, and the result is written back after completion.

    The skill itself does not “do” anything. It only turns “how to do it” into context the model can execute.

    6. Discovery: Budget Control and Dynamic Visibility

    The skill list is not always fully resident. A common approach is to control how many skills are injected based on a budget, and to determine the visible set dynamically according to the current task, directory, and project configuration. This avoids prompt bloat and reduces the chance of accidental triggering. For developers, this means skill descriptions must be narrow and precise, and trigger conditions must be decidable.

    7. Practical Takeaways for Custom Skills

    • Write “processes,” not “features”: a skill should describe steps and decision criteria, not duplicate capabilities that tools already provide;
    • Define clear termination conditions and acceptance criteria to keep the model from diverging;
    • Contractualize inputs and outputs so returns can be compressed in fork mode;
    • Declare permissions and hooks up front to reduce mid-run failures;
    • State clearly in the description “when not to use it” to reduce accidental invocation.

    8. General Architectural Takeaways

    From the source code, mature agent architectures generally exhibit three layers: a protocol layer (schema and serialization), an execution layer (pipeline, permissions, hooks), and an orchestration layer (skill injection and mode switching). Understanding these three layers is what allows you to design stable, governable, and observable agent applications on platforms such as Baidu AI Cloud, moving capabilities from “demo-ready” to “operation-ready.”