main: 扩展 Agent Run 调度与队列功能
- 增加 Agent Run MVP-0,包括 RunDispatcher 和 AgentRunJob - 优化队列配置,支持 Redis 队列驱动,添加 Horizon 容器 - 更新 Docker 配置,细化角色分工,新增 Horizon 配置 - 增加测试任务 `TestJob`,扩展队列使用示例 - 更新 OpenAPI 规范,添加 Agent Run 相关接口及示例 - 编写文档,详细描述 Agent Run 流程与 MVP-0 功能 - 优化相关服务与文档,支持队列与异步运行
This commit is contained in:
12
app/Services/Agent/AgentProviderInterface.php
Normal file
12
app/Services/Agent/AgentProviderInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Agent;
|
||||
|
||||
interface AgentProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $context
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function generate(array $context, array $options = []): string;
|
||||
}
|
||||
26
app/Services/Agent/DummyAgentProvider.php
Normal file
26
app/Services/Agent/DummyAgentProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Agent;
|
||||
|
||||
class DummyAgentProvider implements AgentProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $context
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function generate(array $context, array $options = []): string
|
||||
{
|
||||
$messages = $context['messages'] ?? [];
|
||||
$lastUser = null;
|
||||
foreach (array_reverse($messages) as $msg) {
|
||||
if (($msg['role'] ?? '') === 'USER' && ($msg['type'] ?? '') === 'user.prompt') {
|
||||
$lastUser = $msg['content'] ?? null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$summary = $lastUser ? mb_substr($lastUser, 0, 80) : 'no user prompt';
|
||||
|
||||
return sprintf('MVP reply: based on last user input -> %s', $summary);
|
||||
}
|
||||
}
|
||||
42
app/Services/Agent/HttpAgentProvider.php
Normal file
42
app/Services/Agent/HttpAgentProvider.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Agent;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class HttpAgentProvider implements AgentProviderInterface
|
||||
{
|
||||
protected string $endpoint;
|
||||
|
||||
public function __construct(?string $endpoint = null)
|
||||
{
|
||||
$this->endpoint = $endpoint ?? config('services.agent_provider.endpoint', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $context
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function generate(array $context, array $options = []): string
|
||||
{
|
||||
if (empty($this->endpoint)) {
|
||||
// placeholder to avoid accidental outbound calls when未配置
|
||||
return (new DummyAgentProvider())->generate($context, $options);
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'context' => $context,
|
||||
'options' => $options,
|
||||
];
|
||||
|
||||
$response = Http::post($this->endpoint, $payload);
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw new \RuntimeException('Agent provider failed: '.$response->body());
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
return is_string($data) ? $data : ($data['content'] ?? '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user