AI Agent Skills: Code Architecture and Function Calling Explained
Agent skills and function calling serve different roles: skills package reusable task knowledge, while function calls connect model decisions to executable tools. This article explains their code-level architecture, inline and delegated execution, permission boundaries, progressive skill discovery, and evidence-based verification, with a repository commit workflow as a practical example.
1. Start with the Right Model: A Skill Is Not Just Another Function
To understand agent skills, first separate three architectural layers:
- Model layer: Understands the task, develops a plan, and decides what to do next.
- Orchestration layer: Manages messages, discovers skills, schedules tools, and enforces permission policies.
- Execution layer: Accesses files, runs commands, queries data, or interacts with external systems.
Function calling primarily connects the model layer to the execution layer. The model produces a structured invocation request, the application validates its arguments and executes the operation, and the result is returned to the model.
Skills primarily address how task knowledge reaches the agent. They package the procedures, constraints, reference materials, and acceptance criteria needed for a class of tasks, then supply that knowledge to the model or a separate execution unit when appropriate.
A more precise relationship is:
Function calling provides executable action interfaces. Skills provide the methods and constraints needed to complete a task. The agent orchestrator connects the two.
However, there is no universal underlying protocol for skills. Different systems may implement them as prompt templates, workflows, script packages, subagent configurations, or combinations of these. One implementation does not justify a blanket claim that all skills return instructions rather than results.
This article uses a common architecture: skills are primarily instruction documents loaded on demand by an orchestrator. The main agent or a separate execution unit then calls actual tools to complete the task.
2. How Function Calling Works in Code
2.1 Tool Definitions Describe Program Capabilities to the Model
A tool typically includes four types of information:
- A name and purpose.
- Structured constraints on input arguments.
- Permission-checking logic.
- An implementation function.
The following language-independent pseudocode illustrates the architecture. It does not represent any specific product interface:
ToolDefinition:namedescriptioninput_schemavalidate_arguments(arguments)authorize(context, arguments)execute(context, arguments)format_result(result)
An important boundary exists here: the model usually sees the tool name, description, and argument schema—not the implementation’s source code. The host application maintains that implementation and decides whether it may run.
For example, a file-reading tool might accept a file path and return its text. But the execution layer must enforce which paths are readable, whether sensitive directories are accessible, and whether returned content requires redaction. These controls should not depend on the model voluntarily following instructions.
2.2 A Model Generates a Request, Not Proof of Execution
A typical invocation flow looks like this:
User task→ Model generates a tool-call request→ Orchestrator parses the request→ Arguments are validated→ Permissions and policies are checked→ Tool executes→ Result is formatted→ Result is added to context→ Model continues reasoning
An implementation may also include pre- and post-execution hooks, timeouts, concurrency limits, retries, auditing, and result truncation. Their order and number vary. A particular implementation’s sequence should not be treated as a universal protocol requirement.
Three states must remain distinct:
- The model requests an invocation: It has expressed an intent.
- The system authorizes execution: The request has passed policy checks.
- The tool completes the operation: It has produced an actual result or side effect.
Only the third state can support claims such as “the file has been modified” or “the task has been submitted.” Generating tool-call text does not mean the operation occurred.
2.3 Tool Results Should Be Structured, but Not Treated as Trusted Instructions
Tool results may contain text, structured data, resource references, or errors.
A useful result structure separates these concerns:
ToolOutcome:statusdataerrorside_effectsevidence
A failed execution should return a failure status and a meaningful reason, rather than only an ambiguous description. For write operations, the result should record which objects changed, whether all steps completed, and whether the operation partially succeeded.
File contents, web pages, and text returned by external services may also contain instructions intended to redirect the model’s behavior. Such content should be treated as task data, not automatically granted the same authority as system policies.
3. The Core of a Skill: Loadable Task Knowledge
In a document-centered implementation, a skill can contain the following components:
SkillPackage:metadatainstructionsreferencesoptional_scriptsacceptance_criteria
Their roles are:
- Metadata: Describes the purpose, scope, and conditions for selecting the skill.
- Instructions: Define execution steps and key constraints.
- References: Provide specifications, examples, or domain knowledge.
- Optional scripts: Handle tasks suited to deterministic execution.
- Acceptance criteria: Define when completion can be reported.
A skill’s value is not simply that it adds more prompt text. It turns practical task knowledge into an asset that can be versioned, tested, and reused.
For example, a skill for reviewing changes and creating a commit should explain how to inspect the change scope, identify sensitive files, prepare a commit message, and handle unrelated modifications. Tools governed by permission controls must still perform the operations that actually change repository state.
3.1 Why Skill Loading and Tool Execution Are Often Confused
Some systems expose skill loading as a tool, so the model selects a skill through a structured invocation request. But the result may be a set of instructions to add to context rather than the outcome of a business operation.
An orchestrator might represent this through an internal event:
SkillLoadOutcome:instruction_documentsupporting_resourcesexecution_mode
It can then place the instructions in the appropriate message context or pass them to a dedicated task executor.
This means skill loading can use function calling as its interaction mechanism while serving a different semantic purpose: loading task knowledge.
It does not mean skills must bypass the tool-result channel. Some systems deliver instructions as tool results, others append internal messages, and others directly construct a subtask context. The important distinction is not the field name, but whether the model receives an operation result or rules for subsequent execution.
3.2 Authorized Instruction Loading Is Not the Same as Prompt Injection
Mechanically, loading a skill adds instructions to the model’s context. In security discussions, however, prompt injection usually refers to untrusted content attempting to cross a trust boundary and alter system behavior.
These should not be treated as equivalent.
The relevant security questions concern the skill’s source and authority. If arbitrary external documents can be elevated into high-priority task instructions, a security vulnerability may result. Even trusted skills must not override system safety policies or grant themselves permission to access secrets or perform dangerous operations.
4. Inline Mode: Execute the Skill in the Current Context
Inline execution follows a straightforward flow:
Current conversation→ Select a skill→ Load the required instructions→ Main agent plans the steps→ Invoke actual tools→ Continue based on results→ Verify completion and respond
Its main advantage is context continuity. The model already has the user’s background, previous decisions, and current state, so that information does not need to be passed again.
However, inline mode has three common drawbacks.
First, context growth.
Skill documents, references, and tool outputs accumulate, consuming space the model needs to understand the current task.
Second, instruction interference.
Rules from a completed skill may remain in context and influence later, unrelated tasks.
Third, noisy intermediate activity.
Exploratory reads, unsuccessful attempts, and lengthy outputs can make later decisions less clear.
Inline mode therefore suits shorter tasks that depend on the current conversation and require frequent user interaction. The orchestrator should explicitly scope the skill’s applicability and reduce residual influence after completion through structured summaries or context reconstruction. It should not assume the model can automatically “forget” old rules.
5. Delegated Mode: Use a Separate Execution Unit
Delegated, or branched, execution creates a subtask with its own context:
Main agent→ Construct subtask input→ Load the skill and required materials→ Subtask executor invokes restricted tools→ Return a structured result→ Main agent validates and summarizes
Here, “separate” primarily refers to context and task lifecycle. It does not necessarily imply operating-system isolation, separate permissions, or a new model instance.
If the subtask executor shares the main agent’s filesystem and write permissions, it can still affect the same workspace. Delegation should therefore not be equated with a security sandbox.
5.1 Subtask Input Should Be Minimal but Sufficient
Appropriate input typically includes:
- A clear task objective.
- Necessary business context.
- Accessible resources and permitted operations.
- Completion criteria.
- Requirements for the returned result structure.
Copying the entire conversation indiscriminately increases cost and exposes more potentially sensitive information.
5.2 Result Summaries Need Supporting Evidence
Returning only the outcome can reduce context noise, but the result should be more than “completed.”
A useful report structure is:
TaskReport:statussummarychanged_resourcesverificationunresolved_issuesevidence_references
The main agent can use this report to decide whether further review is needed, whether additional checks should run, or whether limitations must be explained to the user. For high-risk operations, independent verification is more reliable than accepting the subtask executor’s natural-language conclusion.
6. A Complete Workflow for Committing Changes
A repository commit task illustrates the architecture in six stages.
Stage 1: Match the Skill
The user asks the agent to review the current changes and create a commit. The orchestrator identifies candidate skills from their summaries and checks their applicability.
If the task also involves publishing, deletion, or remote synchronization, the scope should be clarified first. Permission to create a commit must not be interpreted as authorization for every subsequent operation.
Stage 2: Load the Rules
The model receives the skill instructions, such as:
- Inspect the workspace state first.
- Distinguish the user’s existing modifications from changes made for the current task.
- Exclude unrelated files.
- Check for content that could expose credentials.
- Generate a commit message based on the actual changes.
- Verify the result afterward.
No repository write operation has occurred at this point.
Stage 3: Read Status and Diffs
The model invokes read-only tools to inspect repository status and diffs. If the output is too long, it should be read file by file or filtered by scope. Truncating the output does not justify claiming that all changes have been reviewed.
Stage 4: Run Validation
The agent runs checks through the project’s existing validation mechanisms. It must distinguish between:
- Checks that passed.
- Checks that failed.
- Checks that could not run in the current environment.
Tests that were not run must not be reported as passing.
Stage 5: Perform the Write Operation
After permission policies are satisfied, the agent selects only the intended files for the commit. Where existing user changes, sensitive content, or irreversible actions are involved, it should pause and request confirmation as required by policy.
Stage 6: Verify and Report
Tool return values and subsequent state checks establish whether the commit succeeded. The agent then reports the change scope, validation results, and unresolved issues.
If the commit fails, it should describe the actual current state rather than presenting the plan as a completed action.
This workflow illustrates the division of responsibilities: the skill defines the execution strategy, function calling supplies action interfaces, permissions determine whether execution is allowed, and evidence determines whether completion can be claimed.
7. Skill Discovery: Avoid Loading Every Document at Once
As the number of skills grows, loading all of them creates context overhead and makes selection harder. Progressive discovery is a more practical approach:
- Initially expose short summaries.
- Filter candidate skills based on the task.
- Load full instructions only for the selected skills.
- Read additional references as needed during execution.
The context budget can be divided as follows:
Available context= Task information+ Skill instructions+ Tool results+ Headroom for reasoning
The allocation should be determined through task evaluation, not unsupported fixed percentages.
Dynamic visibility also matters. A skill that depends on unavailable resources or exceeds the user’s permissions can be temporarily excluded from matching.
However, hiding a skill is only a selection optimization—not a substitute for authorization. If the model requests the same operation through another route, the execution layer must still block it when required.
8. How to Write Custom Skills
8.1 Define Boundaries, Not Just Goals
“Help with data analysis” is too broad. A better description specifies input types, permitted data scope, output format, and situations where the skill does not apply.
Clear boundaries reduce accidental selection and excessive execution.
8.2 Separate Deterministic Steps from Judgment
Format conversion, field validation, and calculations based on fixed rules are suitable for scripts or tools. Understanding requirements, explaining anomalies, and choosing an approach are better suited to the model.
Do not repeatedly ask the model to generate operations that deterministic software can perform reliably. Equally, avoid forcing decisions that require semantic understanding into brittle hard-coded rules.
8.3 Specify Failure Paths
A skill should describe not only the successful path, but also:
- How to ask for missing input.
- When to stop because permissions are insufficient.
- How to handle tool timeouts.
- How to report partial success.
- How to block execution when sensitive information is detected.
- Whether execution may continue after validation fails.
Retries require particular care for write operations. Repeating a read usually has limited impact, while repeating a creation, deduction, commit, or send operation may cause real side effects. Retry decisions should depend on both idempotency and state checks.
8.4 Make Acceptance Criteria Observable
“The result is correct” is not a sufficient acceptance criterion. Prefer verifiable conditions such as:
- The target file exists.
- A check returns a passing status.
- The record count matches the input.
- The state after a write matches the expected outcome.
Skill tests should also cover normal execution, invalid arguments, permission denial, malicious content, tool failures, and insufficient context.
9. Function Calling and Skills: Differences and Architectural Conclusions
| Dimension | Function calling | Skills |
|---|---|---|
| Primary purpose | Connect model decisions to program operations | Organize reusable task knowledge and procedures |
| Typical input | Structured arguments | Task objectives, context, and resources |
| Typical output | Data, status, or operation results | Loaded instructions, execution plans, or task results |
| Executor | Tool implementations in the host application | Main agent, subtask executor, or workflow |
| Main control points | Arguments, permissions, timeouts, and side effects | Source trust, context scope, and procedural constraints |
| Relationship | Can load or execute skills | Can combine multiple tools to complete a task |
Both need clear inputs and outputs, error handling, permission constraints, and observability. Their difference lies in the abstraction layer they address.
Reliable agent design separates four concerns: how knowledge is loaded, how the model makes decisions, how operations are authorized, and how results are verified.
Skills capture reusable task methods. Function calling connects the model to actual capabilities. The orchestrator manages lifecycle and policy enforcement. With these boundaries explicit, a skill becomes a maintainable, testable, reusable engineering asset rather than an unwieldy prompt.
