truthanb/laravel-ai-skills 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

truthanb/laravel-ai-skills

最新稳定版本:v0.6.0

Composer 安装命令:

composer require truthanb/laravel-ai-skills

包简介

Agent Skills (agentskills.io) support for Laravel AI

README 文档

README

Agent Skills (agentskills.io) support for Laravel AI. Load, register, and wire skill-based instructions and tools into your AI agents.

Installation

composer require truthanb/laravel-ai-skills

Compatibility

This package supports stable laravel/ai releases from 0.2 through 0.6.

Quick Start

1. Create a Skill Directory

Create a skill directory with a SKILL.md file following the Agent Skills specification:

resources/skills/
└── customer-support/
    ├── SKILL.md
    ├── scripts/
    │   └── triage.sh
    └── references/
        └── TEMPLATES.md

The SKILL.md file uses YAML frontmatter:

---
name: customer-support
description: Handle customer support inquiries and ticket routing.
license: MIT
---

# Customer Support Skill

Use this skill when handling customer inquiries...

2. Use the HasSkills Trait

Add the HasSkills trait to your agent and call skillPrompt() in your instructions and skillTools() in your tools:

<?php

namespace App\Agents;

use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Promptable;
use Truthanb\LaravelAiSkills\HasSkills;

class SupportAgent implements Agent, HasTools
{
    use HasSkills, Promptable;

    public function instructions(): string
    {
        return 'You are a helpful support assistant.'.$this->skillPrompt();
    }

    public function tools(): iterable
    {
        return [...$this->skillTools()];
    }
}

By default, skills are loaded from resources/skills/ — following Laravel conventions. You can publish the config to customize the path. The agent automatically gets:

  • Skill descriptions injected into its system prompt (via skillPrompt())
  • A skill activation tool to load full skill instructions on demand
  • A skill resource reader tool to read scripts, references, and assets from a skill

Configuration

Publish the config file to customize skill paths:

php artisan vendor:publish --tag=skills-config

This creates config/skills.php where you can set your paths:

return [
    'paths' => [
        resource_path('skills'),
    ],
];

Custom Skill Paths Per Agent

Override skillPaths() on a specific agent to load skills from different directories:

class SupportAgent implements Agent, HasTools
{
    use HasSkills, Promptable;

    public function instructions(): string
    {
        return 'You are a helpful assistant.'.$this->skillPrompt();
    }

    public function tools(): iterable
    {
        return [...$this->skillTools()];
    }

    protected function skillPaths(): array
    {
        return [
            resource_path('skills/support'),
            resource_path('skills/shared'),
        ];
    }
}

Direct Override (DB, S3, etc.)

For skills loaded from a database, S3, or any non-filesystem source, override skills() directly:

class DynamicAgent implements Agent, HasTools
{
    use HasSkills, Promptable;

    public function __construct(protected array $loadedSkills = []) {}

    public function instructions(): string
    {
        return 'You are a helpful assistant.'.$this->skillPrompt();
    }

    public function tools(): iterable
    {
        return [...$this->skillTools()];
    }

    public function skills(): array
    {
        return $this->loadedSkills;
    }
}

Manual Approach

If you prefer full control, manage the SkillRegistry and tools yourself:

use Truthanb\LaravelAiSkills\ActivateSkillTool;
use Truthanb\LaravelAiSkills\ReadSkillResourceTool;
use Truthanb\LaravelAiSkills\SkillRegistry;

class ManualAgent implements Agent, HasTools
{
    use Promptable;

    public function __construct(protected SkillRegistry $skills) {}

    public function instructions(): string
    {
        $instructions = 'You are a helpful assistant.';

        if ($this->skills->count() > 0) {
            $instructions .= "\n\n".$this->skills->toPrompt();
        }

        return $instructions;
    }

    public function tools(): iterable
    {
        return [
            new ActivateSkillTool($this->skills),
            new ReadSkillResourceTool($this->skills),
        ];
    }
}

Caching

Skills are automatically cached using Laravel's cache system (default TTL: 1 hour). If caching is unavailable, skills are loaded directly from the filesystem with a graceful fallback.

Override skillCacheTtl() to customize:

protected function skillCacheTtl(): int
{
    return 1800; // 30 minutes
}

Call clearSkillCache() to reset both in-memory and persistent caches:

$agent->clearSkillCache();

Specification

This package follows the Agent Skills specification. Each skill is a directory containing a SKILL.md file with YAML frontmatter and optional resource subdirectories (scripts/, references/, assets/).

License

MIT

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固