AgentSkillsCN

add-tool

为YuBot智能体运行时搭建全新的Pi SDK工具,配备TypeBox模式、实现代码与测试用例。

SKILL.md
--- frontmatter
name: add-tool
description: Scaffold a new Pi SDK tool for the YuBot agent runtime with TypeBox schema, implementation, and tests
invocation: user
user_invocation: /add-tool

Add Tool Skill

Scaffold a new tool for the YuBot agent runtime (Pi SDK).

Inputs

The user provides:

  • Tool name (snake_case, e.g., get_user_profile)
  • Description (what the tool does)
  • Parameters (name, type, description for each)
  • Return type (what the tool returns)

Generated Files

1. Tool Implementation

Create packages/agent-runtime/src/tools/{tool_name}.ts:

typescript
import { Type, Static } from '@sinclair/typebox';
import { Tool } from '../types';

export const {ToolName}Schema = Type.Object({
  // parameters from user input
});

export type {ToolName}Input = Static<typeof {ToolName}Schema>;

const {toolName}Tool: Tool = {
  name: '{tool_name}',
  description: '{description}',
  schema: {ToolName}Schema,
  async execute(input: {ToolName}Input, { db, abortSignal }) {
    // TODO: implement
    throw new Error('Not implemented');
  },
};

export default {toolName}Tool;

2. Test File

Create packages/agent-runtime/src/tools/{tool_name}.test.ts:

typescript
import { describe, it, expect, vi } from 'vitest';
import {toolName}Tool from './{tool_name}';

describe('{tool_name}', () => {
  it('should have correct name and schema', () => {
    expect({toolName}Tool.name).toBe('{tool_name}');
    expect({toolName}Tool.schema).toBeDefined();
  });

  it('should execute successfully with valid input', async () => {
    // TODO: mock db, test execution
  });

  it('should handle abort signal', async () => {
    // TODO: test cancellation
  });
});

3. Register in Tool Index

Add the tool to packages/agent-runtime/src/tools/index.ts:

typescript
import {toolName}Tool from './{tool_name}';
// ... add to tools array

After Scaffolding

  • Run bun --filter agent-runtime typecheck to verify types
  • Implement the execute function
  • Fill in test cases
  • Run bun --filter agent-runtime test to verify