- 支持 tool.call 和 tool.result 消息类型处理 - 引入 Tool 调度与执行逻辑,支持超时与结果截断 - 增加 ToolRegistry 和 ToolExecutor 管理工具定义与执行 - 更新上下文构建与消息映射逻辑,适配工具闭环处理 - 扩展配置与环境变量,支持 Tool 调用相关选项 - 增强单元测试覆盖工具调用与执行情景 - 更新文档和 OpenAPI,新增工具相关说明与模型定义
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Tool\Tools;
|
|
|
|
use App\Services\Tool\Tool;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class GetTimeTool implements Tool
|
|
{
|
|
public function name(): string
|
|
{
|
|
return 'get_time';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return '返回服务器当前时间,可指定 PHP 日期格式。';
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function parameters(): array
|
|
{
|
|
return [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'format' => [
|
|
'type' => 'string',
|
|
'description' => '可选的日期格式,默认为 RFC3339。',
|
|
],
|
|
],
|
|
'required' => [],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $arguments
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function execute(array $arguments): array
|
|
{
|
|
$format = is_string($arguments['format'] ?? null) && $arguments['format'] !== ''
|
|
? $arguments['format']
|
|
: Carbon::RFC3339_EXTENDED;
|
|
|
|
return [
|
|
'now' => Carbon::now()->format($format),
|
|
];
|
|
}
|
|
}
|