Agent Skills and Function Calling: Code-Level Implementation and Execution Mechanisms
This article explains the difference between agent skills and function calling, then examines how each works in code and in an agent runtime. It covers tool declarations, parameter validation, execution pipelines, skill packaging and on-demand loading, inline versus isolated subtasks, a complete commit workflow, skill discovery with context budgets, and practical rules for writing reliable custom skills. It concludes with the architectural separation of task knowledge, orchestration, and execution permissions.
1. Establish the Right Mental Model: Skills and Function Calling Operate at Different Layers
When building agents, developers often encounter two concepts: skills and function calling. Both allow a model to complete tasks beyond conversation, so they are easily understood as two competing capability systems.
In practice, they usually solve different problems.
Function calling converts model decisions into structured requests that a host program can execute. Examples include reading files, querying business data, running tests, and submitting changes. It focuses on which capability is called, which arguments are passed, and which result is returned.
Skills primarily encapsulate task knowledge: for a given type of goal, which prerequisites should be checked, which steps should be followed, which tools should be called, and how to determine that the task is complete. They focus on how the task should be done.
A simple relationship can describe the division of responsibilities:
Skills provide the task process, the model makes decisions based on that process, function calling carries out specific actions, and the execution environment enforces permissions and security limits.
One important caveat: skills do not have a unified industry implementation standard. Some systems implement them as operation instructions loaded on demand, some implement them as independent subtasks, and others use deterministic workflows for direct execution. It is not valid to infer that every agent uses the same mechanism based on the fields, message types, or execution branches of one implementation.
2. How Function Calling Works at the Code Level
1. A Tool Declaration Is Only a Capability Description, Not Execution
A tool typically contains the following information:
- Name: identifies the capability that can be called.
- Description: helps the model decide when the tool is appropriate.
- Input schema: defines argument types, required fields, and value constraints.
- Execution function: performs the actual operation in the host environment.
- Permission policy: determines whether the current user and session may execute the tool.
- Result handling: converts the execution result into data the model can understand.
The following is a conceptual example. The fields only illustrate the architecture and do not correspond to a specific product interface:
tool definition = {name: "read_file",description: "Read a text file within an authorized working directory",parameter_schema: {path: text,start_line: optional integer,end_line: optional integer},permission_check: check whether the path is within the allowed scope,execute: read the specified file,result_handler: limit length and return text}
What is usually sent to the model is the tool name, description, and parameter schema, not the source code of the execution function.
The tool request generated by the model is also only an action waiting to be executed. The host program is still responsible for actually reading the file. The model does not gain operating system permissions simply because it outputs a function name.
2. Parameter Schemas Cannot Replace Business Validation
Tool calls require at least two kinds of validation.
The first is structural validation. For example, a path must be a string, line numbers must be integers, and required fields must be present.
The second is semantic and security validation. For example, does the path escape the allowed directory, does the file contain sensitive information, and does the current user have read permission?
An argument can fully conform to its schema and still be unsafe. Therefore, “the arguments match the schema” cannot be treated as a sufficient condition for “the tool may execute.”
3. The Execution Pipeline Needs Central Management
A relatively complete execution flow can be represented as:
receive call request→ parse and validate arguments→ validate business constraints→ pre-execution policy check→ permission decision→ call execution function→ normalize results and errors→ record audit information→ return to model
The exact steps and order vary by system, but security rejection should occur before side effects are produced.
For operations such as writing files, sending notifications, and modifying databases, idempotency, timeouts, concurrency control, and failure recovery should also be considered. A model may request the same operation again because it did not receive a result. If the host program does not identify duplicate requests, duplicate writes or duplicate sends may occur.
3. The Core of Skills: Assembling Task Knowledge on Demand
1. A Skill Can Be Understood as a Task Knowledge Package
A skill can typically consist of the following:
skill package├── metadata: name, purpose, applicable conditions├── operating instructions: steps, constraints, failure handling├── reference material: specifications, examples, checklists├── optional resources: templates, scripts, or supporting files└── execution policy: context scope and permission requirements
Operating instructions are the core, but a skill does not necessarily contain only prompt text. It may also carry templates and supporting scripts, and may even include explicit programmatic execution logic.
Therefore, summarizing every skill as “a prompt wearing a tool’s clothing” is not precise. A more accurate statement is: in prompt-driven skill architectures, the skill entry point may appear as a tool, but its main role is to assemble task knowledge into a context visible to the model.
2. Loading a Skill Does Not Mean the Task Is Complete
Suppose the user asks the agent to “organize the current changes and create a local commit.”
The agent first calls the skill entry point, and the system loads instructions for the commit task. At this point, only knowledge loading has been completed, not the commit operation.
Next, the model still needs to call the actual tools according to the instructions:
user states goal→ select commit skill→ load inspection process→ query change status→ read diffs→ run necessary validation→ determine commit scope→ complete commit→ summarize results
This is one of the most important differences between skills and ordinary tool results: an ordinary tool usually returns the result of an action, while a prompt-driven skill may return task context describing how to act next.
3. How Instructions Enter the Model Context
Skill content can enter the reasoning process in multiple ways, for example:
- presented to the model as tool return content;
- inserted into subsequent requests as controlled task context;
- used by an orchestration layer to construct an independent subtask;
- converted directly into workflow nodes for execution.
These approaches differ in message packaging and control flow. It is not valid to claim broadly that skills must use a special message marker or must bypass the tool result mechanism.
The more important engineering questions are: where the skill content comes from, what trust level it has, and which behaviors it can influence.
Reviewed built-in skills, user-defined skills, and externally downloaded skills should not automatically receive the same trust level. Loading a skill should not allow it to override system safety rules or expand tool permissions.
4. Two Common Runtime Modes: Inline and Isolated Subtasks
1. Inline Mode: Continue Execution in the Current Session
Inline mode adds skill instructions to the current task context, and the current model continues reasoning and calling tools.
Its main advantage is contextual continuity: the model can directly use the user’s earlier requirements, files already read, and previous execution results.
It also has clear costs:
- skill instructions consume context space;
- multiple skills may create conflicting rules;
- when intermediate results are excessive, main task information may be pushed out;
- incorrect instructions may continue to affect later reasoning.
Inline skills should therefore be as focused as possible. Loading all reference material at once is usually not advisable. Reading detailed documentation only when needed is generally better for controlling context cost.
2. Isolated Subtask Mode: Assign Work to an Independent Execution Unit
Isolation mode creates a separate task context, provides the goal, necessary materials, and allowed tools to a child execution unit, and lets the main workflow wait for the result.
Here, “independent” usually means separation of reasoning context and task state. It does not necessarily mean a new operating system process has been created, and it certainly does not necessarily mean security isolation has been achieved.
A reasonable subtask input should clearly specify:
goal: check tests potentially affected by the current changesinput: relevant files, change summary, test directoryallowed capabilities: read files, run specified testsforbidden capabilities: delete files, modify commit historyoutput: inspection conclusion, evidence, failures, unverified items
This mode is suitable for parallel analysis and inspection tasks with clear boundaries, but it also introduces information transfer costs. The main task should not receive only a sentence saying “inspection passed”; it should also receive traceable evidence and coverage scope.
If multiple subtasks can modify the same working directory, separating contexts alone cannot avoid conflicts. In that case, directory isolation, locking, version checks, or serialized write strategies are also needed.
5. Use a Code Commit Task to Connect the Full Execution Chain
A reliable commit skill should not only tell the model to “review the diff and commit.” It should define a verifiable process and exit conditions.
Step 1: Confirm the Goal and Work Scope
Check whether the current working directory is correct, whether there are unfinished merge operations, and which changes the user expects to commit.
If the directory contains both the user’s original changes and new changes made by the agent, do not include all files in the commit by default. The scope should be confirmed based on task records, diff content, and user intent.
Step 2: Inspect the Changes
The model reads status and diffs through tools and identifies functional changes, configuration changes, generated files, and potential sensitive information.
Inspection here cannot rely only on file names. A seemingly ordinary configuration file may also contain credentials or environment-specific data.
Step 3: Run Necessary Validation
Select tests, builds, or static checks according to the change scope. If the environment cannot execute them, explicitly mark the changes as “unverified.” Do not interpret “not run” as “passed.”
Validation results should also include execution scope. One set of passing tests does not mean the entire project has been comprehensively validated.
Step 4: Recheck Status Before Execution
The workspace may change between analysis and execution. Therefore, before the actual commit, file status and diffs should be confirmed again. When necessary, versions or content digests should be checked to avoid committing new changes that have not been inspected.
Step 5: Execute and Report
After completing the local commit, report the files actually included, validation results, commit identifier, and remaining risks.
A local commit and a remote publish are different permission actions. The latter should not be performed automatically just because the former succeeded.
This process demonstrates the value of skills: they organize the process and checkpoints, but all reads, tests, and writes should still be performed through controlled tools.
6. Why Skill Discovery Needs Budgets and Dynamic Visibility
As the number of skills grows, placing all full instructions into every model request is unreasonable. It increases context overhead and presents the model with many similar descriptions, reducing selection accuracy.
A more common design is layered loading:
- First expose short names, purposes, and trigger conditions.
- Filter candidate skills based on user goals, project state, and permissions.
- After confirming that a skill is needed, load the full instructions.
- When citing large reference materials, continue reading only the relevant parts on demand.
Dynamic visibility can also prevent the model from selecting capabilities that cannot currently be executed. For example, a read-only session does not need to expose publishing skills, and when a validation environment is missing, the limitations of relevant skills should be indicated.
However, “not shown to the model” does not mean “a permission boundary has been established.” Even if the model guesses a tool name, the execution layer must still reject unauthorized calls.
For context budgets, priority should be given to user goals, safety constraints, key decisions, and validation evidence, and only then should repeated instructions and verbose logs be compressed. Task boundaries must not be lost just to save space.
7. How to Write Reliable Custom Skills
1. Define Clear Inputs and Completion Conditions
Skill instructions should answer at least the following:
- In which scenarios should the skill be used?
- Which prerequisite information is needed?
- Which actions may be executed automatically?
- Which actions require confirmation?
- How is success determined?
- How should the agent exit on failure or uncertainty?
Broad goals such as “optimize the project” or “complete deployment” are too vague. They should be divided into tasks with clear artifacts and permission boundaries.
2. Put Deterministic Constraints in Code
Natural language is suitable for expressing policy and judgment criteria, but it is not suitable for carrying all safety limits.
Path scope, database write permissions, sensitive field filtering, and maximum retry counts should be enforced by programs. Skill instructions can remind the model, but they cannot become the only line of defense.
A basic principle is: prompts guide, code constrains.
3. Distinguish Task Material from Trusted Instructions
File content, web page text, and logs may all contain instruction-like statements. When the model reads these materials, it should treat them as data to be analyzed, not as commands to execute automatically.
The skill loader needs to record content sources and prevent external material from gaining higher priority through skill entry points.
4. Design Failure Paths, Not Just Success Paths
Tool failures may come from invalid arguments, insufficient permissions, missing resources, timeouts, or environment changes. Different causes should use different strategies:
- Invalid arguments: correct them and retry a limited number of times;
- Insufficient permissions: stop and request authorization;
- Missing resources: check whether the target is correct;
- Execution timeout: first confirm whether side effects have already occurred;
- Workspace changes: inspect again before execution.
Blind retries are not a reliability design.
5. Evaluate Trajectories, Not Only Final Answers
Skill tests should check both task results and the execution process.
In addition to success rate, observe whether unnecessary tools were called, whether authorization was exceeded, whether success was claimed with insufficient evidence, and whether the agent can recover or exit safely after failure.
For enterprise scenarios, a task that “happened to complete” is less valuable than an execution path that is explainable, auditable, and reproducible.
8. Similarities, Differences, and Architectural Conclusions
Skills and function calling share several common points: both need to be discovered and selected by the agent, both may be subject to permission limits, and both should be included in logging and auditing.
Their main differences are:
- Abstraction level: function calling provides action capabilities, while skills organize task capabilities.
- Input form: function calling emphasizes structured arguments, while skills also include goals, processes, and context.
- Output meaning: function calling usually returns execution results, while a skill entry point may return operating instructions or subtask results.
- Execution cycle: function calling is usually a single action interaction, while a skill may cover multiple rounds of reasoning and multiple calls.
- Security responsibility: skills cannot grant permissions by themselves; final execution authority must be controlled by the host environment.
A complete agent architecture can therefore be divided into three layers:
The task layer understands goals and selects skills; the orchestration layer assembles context, manages subtasks, and determines process state; the execution layer validates arguments, controls permissions, runs tools, and records results.
Skills do not give the model new capabilities out of thin air. They allow existing capabilities to be used more methodically. Function calling is not a complete task solution either; it is only the bridge between model decisions and real execution.
Only by designing process knowledge, runtime orchestration, and execution permissions separately can an agent remain flexible while becoming a maintainable, verifiable, and auditable engineering system.
