Learning Objectives
- Distinguish explicit user invocation, implicit model invocation, application invocation, and skill-to-skill invocation.
- Model human visibility and model eligibility as independent policy dimensions.
- Write routing descriptions with positive triggers and near-miss boundaries.
- Separate eligibility, selection, activation, argument binding, and execution in traces and tests.
- Adapt runtime-specific invocation fields without presenting them as portable frontmatter.
The Problem
You install a database-migration skill. The user can run it by name, but the model also sees its description and selects it when someone asks a general database question. The skill then proposes a schema change for a task that only needed an explanation.
You add user-invocable: false, expecting to block people from running it manually. In another runtime, that field is ignored. You add disable-model-invocation: true, expecting the skill to disappear entirely. In the runtime that understands it, the user can still invoke it explicitly.
Nothing is wrong with the field names. The model is wrong. "User can see it," "model can select it," "application can preload it," and "tools inside it can execute" are separate facts. A single boolean called invocable cannot express them.
Routing has a second failure mode. If descriptions are vague, several skills become plausible. If descriptions are stuffed with keywords, unrelated tasks trigger them. The catalog is a probabilistic interface: compact enough to fit, specific enough to route.
The Concept
Five channels can start the lifecycle
| Actor | Invocation shape | Typical use | Main risk |
|---|---|---|---|
| Human user | Names a skill in the UI or prompt | Deliberate workflow selection | User expects availability or authority the host does not grant |
| Model or autonomous agent | Selects a catalog entry from task context | Automatic expert procedure | False-positive routing |
| Application | Activates or preloads a skill through runtime code | Fixed product workflow | Hidden coupling to one host |
| Another skill or subagent | Requests an exact skill as a workflow dependency | Composition | Cycles, missing dependency, or context bleed |
| Evaluation harness | Activates an exact skill under a fixed scenario | Repeatable measurement | Tests the skill while accidentally bypassing the production policy under study |
The portable Agent Skills specification defines the package. It does not standardize one universal slash-command UI, implicit-routing flag, application API, or subagent lifecycle.
The five invocation stages
Interactive figure coming later.
Use these words precisely:
- Eligible means policy permits this actor to request the skill.
- Selected means the user named it or a router judged it relevant.
- Activated means its instructions entered the working context.
- Executing means the agent began model or tool work under those instructions.
- Completed means the output met an independent success check.
A trace that records only skill_used=true hides the boundary where a failure happened.
Human and model invocation form a 2x2 matrix
| Human can invoke | Model can invoke | Mode | Suitable examples |
|---|---|---|---|
| Yes | Yes | Shared | Code explanation, test planning, documentation review |
| Yes | No | Human-only | Publish preparation, billing export, destructive cleanup plan |
| No | Yes | Model-only | Internal style guide, domain reference, automatic support procedure |
| No | No | Disabled or application-only | Staged rollout, deprecated package, programmatic preload |
The matrix is a policy model, not standard YAML.
One current host uses disable-model-invocation: true for the human-only row and user-invocable: false for the model-only row. The default is both. Another host uses agents/openai.yaml with allow_implicit_invocation: false to keep explicit invocation while disabling implicit selection. These are runtime adapters. Unknown hosts may ignore them.
The confusing detail matters: user-invocable: false does not mean "the model cannot use this." It removes direct user invocation in the host that defines it. disable-model-invocation: true does not mean "the skill is disabled." It removes model-initiated selection while keeping explicit user access.
Explicit invocation is identity-first
An explicit invocation supplies identity directly:
/release-readiness v2.4.0
or:
release-readiness check v2.4.0 without publishing
Current Codex interfaces document /skills for selection and plain skill names in requests for explicit invocation. Claude Code documents /skill-name and host-specific argument expansion. The exact syntax, menu visibility, quoting rules, and variable expansion belong to the host.
An explicit request still passes policy. Naming a skill should not bypass missing permissions, workspace constraints, approval gates, or runtime isolation.
Implicit invocation is description-first
For implicit routing, the model initially sees catalog metadata rather than the full body. The description is therefore the skill's routing interface.
Weak:
description: Helps with releases.
Over-broad:
description: Use for release, version, package, build, deploy, publish, tag, changelog, GitHub, CI, or software tasks.
Bounded:
description: Inspect an already prepared release candidate and produce a readiness report. Use when the user asks whether a version, tag, package, or image is ready to publish; do not use for ordinary build failures or feature development.
The bounded version contains:
- Capability: inspect a prepared candidate.
- Output: readiness report.
- Positive boundary: asks whether a release artifact is ready.
- Negative boundary: ordinary builds and development are out of scope.
Negative boundaries are useful when two nearby skills share vocabulary. They are not a replacement for near-miss evals.
Routing is classification with an abstain option
For a skill s and request x, imagine a router score:
score(s, x) = capability_match + trigger_match + context_match - exclusion_match - ambiguity_penalty
The exact scoring may be an LLM decision rather than arithmetic. The engineering principle still holds: selection should beat a threshold and a competing skill. When evidence is weak, abstain.
Interactive figure coming later.
For high-impact skills, implicit routing may be inappropriate even with a strong description. Use human-only policy when the cost of a false positive exceeds the convenience of automatic selection.
Eligibility must precede ranking
Do not score every discovered skill, choose the strongest match, and check that one skill's policy afterward. A blocked top match would incorrectly prevent an eligible lower-scored candidate from being considered.
Use this order for implicit routing:
- Filter discovered skills by the requesting actor and the active host adapter.
- Score only the eligible candidates.
- Select the strongest eligible match if it clears the threshold and ambiguity rules.
- Abstain when no candidate is eligible or no eligible score is strong enough.
Suppose incident-triage scores 0.80 but its host extension disables model invocation. incident-review scores 0.55 and allows model invocation. The router should evaluate incident-review as the best eligible candidate. It should not choose incident-triage, deny it, and stop.
This ordering also keeps policy changes from altering the meaning of a relevance score. Eligibility defines the selection set. Relevance ranks that set.
Routing evals need near misses
Positive cases prove recall:
{"prompt":"Is version 2.4.0 ready to publish?","expected":"release-readiness"}
Clear negatives prove basic precision:
{"prompt":"Explain rotary position embeddings.","expected":null}
Near misses expose boundary quality:
{"prompt":"Why did today's package build fail?","expected":"build-diagnostics"}
The near miss shares package and build with the release skill but belongs elsewhere. A routing set made only of obvious positives and unrelated negatives will overstate quality.
Arguments have three representations
An invocation argument crosses several boundaries:
Interactive figure coming later.
At each boundary, preserve intent without treating text as code.
- The host parser decides command syntax and quoting.
- The skill receives bound text or variables according to host rules.
- The instructions validate required values and defaults.
- A tool call converts values to a typed schema and revalidates them.
Do not interpolate raw arguments into shell commands. Prefer a script invoked with an argument vector or a typed MCP tool.
Application invocation is explicit orchestration
A product can activate a skill because its workflow already knows the task type. For example, a pull-request review service can preload pull-request-risk-review after the user presses Review.
This removes routing uncertainty but creates a dependency on the runtime API. Keep that adapter outside the portable body:
Interactive figure coming later.
The skill should remain intelligible when opened by a different compliant client.
Skill-to-skill invocation is a tool-like edge
Suppose release-readiness asks for security-change-review when dependency files changed.
The caller should provide:
- the target skill identity;
- a bounded task and artifact paths;
- the expected response contract;
- the reason for invocation;
- a fallback if unavailable;
- a maximum depth or cycle rule.
{
"target_skill": "security-change-review",
"task": "Review dependency changes in the candidate diff",
"inputs": ["artifacts/release.diff"],
"expected": "risk-report.json",
"max_depth": 2
}
The second skill is not pasted blindly into the first. The host decides how to activate it and whether it shares context, runs in a fork, or returns through a tool result.
Context lifecycle is host-specific
After activation, the skill body may remain in the conversation, be summarized during compaction, or run in a delegated context. Tool allowances may last one turn while instructions persist longer. A subagent may receive the skill without the parent's entire history.
Do not write a skill that depends on an invisible lifetime assumption. Put durable outputs in files or typed state, make re-entry safe, and state what must be reloaded after interruption.
On resume, read `artifacts/release-readiness.json` if it exists.
Revalidate the candidate commit before continuing.
Do not repeat an external write whose idempotency key is already recorded.
Build It
code/main.py implements policy and routing as separate adapters.
The model includes:
Actorfor human, model, autonomous agent, application, skill, and harness callers;SkillMetadatafor routing identity;InvocationPolicyfor the human/model matrix;InvocationRequestandInvocationDecisionfor traceable inputs and outcomes;CorePolicyAdapterfor portable behavior with no host extensions;ExtensionPolicyAdapterfor recognized runtime fields;build_invocation_matrix(policy)for the 2x2 view;route_request(skills, request, adapter)for eligibility filtering before relevance ranking, selection, and denial.
Run it:
cd phases/13-tools-and-protocols/25-skill-invocation-and-routing
python3 code/main.py
python3 -m unittest discover -s code/tests -v
The demo prints one matrix and decisions for explicit human, implicit model, autonomous-agent, application, skill-composition, and harness channels. Its extension-adapter results show a blocked top lexical match being removed before an eligible alternative is ranked. It also includes exact-name allowlists. No model API is required. The deterministic router exists to make policy boundaries inspectable, not to claim that lexical matching reproduces production model routing.
Why core and extension adapters are separate
If one parser assigns meaning to every observed frontmatter field, it silently promotes runtime conventions into a fake standard. Separate adapters force the caller to name which host semantics are active.
The CorePolicyAdapter uses only application-supplied policy. The ExtensionPolicyAdapter recognizes an explicit set of host fields and records which field changed the decision.
Use It
Write an invocation contract before publishing a skill:
actors:
human: allow
model: deny
application: allow
skill: deny
explicit_name: release-readiness
arguments:
candidate: required
publish: fixed_false
ambiguity: ask_user
missing_dependency: stop
context:
durable_state: artifacts/release-readiness.json
max_composition_depth: 2
This contract is design documentation for adapters and tests. It is not portable SKILL.md frontmatter unless a standard explicitly adopts it.
Ship It
This lesson produces the skill-invocation-router bundle. It includes an invocation-model reference, an example host policy, and a non-executing CLI that evaluates one human, model, autonomous-agent, application, skill-composition, or harness request and returns a JSON decision with channel, adapter, score, and reason.
The one-request CLI is a policy probe, not a full trigger evaluation. Use the labeled positive and near-miss design in Lesson 27 to compute confusion counts, precision, recall, and repeated-run stability.
Exercises
- Create all four rows of the human/model matrix and write one legitimate use case for each.
- Add application-only activation to
CorePolicyAdapter. Prove that human and model callers remain denied. - Write ten near misses for a deployment skill. Each prompt must share vocabulary with the skill while belonging to a different workflow.
- Add an ambiguity margin between the top two routing scores. Return
askwhen the margin is too small. - Add a maximum composition depth to skill-to-skill requests and detect a two-skill cycle.
- Run the same labeled set through core and extension adapters. Explain every changed decision.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| Explicit invocation | "Slash command" | An actor supplies skill identity directly, subject to policy |
| Implicit invocation | "The model chooses" | A router selects from eligible catalog metadata based on task context |
| User-invocable | "Humans can use it" | A host-specific menu or direct-invocation property, not a core field |
| Model-invocable | "The agent can use it" | Eligibility for implicit model selection under host policy |
| Invocation adapter | "Frontmatter parser" | Code that maps a host's fields and APIs into a declared policy model |
| Near miss | "Hard negative" | A non-triggering request that resembles a skill's intended inputs |
| Abstention | "No skill selected" | A deliberate routing result when evidence is absent or ambiguous |
Further Reading
- Optimizing skill descriptions for positive triggers, specificity, and evaluation.
- Evaluating skills for trigger and output eval design.
- OpenAI: Build skills for current Codex explicit and implicit invocation controls.
- Claude Code skills for one host's
user-invocable,disable-model-invocation, arguments, and delegated context.
Code
main.py
python phases/13-tools-and-protocols/25-skill-invocation-and-routing/code/main.pyOpen on GitHub ↗tests/test_main.py
python phases/13-tools-and-protocols/25-skill-invocation-and-routing/code/tests/test_main.pyOpen on GitHub ↗
Take-away files
skill-invocation-router/assets/host-policy.json
{
"allowHuman": true,
"allowModel": true,
"allowAgent": true,
"allowProgrammatic": true,
"allowApplication": true,
"allowSkill": true,
"modelThreshold": 0.2,
"harnessAllowlist": ["incident-triage"],
"applicationAllowlist": ["release-notes"],
"skillCallerAllowlist": ["release-readiness"],
"maxSkillDepth": 2,
"recognizedExtensions": ["user-invocable", "disable-model-invocation"]
}
skill-invocation-router/references/invocation-model.md
# Invocation model | Channel | Initiator | Selection | Typical use | |---|---|---|---| | Explicit human | User | Exact discovered name | Deliberate workflow choice | | Implicit model or agent | Model or autonomous agent | Description relevance plus host policy | Context-sensitive routing | | Programmatic application | Product runtime | Exact configured name and target allowlist | Deterministic product workflow | | Skill composition | Another skill or subagent | Exact target, caller identity, and depth policy | Bounded workflow dependency | | Programmatic harness | Evaluation runtime | Exact configured name and target allowlist | Deterministic evaluation | Human and model activation form a 2x2: neither, human only, model only, or both. Application, composition, and harness activation are separate channels with their own target, caller, and depth policies. For implicit routing, apply actor and host-extension eligibility before relevance ranking. A blocked high-scoring skill is not the winner; remove it from the selection set and evaluate the remaining eligible candidates. Abstain if the eligible set is empty or its best score misses the threshold. Fields such as `user-invocable` or `disable-model-invocation` may be meaningful to a particular host. An adapter may enforce them, but portable documentation must not claim that every runtime recognizes the same fields or values.
skill-invocation-router/scripts/simulate_invocation.py
#!/usr/bin/env python3
"""Simulate one invocation decision and print JSON; no skill code is executed."""
from __future__ import annotations
import argparse
import json
import math
import re
from pathlib import Path
def tokens(value: str) -> set[str]:
return set(re.findall(r"[a-z0-9]+", value.lower()))
def score(query: str, name: str, description: str) -> float:
left, right = tokens(query), tokens(f"{name} {description}")
return 0.0 if not left or not right else len(left & right) / len(left | right)
def policy_bool(policy: dict[str, object], key: str, default: bool = False) -> bool:
value = policy.get(key, default)
if type(value) is not bool:
raise ValueError(f"{key} must be a JSON boolean")
return value
def string_list(policy: dict[str, object], key: str) -> list[str]:
value = policy.get(key, [])
if not isinstance(value, list) or not all(
isinstance(item, str) and item for item in value
):
raise ValueError(f"{key} must be an array of non-empty names")
return value
def validate_policy(
policy: dict[str, object],
) -> tuple[float, list[str], list[str], list[str], list[str], int]:
threshold = policy.get("modelThreshold", 1.0)
if (
isinstance(threshold, bool)
or not isinstance(threshold, (int, float))
or not math.isfinite(threshold)
or not 0.0 <= threshold <= 1.0
):
raise ValueError("modelThreshold must be a finite number from 0 to 1")
harness_allowlist = string_list(policy, "harnessAllowlist")
recognized = string_list(policy, "recognizedExtensions")
application_allowlist = string_list(policy, "applicationAllowlist")
skill_callers = string_list(policy, "skillCallerAllowlist")
max_depth = policy.get("maxSkillDepth", 1)
if type(max_depth) is not int or max_depth < 1:
raise ValueError("maxSkillDepth must be a positive integer")
return (
float(threshold),
harness_allowlist,
recognized,
application_allowlist,
skill_callers,
max_depth,
)
def decide(args: argparse.Namespace, policy: dict[str, object]) -> dict[str, object]:
actor = args.actor
(
threshold,
harness_allowlist,
recognized,
application_allowlist,
skill_callers,
max_depth,
) = validate_policy(policy)
channel = {
"human": "explicit-human",
"model": "implicit-model",
"agent": "implicit-agent",
"application": "programmatic-application",
"skill": "composed-skill",
"harness": "programmatic-harness",
}[actor]
adapter = "host-extension-policy" if recognized else "core-policy"
if actor == "human":
allowed = policy_bool(policy, "allowHuman") and args.explicit_name == args.name
reason = "exact human selection" if allowed else "human policy or exact-name check blocked activation"
match_score = 1.0 if args.explicit_name == args.name else 0.0
if "user-invocable" in recognized and args.user_invocable == "false":
allowed = False
reason = "host extension user-invocable=false"
elif actor == "harness":
allowed = (
policy_bool(policy, "allowProgrammatic")
and args.explicit_name == args.name
and args.name in harness_allowlist
)
reason = "programmatic allowlist" if allowed else "programmatic policy, exact name, or allowlist blocked activation"
match_score = 1.0 if args.explicit_name == args.name else 0.0
elif actor == "application":
allowed = (
policy_bool(policy, "allowApplication")
and args.explicit_name == args.name
and args.name in application_allowlist
)
reason = "application target allowlist" if allowed else "application policy, exact name, or target allowlist blocked activation"
match_score = 1.0 if args.explicit_name == args.name else 0.0
elif actor == "skill":
caller_name = getattr(args, "caller_name", None)
depth = getattr(args, "depth", 0)
allowed = (
policy_bool(policy, "allowSkill")
and args.explicit_name == args.name
and caller_name in skill_callers
and caller_name != args.name
and type(depth) is int
and 1 <= depth <= max_depth
)
reason = "skill caller and depth policy" if allowed else "skill policy, exact target, caller allowlist, cycle, or depth blocked activation"
match_score = 1.0 if args.explicit_name == args.name else 0.0
else:
policy_key = "allowAgent" if actor == "agent" else "allowModel"
match_score = 0.0
eligible = policy_bool(policy, policy_key)
if not eligible:
allowed = False
reason = f"{actor} activation policy blocked eligibility"
elif (
"disable-model-invocation" in recognized
and args.disable_model_invocation == "true"
):
allowed = False
reason = "host extension disable-model-invocation=true"
else:
match_score = score(args.query, args.name, args.description)
allowed = match_score >= threshold
reason = (
"model relevance threshold"
if allowed
else "relevance threshold blocked activation"
)
return {
"activated": allowed,
"adapter": adapter,
"actor": actor,
"channel": channel,
"skill": args.name,
"score": round(match_score, 4),
"reason": reason,
}
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--policy", type=Path, required=True)
parser.add_argument(
"--actor",
choices=("human", "model", "agent", "application", "skill", "harness"),
required=True,
)
parser.add_argument("--name", required=True)
parser.add_argument("--description", required=True)
parser.add_argument("--query", default="")
parser.add_argument("--explicit-name")
parser.add_argument("--caller-name")
parser.add_argument("--depth", type=int, default=0)
parser.add_argument("--user-invocable", choices=("true", "false"))
parser.add_argument("--disable-model-invocation", choices=("true", "false"))
args = parser.parse_args()
policy = json.loads(args.policy.read_text(encoding="utf-8"))
try:
result = decide(args, policy)
except ValueError as error:
result = {
"activated": False,
"actor": args.actor,
"channel": "policy-validation",
"adapter": "invalid-policy",
"skill": args.name,
"score": 0.0,
"reason": str(error),
}
print(json.dumps(result, indent=2, sort_keys=True))
raise SystemExit(2) from error
print(json.dumps(result, indent=2, sort_keys=True))
if __name__ == "__main__":
main()
skill-invocation-router/SKILL.md
--- name: skill-invocation-router description: Design and test explicit human, implicit model or agent, programmatic application, bounded skill-composition, and harness activation policies for an Agent Skill catalog. license: MIT metadata: lesson: "25" --- # Skill invocation router Use this skill when a host needs an auditable activation policy rather than one undifferentiated `invocable` flag. 1. Read `references/invocation-model.md` and classify the requested channel. 2. Review `assets/host-policy.json` as an example adapter configuration, not a portable standard. 3. Run `python3 scripts/simulate_invocation.py --policy assets/host-policy.json --actor ACTOR --name NAME --description DESCRIPTION --query QUERY [--explicit-name NAME] [--caller-name NAME] [--depth N] [--user-invocable true|false] [--disable-model-invocation true|false]`. 4. For a human, application, skill, or harness request, require an exact discovered name and its channel-specific allowlist. 5. For a skill caller, also require caller identity, a non-cyclic target, and a bounded composition depth. 6. For a model or autonomous agent request, remove candidates that the actor or recognized host extensions make ineligible. 7. Score only the remaining descriptions. Select the strongest eligible match or abstain when no eligible candidate clears the threshold. 8. Return the JSON decision with the adapter, channel, score, and policy reason. Activation loads instructions. It does not approve tools, filesystem changes, network access, secret use, or bundled scripts.