main: 增强工具功能与消息处理

- 添加 `FileReadTool`,支持文件内容读取与安全验证
- 引入 `hasToolMessages` 逻辑,优化工具历史上下文处理
- 修改工具选项逻辑,支持禁用工具时的动态调整
- 增加消息序列化逻辑,优化 Redis 序列管理与数据同步
- 扩展测试覆盖,验证序列化与工具调用场景
- 增强 Docker Compose 脚本,支持应用重置与日志清理
- 调整工具调用超时设置,提升运行时用户体验
This commit is contained in:
2025-12-24 00:55:54 +08:00
parent 71226c255b
commit e956df9daa
24 changed files with 741 additions and 38 deletions

View File

@@ -106,6 +106,51 @@ class OpenAiAdapterTest extends TestCase
$this->assertSame('call_1', $toolResultMessage['tool_call_id']);
}
public function test_disable_tools_still_includes_definitions_when_history_has_tools(): void
{
$context = new AgentContext('run-1', 'session-1', 'system prompt', [
[
'message_id' => 'm1',
'role' => Message::ROLE_USER,
'type' => 'user.prompt',
'content' => 'call tool',
'payload' => [],
'seq' => 1,
],
[
'message_id' => 'm2',
'role' => Message::ROLE_AGENT,
'type' => 'tool.call',
'content' => null,
'payload' => [
'tool_call_id' => 'call_1',
'name' => 'get_time',
'arguments' => ['format' => 'c'],
],
'seq' => 2,
],
[
'message_id' => 'm3',
'role' => Message::ROLE_TOOL,
'type' => 'tool.result',
'content' => '2024-01-01',
'payload' => [
'tool_call_id' => 'call_1',
'name' => 'get_time',
'output' => '2024-01-01',
],
'seq' => 3,
],
]);
$payload = (new ChatCompletionsRequestBuilder(new ToolRegistry()))->build($context, [
'disable_tools' => true,
]);
$this->assertSame('none', $payload['tool_choice']);
$this->assertNotEmpty($payload['tools']);
}
public function test_event_normalizer_maps_delta_and_done(): void
{
$normalizer = new OpenAiEventNormalizer();