main: 增强工具调用与消息流程
- 支持 tool.call 和 tool.result 消息类型处理 - 引入 Tool 调度与执行逻辑,支持超时与结果截断 - 增加 ToolRegistry 和 ToolExecutor 管理工具定义与执行 - 更新上下文构建与消息映射逻辑,适配工具闭环处理 - 扩展配置与环境变量,支持 Tool 调用相关选项 - 增强单元测试覆盖工具调用与执行情景 - 更新文档和 OpenAPI,新增工具相关说明与模型定义
This commit is contained in:
39
app/Services/Tool/ToolRunDispatcher.php
Normal file
39
app/Services/Tool/ToolRunDispatcher.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Tool;
|
||||
|
||||
use App\Jobs\ToolRunJob;
|
||||
use App\Services\OutputSink;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 子 Run 调度:为单个 tool_call 创建 Run 并投递队列,幂等。
|
||||
*/
|
||||
class ToolRunDispatcher
|
||||
{
|
||||
public function __construct(private readonly OutputSink $outputSink)
|
||||
{
|
||||
}
|
||||
|
||||
public function dispatch(string $sessionId, ToolCall $toolCall): string
|
||||
{
|
||||
$shouldDispatch = false;
|
||||
|
||||
DB::transaction(function () use ($sessionId, $toolCall, &$shouldDispatch): void {
|
||||
$wasDeduped = null;
|
||||
$this->outputSink->appendRunStatus($sessionId, $toolCall->runId, 'RUNNING', [
|
||||
'parent_run_id' => $toolCall->parentRunId,
|
||||
'tool_call_id' => $toolCall->toolCallId,
|
||||
'dedupe_key' => "run:{$toolCall->runId}:status:RUNNING",
|
||||
], $wasDeduped);
|
||||
|
||||
$shouldDispatch = ! $wasDeduped;
|
||||
});
|
||||
|
||||
if ($shouldDispatch) {
|
||||
ToolRunJob::dispatchSync($sessionId, $toolCall->toArray());
|
||||
}
|
||||
|
||||
return $toolCall->runId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user