ExAgent. Skills
(ExAgent v3.0.0)
View Source
Skills that the model loads on demand (progressive disclosure).
Stability — Stable.
An agent with many specialised procedures should not send all of them on every request. With skills, the model sees a short catalog (name + description) and loads a skill's full instructions only when a task needs it:
skills = ExAgent.Skills.from_dir!(Application.app_dir(:my_app, "priv/skills"))
agent = ExAgent.new(model: model, instructions: "You are...", skills: skills)ExAgent.new/1 with :skills adds an ExAgent.Skills.Gate before the
agent's capabilities and ExAgent.Skills.Restore after them. The gate
contributes, through its ExAgent.Capability.tools/1:
- a
load_skilltool whose description lists the catalog. Its result (the skill instructions, plus its file list and newly available tools) becomes an ordinary tool return in the history, so a loaded skill stays in context across steps,ExAgent.Serverturns, snapshots and continuations; - a
read_skill_filetool, when a skill has a directory, to read files such asreferences/forms.mdrelative to that directory, never outside it; - every skill's
:tools, offered only once their skill has been loaded.
ExAgent.Skills.Restore restores loaded skills that a compaction capability
removed from the request.
A skill that cannot be loaded (too large or unreadable) and a file that
read_skill_file cannot read return a :tool_error result: the model sees
the reason and the run continues without spending tool retries. The tools'
max_retries: 2 applies to arguments that fail their schema, such as an
unknown skill name.
The catalog lives in the tool definition, so providers cache it with the other
tool definitions; changing the skill set changes that definition, like changing
any tool. The history is unchanged. The gate adds one constant instruction line
pointing at load_skill to each request; agent.instructions is unchanged.
Without :skills, agents are unaffected.
Directory layout
priv/skills/
release-notes/
SKILL.md
references/style.md
incident-report/
SKILL.mdA SKILL.md starts with YAML frontmatter:
---
name: release-notes
description: Write release notes. Use when asked to summarise changes for a release.
---
# Release notes
1. Read references/style.md ...This is the format used by other agent harnesses, so the same skills work
there. See ExAgent.Skill for fields and validation rules.
Tools gated by a skill
skills = ExAgent.Skills.from_dir!(dir, tools: %{"deploy" => DeployTools.tools()})The deploy tools are omitted from requests until deploy is loaded. They stay
in the agent inventory, so persisted continuations restore them as usual. A
tool listed both in :tools and in a skill is gated. The gate controls what
the model is offered; it is not an authority boundary.
Composing by hand
capabilities/2 returns the pieces ExAgent.new/1 adds, for example to
place a capability that measures the final request after :restore. Keep
:gate before capabilities that restrict the offered tools (so they keep the
final say) and :restore after any compaction capability. tools/2 returns
the tools the gate contributes.
Skills only add instructions and tools; they do not grant permissions or execute skill scripts.
Summary
Functions
Build the capabilities added for skills
Read every immediate subdirectory of root that contains a SKILL.md.
Like from_dir/2, raising ArgumentError on error.
Names of the skills successfully loaded in messages, each once, ordered by
its most recent load.
Build the tools added for skills: load_skill, read_skill_file when any
skill has a :path, then each skill's gated tools (deduplicated).
Validate a skill list for an agent: valid skills, unique names, and gated tools whose names are unique.
Functions
@spec capabilities([ExAgent.Skill.t()], keyword()) :: %{ gate: ExAgent.Skills.Gate.t(), restore: module() }
Build the capabilities added for skills:
:gate— anExAgent.Skills.Gatethat contributestools(skills, opts)and gates the skills' own tools. Place it before capabilities that restrict the offered tools.:restore—ExAgent.Skills.Restore. Place it after compaction.
opts are those of tools/2.
@spec from_dir(Path.t(), keyword()) :: {:ok, [ExAgent.Skill.t()]} | {:error, term()}
Read every immediate subdirectory of root that contains a SKILL.md.
Skills are returned sorted by name. Directories without SKILL.md and hidden
directories are ignored. An invalid skill, a duplicate name or an unreadable
root fails the whole call.
Options:
:tools— map of skill name to its gatedExAgent.Tools.
@spec from_dir!(Path.t(), keyword()) :: [ExAgent.Skill.t()]
Like from_dir/2, raising ArgumentError on error.
@spec loaded([ExAgent.Message.t()]) :: [String.t()]
Names of the skills successfully loaded in messages, each once, ordered by
its most recent load.
Useful to show which skills a conversation used, for example
{:ok, messages} = ExAgent.Server.history(server) and ExAgent.Skills.loaded(messages).
@spec tools([ExAgent.Skill.t()], keyword()) :: [ExAgent.Tool.t()]
Build the tools added for skills: load_skill, read_skill_file when any
skill has a :path, then each skill's gated tools (deduplicated).
The only option is :max_file_bytes (a positive integer, default 256 KiB).
It bounds the instruction body and the contents of each reference file.
The file list and tool names are added after the body check. Unknown,
duplicate or malformed options raise ArgumentError at construction.
@spec validate([ExAgent.Skill.t()]) :: :ok | {:error, term()}
Validate a skill list for an agent: valid skills, unique names, and gated tools whose names are unique.