The Open Framework for Building Agents
fix(skills): qualify single-entry dynamic skill maps as slug__key (#143)
Casey Gowrie2197c14b13de
diff --git a/.changeset/dynamic-skill-single-entry-map-naming.md b/.changeset/dynamic-skill-single-entry-map-naming.mdnew file mode 100644index 000000000..74bb5e214--- /dev/null+++ b/.changeset/dynamic-skill-single-entry-map-naming.md@@ -0,0 +1,7 @@+---+"eve": patch+---++Dynamic skill resolvers that return a map now name every entry `<slug>__<key>` even when the map holds a single entry, matching dynamic tools and the documented contract. Previously a one-entry map was advertised and materialized under the bare resolver slug, so `load_skill` failed to find it and adding a second skill silently renamed the first. `load_skill` failures now also list the available skill names so the model can correct a wrong id.++Adds a `t.loadedSkill(skill, opts?)` eval assertion — sugar for `t.calledTool("load_skill", { input: { skill }, ... })`.diff --git a/docs/evals/assertions.mdx b/docs/evals/assertions.mdxindex 952089887..51835237d 100644--- a/docs/evals/assertions.mdx+++ b/docs/evals/assertions.mdx@@ -17,6 +17,7 @@ Run-level assertions read the whole run, so they take no value. They are methods| `t.messageIncludes(token)` | Joined assistant text contains `token` (string or RegExp) || `t.outputEquals(value)` / `t.outputMatches(schema)` | Deep equality or Standard Schema (e.g. Zod) validation of the agent's structured output || `t.calledTool(name, opts?)` | A matching tool call happened (`input`, `output`, `isError`, `times` constraints) |+| `t.loadedSkill(skill, opts?)` | Sugar for `t.calledTool("load_skill", { input: { skill }, ...opts })` || `t.notCalledTool(name)` | No call to `name` || `t.toolOrder([...names])` | Tool names appear in order (other calls may interleave) || `t.usedNoTools()` | No tool calls at all |diff --git a/docs/guides/dynamic-capabilities.md b/docs/guides/dynamic-capabilities.mdindex c85013ddf..9f59eabc2 100644--- a/docs/guides/dynamic-capabilities.md+++ b/docs/guides/dynamic-capabilities.md@@ -116,6 +116,8 @@ export default defineDynamic({The caller's team gets its own playbook advertised as a loadable skill; everyone else gets nothing.+Skills follow the same naming rule as tools: a single `defineSkill(...)` is named after the file slug, while a map return names each entry `slug__key` — even when the map holds one entry, so adding a second skill later never renames the first.+## Dynamic instructionsA dynamic instructions file resolves the per-session system prompt the same way, returning `defineInstructions(...)` built from the principal, tenant, or external data:diff --git a/e2e/fixtures/agent-skills/agent/skills/dynamic-single-map.ts b/e2e/fixtures/agent-skills/agent/skills/dynamic-single-map.tsnew file mode 100644index 000000000..64030bd82--- /dev/null+++ b/e2e/fixtures/agent-skills/agent/skills/dynamic-single-map.ts@@ -0,0 +1,26 @@+import { defineDynamic, defineSkill } from "eve/skills";++export const DYNAMIC_SINGLE_MAP_TOKEN = "dynamic-single-map-solo-X3R8";++// A map with exactly one entry: its id must still qualify as+// `dynamic-single-map__solo`, never collapse to the bare resolver slug.+export default defineDynamic({+ events: {+ "session.started": async () => {+ return {+ solo: defineSkill({+ description:+ "Smoke-test fixture: the sole skill from a single-entry map resolver. " ++ 'Only load when the user explicitly asks for "dynamic single map solo".',+ markdown: [+ "# Solo Skill",+ "",+ "When this skill is loaded, reply with exactly:",+ "",+ DYNAMIC_SINGLE_MAP_TOKEN,+ ].join("\n"),+ }),+ };+ },+ },+});diff --git a/e2e/fixtures/agent-skills/evals/skills/dynamic-single-map.eval.ts b/e2e/fixtures/agent-skills/evals/skills/dynamic-single-map.eval.tsnew file mode 100644index 000000000..c3d24c68c--- /dev/null+++ b/e2e/fixtures/agent-skills/evals/skills/dynamic-single-map.eval.ts@@ -0,0 +1,27 @@+import { defineEval } from "eve/evals";++const DYNAMIC_SINGLE_MAP_TOKEN = "dynamic-single-map-solo-X3R8";++/**+ * Skill smoke eval (regression):+ * a `defineDynamic` resolver returning a single-entry map+ * (skills/dynamic-single-map.ts) must expose that entry under its qualified id+ * `dynamic-single-map__solo` — not the bare resolver slug. Asserting the loaded+ * skill id is exactly the qualified name guards the single-entry-map naming fix.+ */+export default defineEval({+ description: "Skills smoke: single-entry dynamic skill-map qualifies as slug__key.",+ async test(t) {+ const turn = await t.send(+ "Please use the dynamic single map solo skill and follow its instructions exactly.",+ );+ turn.expectOk();++ t.didNotFail();+ t.completed();+ t.loadedSkill("dynamic-single-map__solo", {+ output: new RegExp(DYNAMIC_SINGLE_MAP_TOKEN, "u"),+ });+ t.messageIncludes(DYNAMIC_SINGLE_MAP_TOKEN);+ },+});diff --git a/e2e/fixtures/agent-skills/evals/skills/dynamic-skill-map.eval.ts b/e2e/fixtures/agent-skills/evals/skills/dynamic-skill-map.eval.tsindex 60e4b89fe..b8e360a29 100644--- a/e2e/fixtures/agent-skills/evals/skills/dynamic-skill-map.eval.ts+++ b/e2e/fixtures/agent-skills/evals/skills/dynamic-skill-map.eval.ts@@ -18,8 +18,7 @@ export default defineEval({t.didNotFail();t.completed();- t.calledTool("load_skill", {- input: { skill: "dynamic-multi__alpha" },+ t.loadedSkill("dynamic-multi__alpha", {output: new RegExp(DYNAMIC_MULTI_ALPHA_TOKEN, "u"),});t.messageIncludes(DYNAMIC_MULTI_ALPHA_TOKEN);diff --git a/e2e/fixtures/agent-skills/evals/skills/dynamic-skill.eval.ts b/e2e/fixtures/agent-skills/evals/skills/dynamic-skill.eval.tsindex 28eeac8e6..09aad628d 100644--- a/e2e/fixtures/agent-skills/evals/skills/dynamic-skill.eval.ts+++ b/e2e/fixtures/agent-skills/evals/skills/dynamic-skill.eval.ts@@ -18,8 +18,7 @@ export default defineEval({t.didNotFail();t.completed();- t.calledTool("load_skill", {- input: { skill: "dynamic-tenant-policy" },+ t.loadedSkill("dynamic-tenant-policy", {output: new RegExp(DYNAMIC_SKILL_TOKEN, "u"),});t.messageIncludes(DYNAMIC_SKILL_TOKEN);diff --git a/packages/eve/src/context/dynamic-skill-lifecycle.test.ts b/packages/eve/src/context/dynamic-skill-lifecycle.test.tsindex 2b23e2b55..9f800fb2b 100644--- a/packages/eve/src/context/dynamic-skill-lifecycle.test.ts+++ b/packages/eve/src/context/dynamic-skill-lifecycle.test.ts@@ -132,6 +132,47 @@ describe("dispatchDynamicSkillEvent", () => {expect(announcement).toContain("support: Support policy");});+ it("qualifies a single-entry map as slug__key (never collapses to the bare slug)", async () => {+ const { ctx, sandbox } = createCtx();+ const resolver = createResolver("custom", () => ({+ "talk-like-a-dog": makeSkill("Talk like a dog", "Woof."),+ }));++ await dispatchDynamicSkillEvent({+ ctx,+ event: makeEvent(),+ messages: [],+ resolvers: [resolver],+ });++ expect(ctx.get(DynamicSkillManifestKey)).toEqual({+ custom: [{ description: "Talk like a dog", name: "custom__talk-like-a-dog" }],+ });+ expect(ctx.get(PendingSkillAnnouncementKey)).toContain(+ "custom__talk-like-a-dog: Talk like a dog",+ );+ expect(sandbox.writes.some((w) => w.path.includes("/skills/custom__talk-like-a-dog/"))).toBe(+ true,+ );+ });++ it("collapses a directly-returned single defineSkill to the bare slug", async () => {+ const { ctx, sandbox } = createCtx();+ const resolver = createResolver("tenant", () => makeSkill("Tenant policy"));++ await dispatchDynamicSkillEvent({+ ctx,+ event: makeEvent(),+ messages: [],+ resolvers: [resolver],+ });++ expect(ctx.get(DynamicSkillManifestKey)).toEqual({+ tenant: [{ description: "Tenant policy", name: "tenant" }],+ });+ expect(sandbox.writes.some((w) => w.path.includes("/skills/tenant/"))).toBe(true);+ });+it("rejects duplicate names produced by dynamic skill resolvers before writing", async () => {const { ctx, sandbox } = createCtx();const single = createResolver("foo__bar", () => makeSkill("Single"));diff --git a/packages/eve/src/context/dynamic-skill-lifecycle.ts b/packages/eve/src/context/dynamic-skill-lifecycle.tsindex ceb5e0ec8..f90f319da 100644--- a/packages/eve/src/context/dynamic-skill-lifecycle.ts+++ b/packages/eve/src/context/dynamic-skill-lifecycle.ts@@ -40,7 +40,8 @@ function qualifyDynamicSkillNames(if (keys.length === 0) return result;- if (isSingle || keys.length === 1) {+ // A single-entry map still qualifies as `slug__key`; only isSingle collapses.+ if (isSingle) {result.push({ name: slug, entryKey: keys[0]!, entry: entries[keys[0]!]! });return result;}diff --git a/packages/eve/src/evals/assertions/run.test.ts b/packages/eve/src/evals/assertions/run.test.tsindex 588744257..92bd8f94f 100644--- a/packages/eve/src/evals/assertions/run.test.ts+++ b/packages/eve/src/evals/assertions/run.test.ts@@ -60,6 +60,20 @@ describe("run assertions", () => {expect((await Run.calledTool("missing").evaluate(result)).score).toBe(0);});+ it("loadedSkill matches a load_skill call by skill id", async () => {+ const result = makeResult({+ derived: {+ toolCalls: [toolCall("load_skill", { skill: "custom__talk-like-a-dog" })],+ toolCallCount: 1,+ },+ });+ expect((await Run.loadedSkill("custom__talk-like-a-dog").evaluate(result)).score).toBe(1);+ expect((await Run.loadedSkill("talk-like-a-dog").evaluate(result)).score).toBe(0);+ expect(Run.loadedSkill("custom__talk-like-a-dog").name).toBe(+ "loadedSkill(custom__talk-like-a-dog)",+ );+ });+it("usedNoTools passes only with zero tool calls", async () => {expect((await Run.usedNoTools().evaluate(makeResult({}))).score).toBe(1);expect(diff --git a/packages/eve/src/evals/assertions/run.ts b/packages/eve/src/evals/assertions/run.tsindex 718a86a80..7aeb63179 100644--- a/packages/eve/src/evals/assertions/run.ts+++ b/packages/eve/src/evals/assertions/run.ts@@ -5,9 +5,11 @@ import {subagentCallMatches,testRegExp,toolCallMatches,+ type EveEvalSkillLoadMatchOptions,type EveEvalSubagentCallMatchOptions,type EveEvalToolCallMatchOptions,} from "#evals/match.js";+import { LOAD_SKILL_TOOL_NAME } from "#runtime/skills/fragment-context.js";import type { AssertionOutcome, RunAssertion } from "#evals/assertions/collector.js";const PASS: AssertionOutcome = { score: 1 };@@ -124,6 +126,19 @@ export function calledTool(name: string, options: EveEvalToolCallMatchOptions =};}+/**+ * Sugar over {@link calledTool} for the framework `load_skill` tool: asserts a+ * skill with id `skill` was loaded. `output`/`isError`/`times` constrain the+ * matching call exactly as for `calledTool`.+ */+export function loadedSkill(+ skill: string,+ options: EveEvalSkillLoadMatchOptions = {},+): RunAssertion {+ const base = calledTool(LOAD_SKILL_TOOL_NAME, { ...options, input: { skill } });+ return { ...base, name: `loadedSkill(${skill})` };+}+/*** Asserts no tool call with `name` happened.*/diff --git a/packages/eve/src/evals/context.ts b/packages/eve/src/evals/context.tsindex cb08a3025..9d3d864fe 100644--- a/packages/eve/src/evals/context.ts+++ b/packages/eve/src/evals/context.ts@@ -79,6 +79,7 @@ export function createEvalContext(deps: {waiting: () => collector.recordRun(RunAssertions.waiting()),messageIncludes: (token) => collector.recordRun(RunAssertions.messageIncludes(token)),calledTool: (name, options) => collector.recordRun(RunAssertions.calledTool(name, options)),+ loadedSkill: (skill, options) => collector.recordRun(RunAssertions.loadedSkill(skill, options)),notCalledTool: (name) => collector.recordRun(RunAssertions.notCalledTool(name)),toolOrder: (names) => collector.recordRun(RunAssertions.toolOrder(names)),usedNoTools: () => collector.recordRun(RunAssertions.usedNoTools()),diff --git a/packages/eve/src/evals/index.ts b/packages/eve/src/evals/index.tsindex 28b118203..3ce66391b 100644--- a/packages/eve/src/evals/index.ts+++ b/packages/eve/src/evals/index.ts@@ -16,6 +16,7 @@ export type { InputRequest } from "#runtime/input/types.js";export type {EveEvalValueMatcher,EveEvalToolCallMatchOptions,+ EveEvalSkillLoadMatchOptions,EveEvalSubagentCallMatchOptions,} from "#evals/match.js";diff --git a/packages/eve/src/evals/match.ts b/packages/eve/src/evals/match.tsindex ed2891dbf..8ca72efd8 100644--- a/packages/eve/src/evals/match.ts+++ b/packages/eve/src/evals/match.ts@@ -33,6 +33,13 @@ export interface EveEvalToolCallMatchOptions {readonly times?: number;}+/**+ * Constraints applied to a `load_skill` call by `t.loadedSkill`. Identical to+ * {@link EveEvalToolCallMatchOptions} without `input`, which the helper fixes to+ * the loaded skill id.+ */+export type EveEvalSkillLoadMatchOptions = Omit<EveEvalToolCallMatchOptions, "input">;+/*** Constraints applied to subagent calls by `t.calledSubagent`.*/diff --git a/packages/eve/src/evals/types.ts b/packages/eve/src/evals/types.tsindex 749436711..d6919a1f4 100644--- a/packages/eve/src/evals/types.ts+++ b/packages/eve/src/evals/types.ts@@ -7,7 +7,11 @@ import type { InputRequest, InputResponse } from "#runtime/input/types.js";import type { JsonObject } from "#shared/json.js";import type { AgentModelOptionsDefinition } from "#shared/agent-definition.js";import type { EvalReporter } from "#evals/runner/reporters/types.js";-import type { EveEvalSubagentCallMatchOptions, EveEvalToolCallMatchOptions } from "#evals/match.js";+import type {+ EveEvalSkillLoadMatchOptions,+ EveEvalSubagentCallMatchOptions,+ EveEvalToolCallMatchOptions,+} from "#evals/match.js";/*** One tool call extracted from the captured stream, pairing the@@ -285,6 +289,8 @@ export interface EveEvalContext extends EveEvalSession {waiting(): AssertionHandle;messageIncludes(token: string | RegExp): AssertionHandle;calledTool(name: string, options?: EveEvalToolCallMatchOptions): AssertionHandle;+ /** Sugar for `calledTool("load_skill", { input: { skill }, ... })`. */+ loadedSkill(skill: string, options?: EveEvalSkillLoadMatchOptions): AssertionHandle;notCalledTool(name: string): AssertionHandle;toolOrder(names: readonly string[]): AssertionHandle;usedNoTools(): AssertionHandle;diff --git a/packages/eve/src/runtime/framework-tools/skill.test.ts b/packages/eve/src/runtime/framework-tools/skill.test.tsindex 56f1c10a2..7f461773b 100644--- a/packages/eve/src/runtime/framework-tools/skill.test.ts+++ b/packages/eve/src/runtime/framework-tools/skill.test.ts@@ -1,5 +1,8 @@import { describe, expect, it } from "vitest";+import { ContextContainer, contextStorage } from "#context/container.js";+import { DynamicSkillManifestKey, SandboxKey } from "#context/keys.js";+import { mockSandbox } from "#internal/testing/mocks/mock-sandbox.js";import { SKILL_TOOL_DEFINITION } from "#runtime/framework-tools/skill.js";describe("SKILL_TOOL_DEFINITION", () => {@@ -13,3 +16,23 @@ describe("SKILL_TOOL_DEFINITION", () => {expect(SKILL_TOOL_DEFINITION.description).toContain("Available skills block");});});++describe("load_skill executor", () => {+ it("surfaces dynamic skill names when the requested id is missing", async () => {+ const ctx = new ContextContainer();+ ctx.set(SandboxKey, mockSandbox().access);+ ctx.set(DynamicSkillManifestKey, {+ custom: [+ { description: "Talk like a dog", name: "custom__talk-like-a-dog" },+ { description: "Bark", name: "custom__bark" },+ ],+ });++ const execute = SKILL_TOOL_DEFINITION.execute;+ if (execute === undefined) throw new Error("load_skill tool is missing an execute function");++ await expect(+ contextStorage.run(ctx, () => execute({ skill: "talk-like-a-dog" })),+ ).rejects.toThrow("Available skills: custom__bark, custom__talk-like-a-dog.");+ });+});diff --git a/packages/eve/src/runtime/framework-tools/skill.ts b/packages/eve/src/runtime/framework-tools/skill.tsindex 6f8936c12..55bb92553 100644--- a/packages/eve/src/runtime/framework-tools/skill.ts+++ b/packages/eve/src/runtime/framework-tools/skill.ts@@ -1,5 +1,5 @@import { loadContext } from "#context/container.js";-import { SandboxKey } from "#context/keys.js";+import { DynamicSkillManifestKey, SandboxKey } from "#context/keys.js";import { loadSkillFromSandbox } from "#runtime/skills/sandbox-access.js";import type { ResolvedToolDefinition } from "#runtime/types.js";import type { JsonObject } from "#shared/json.js";@@ -29,7 +29,17 @@ async function executeLoadSkillTool(args: LoadSkillInput): Promise<unknown> {}const { skill } = args;- return await loadSkillFromSandbox(sandbox, skill);+ return await loadSkillFromSandbox(sandbox, skill, availableSkillNames(ctx));+}++// Dynamic skill names for load_skill's not-found hint. Dynamic-only on purpose:+// importing the bundle (for authored skills) would cycle through the+// framework-tools barrel.+function availableSkillNames(ctx: ReturnType<typeof loadContext>): string[] {+ const dynamic = Object.values(ctx.get(DynamicSkillManifestKey) ?? {})+ .flat()+ .map((s) => s.name);+ return [...new Set(dynamic)].sort();}// ---------------------------------------------------------------------------diff --git a/packages/eve/src/runtime/skills/sandbox-access.test.ts b/packages/eve/src/runtime/skills/sandbox-access.test.tsindex fb49621a3..d6909062c 100644--- a/packages/eve/src/runtime/skills/sandbox-access.test.ts+++ b/packages/eve/src/runtime/skills/sandbox-access.test.ts@@ -39,6 +39,17 @@ describe("loadSkillFromSandbox", () => {'No skill named "missing"',);});++ it("lists available skill names when the requested id is missing", async () => {+ const sandbox = mockSandbox();++ await expect(+ loadSkillFromSandbox(sandbox.access, "talk-like-a-dog", [+ "custom__talk-like-a-dog",+ "research",+ ]),+ ).rejects.toThrow("Available skills: custom__talk-like-a-dog, research.");+ });});describe("createSandboxSkillHandle", () => {diff --git a/packages/eve/src/runtime/skills/sandbox-access.ts b/packages/eve/src/runtime/skills/sandbox-access.tsindex a550ada16..07ae4fc4b 100644--- a/packages/eve/src/runtime/skills/sandbox-access.ts+++ b/packages/eve/src/runtime/skills/sandbox-access.ts@@ -31,16 +31,23 @@ export function assertSafeSkillId(id: string): asserts id is string {* Returns the SKILL.md body with any YAML frontmatter stripped, so the* model receives plain markdown as the tool result. Throws when the id* is unsafe or the file does not exist; the AI SDK forwards the error- * to the model as a tool-error result.+ * to the model as a tool-error result. `availableNames`, when given, is+ * listed in the not-found error so the model can correct a wrong id.*/-export async function loadSkillFromSandbox(access: SandboxAccess, id: string): Promise<string> {+export async function loadSkillFromSandbox(+ access: SandboxAccess,+ id: string,+ availableNames: readonly string[] = [],+): Promise<string> {assertSafeSkillId(id);const sandbox = await requireSandboxSession(access);const path = skillFilePath(id, "SKILL.md");const instructions = await sandbox.readTextFile({ path });if (instructions === null) {- throw new Error(`No skill named "${id}" at ${path}.`);+ const hint =+ availableNames.length > 0 ? ` Available skills: ${availableNames.join(", ")}.` : "";+ throw new Error(`No skill named "${id}" at ${path}.${hint}`);}return instructions.replace(FRONTMATTER_PATTERN, "");