Agent Skills in Source Code: How They Work and How They Differ from Function Calling
This article examines how Agent skills are implemented at the source-code level and how they differ from function calling. It explains the tool interface abstraction, the seven-step tool execution pipeline, and tool registration with deduplication, then shows that skills return instructions rather than results through inline injection or forked sub-contexts. It also covers skill discovery, context budgeting, and practical guidance for writing custom skills, along with the layered architecture pattern common to mature Agent systems.
How Agent Skills Are Implemented in Code, and How They Differ from Function Calling
1. Why You Need to Look at Skills at the Source Level
In AI coding tools and general-purpose Agent frameworks, “Skills” have become a high-frequency capability. Developers use them to package reusable knowledge such as team conventions, code review checklists, and commit message templates. However, most people’s understanding stops at the API documentation level, assuming a skill is simply “a tool that can be called.” The real implementation details only become clear when you read the source code.
In a widely discussed public source-code disclosure, a large amount of TypeScript source was revealed. Looking at the key parts of the skill-related implementation files exposes a decisive detail: after a skill finishes executing, the returned data structure carries a user message marked with metadata (isMeta). This means that after calling a skill, the model does not receive an “execution result” but rather a set of instructions on “what to do next.” Only after reading those instructions does the model begin calling the actual tools to get work done. The skill itself does not even go through the standard tool result (tool_result) channel.
This single implementation detail directly determines two things: how you should write custom skills, and whether your understanding of Agent architecture can move beyond “interface calls” to “control flow design.”
2. Function Calling in Source Code
To understand skills, you first need to understand how function calling is implemented in engineering terms.
2.1 The Tool Interface Abstraction
In a typical implementation, every tool implements a unified interface. The core fields include: name, input schema (inputSchema, usually defined with a schema library such as Zod), the execution function (call), and permission checks (checkPermissions). A builder function merges default values with user-defined ones, and a serialization function converts the tool into a JSON Schema that the model side can recognize, sent along with the request.
The model only sees three things: the tool name, a natural-language description, and a structured parameter schema. When the model decides to use a tool, it outputs a structured tool call block (tool_use block).
2.2 A Strict Seven-Step Execution Pipeline
Once the system receives the call block, it enters a fixed pipeline (pseudocode):
async function runToolUse(block, ctx) {const tool = pool.get(block.name);const args = zodParse(tool.inputSchema, block.input); // 1. schema validationawait customValidate(args, ctx); // 2. custom validationawait runHooks('PreToolUse', args); // 3. pre-hooksawait tool.checkPermissions(args, ctx); // 4. permission checkconst raw = await tool.call(args, ctx); // 5. actual executionconst result = mapResult(raw); // 6. result mappingawait runHooks('PostToolUse', result); // 7. post-hooksreturn result;}
The whole process is a clean request → response loop: the model requests, the system executes, the result is written back into the conversation history, and the model continues reasoning.
2.3 Tool Registration and Deduplication
Tool registration is usually handled by an assembly function: it merges built-in tools with external protocol tools (such as MCP-style tools), deduplicates by name, and gives built-in tools priority. This “built-in first” strategy ensures the stability of the platform’s core capabilities.
3. What Skills Really Are: Prompt Injectors
The biggest difference between skills and function calling lies in the semantics of the return value. Function calling returns a “result”; a skill returns “instructions.”
3.1 Inline Mode: Inject the Playbook, Let the Model Perform
In inline mode, once a skill is triggered, a pre-written “playbook” (steps, constraints, checklist items) is injected into the context as a metadata message. The model does not act immediately; instead, it follows the playbook and calls real tools step by step. The advantage is contextual continuity and strong explainability; the drawback is that it consumes the main conversation’s budget.
3.2 Fork Mode: Work in a Fork, Return Only the Result
In fork mode, the system opens an isolated sub-context (a sub-agent) for the skill. The skill orchestrates tool calls on its own inside the fork, and the main conversation only receives a condensed conclusion. The advantage is saving main-context space and isolating noise; the drawback is lossy results and a longer debugging chain.
3.3 A Real Trace of a Commit-Related Skill
Take generating a commit message as an example: the model triggers the skill → receives instructions to “first read the diff, then classify according to the convention, and finally output the template” → calls real tools in sequence, such as reading files, searching history, and formatting output → produces the result. Throughout the process, the skill never goes through tool_result; it only orchestrates the control flow.
4. Skill Discovery: Budget Control and Dynamic Visibility
Skills are not fully resident in the context; they form a dynamically visible set constrained by a “budget.” Based on task relevance, remaining context budget, and permission scope, the system decides which skill names and summaries to expose to the model for the current request. This avoids context bloat and reduces the probability of accidental triggering. In engineering practice, this is usually combined with layered loading: first provide names and one-line descriptions, then load the full playbook after the model makes a selection.
5. Implications for Writing Custom Skills
- Treat a skill as a “process description” rather than a “function”: spell out the steps, decision conditions, and output format.
- Define tool boundaries clearly: the skill does not do the work itself; it orchestrates real tools to do it.
- Design the return contract: inline mode emphasizes “instruction completeness,” while fork mode emphasizes “consumable conclusions.”
- Control the budget: keep descriptions concise, load on demand, and avoid name collisions with built-in capabilities.
- Put permissions up front: delegate sensitive operations to permission checks and hooks rather than writing them into the playbook.
6. A Common Agent Architecture Pattern from the Source-Code Perspective
Abstractly, a mature Agent architecture generally consists of four layers: a capability registration layer (unified assembly and deduplication of tools and skills), an execution pipeline layer (validation → hooks → permissions → execution → mapping), a context orchestration layer (inline injection and fork isolation), and a budget governance layer (dynamic visibility and layered loading). Function calling solves “what to do,” while skills solve “what process to follow”; the two are complementary rather than substitutes.
7. Conclusion
The key to understanding skills is to free them from the misreading that they are “tools”: they are control flow injectors. Once you master the two modes, inline and fork, along with the discovery and budget mechanisms, you can avoid detours when designing custom skills and push your understanding of Agent architecture from the interface level down to the source-code level. If you combine this with general-purpose cloud capabilities such as container platforms, log services, and monitoring and alerting for observability and canary releases, the engineering implementation of a skill system will be more robust.
