<< All versions
Skill v1.0.0
currentTrusted Publisher100/100microsoft/pilotswarm/add-tool
──Details
PublishedOctober 9, 2026 at 09:39 AM
Content Hashsha256:992e9faf2be7d1e1...
Git SHA
──Files
Files (1 file, 2.9 KB)
SKILL.md2.9 KBactive
SKILL.md · 78 lines · 2.9 KB
version: "1.0.0" name: add-tool description: Add a new tool to PilotSwarm. Covers defining the tool with defineTool(), registering it on the worker (worker-level or per-session), referencing it from the client via toolNames, and adding an integration test.
Add a New Tool
Tools are defined using defineTool() from @github/copilot-sdk and registered on the worker.
Steps
- Define the tool using
defineTool(name, { description, parameters, handler }).
namemust be a unique string identifier (snake_case).descriptionshould clearly explain when the LLM should use it.parametersuses JSON Schema format withtype: "object",properties, andrequired.handleris an async function that receives the validated arguments and returns a result.
- Register on the worker — two patterns:
- Worker-level (recommended): Call
worker.registerTools([myTool])before or afterworker.start(). Clients reference it viatoolNames: ["my_tool"]. - Per-session: Call
worker.setSessionConfig(sessionId, { tools: [myTool] })after creating the session. Only works in same-process mode.
- Add a test in
test/sdk.test.js:
- Create a test function following the existing pattern (e.g.,
testToolCalling). - Track whether the tool handler was called with a boolean flag.
- Assert the LLM's response reflects the tool's output.
- Add the test to the
testsarray at the bottom.
Example
typescript
import { defineTool } from "pilotswarm";const myTool = defineTool("lookup_price", {description: "Look up the current price of a product by name",parameters: {type: "object",properties: {product: { type: "string", description: "Product name" },},required: ["product"],},handler: async ({ product }) => {const price = await fetchPrice(product);return { product, price };},});// Worker-level registrationworker.registerTools([myTool]);// Client references by nameconst session = await client.createSession({toolNames: ["lookup_price"],systemMessage: "You can look up product prices.",});
How tools flow to the Copilot SDK
worker.registerTools() → Map<string, Tool>↓SessionManager.getOrCreate() resolves toolNames → Tool[]↓ManagedSession.runTurn() merges user tools + system tools (wait, ask_user)↓copilotSession.registerTools(allTools) ← Copilot SDK method↓copilotSession.send({ prompt }) ← LLM sees registered tools
Key files
- src/managed-session.ts — where tools are merged and registered on
CopilotSession - src/session-manager.ts — where
toolNamesare resolved from the worker registry - src/worker.ts — where
registerTools()stores tools in the registry - test/sdk.test.js — integration tests