본문으로 건너뛰기

Neuron 플래너 / 실행기

Queuety 워크플로 하나가 전문화된 추론 한 번을 수행합니다. 부모 워크플로는 작업을 계획하고 자식 워크플로를 시작한 뒤 내구성 있게 저장된 결과를 기다립니다. Neuron는 두 번째 에이전트 루프를 실행하지 않고 프로바이더 어댑터를 제공합니다. 이 예제는 고정된 통합 계약을 사용합니다.

제한된 HTTP 클라이언트를 사용하는 프로바이더

PHP
namespace App\Neuron;

use NeuronAI\Agent\SystemPrompt;
use NeuronAI\HttpClient\Curl\CurlHttpClient;
use NeuronAI\HttpClient\HttpClientInterface;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\Providers\Gemini\Gemini;
use NeuronAI\Providers\OpenAI\Responses\OpenAIResponses;
use Queuety\ExecutionContext;

final class ProviderFactory
{
    public static function make(
        string $name,
        string $key,
        string $model,
        ?HttpClientInterface $http = null,
    ): AIProviderInterface {
        $remaining = ExecutionContext::remaining_seconds() ?? 20.0;
        $timeout = min(12.0, $remaining - 2.0);
        if ($timeout <= 0.0) {
            throw new \RuntimeException('No provider budget remains.');
        }
        $http ??= new CurlHttpClient(
            timeout: $timeout,
            connectTimeout: min(2.0, $timeout),
        );
        $provider = match ($name) {
            'anthropic' => new Anthropic($key, $model, httpClient: $http),
            'gemini' => new Gemini($key, $model, httpClient: $http),
            'openai' => new OpenAIResponses($key, $model, httpClient: $http),
            default => throw new \InvalidArgumentException('Unknown provider.'),
        };
        return $provider->systemPrompt((string) new SystemPrompt(
            background: ['Return a concise summary of the assigned topic.'],
        ));
    }
}

각 작업마다 새로운 프로바이더를 만드세요. 프로덕션 환경에서는 주입된 클라이언트가 동일한 잔여 예산을 적용해야 합니다. 도구를 요청하는 응답은 저장한 뒤 Queuety의 다음 작업으로 넘겨야 합니다. 프로바이더 어댑터는 도구를 실행하지 않습니다.

추론 단계 하나

PHP
namespace App\Workflow\Steps;

use App\Ai\Credentials;
use App\Neuron\ProviderFactory;
use NeuronAI\Chat\Messages\ToolCallMessage;
use NeuronAI\Chat\Messages\UserMessage;
use Queuety\ExecutionContext;
use Queuety\Step;

final class ResearchTopicStep implements Step
{
    public function handle(array $state): array
    {
        $credential = Credentials::forRun($state['credential_reference']);
        $provider = ProviderFactory::make(
            $credential->provider,
            $credential->key,
            $credential->model,
        );
        ExecutionContext::assert_active();
        $response = $provider->chat(new UserMessage(
            sprintf('Research %s for brief %d.', $state['topic'], $state['brief_id'])
        ));
        ExecutionContext::assert_active();
        $message = $response->message();
        if ($message instanceof ToolCallMessage) {
            throw new \RuntimeException('This text-only step does not accept tools.');
        }
        return ['summary' => $message->getContent()];
    }

    public function config(): array
    {
        return ['max_attempts' => 1];
    }
}

한 번만 시도하면 결과가 불확실한 유료 요청을 조용히 다시 보내는 일을 피할 수 있습니다. 애플리케이션은 요청 기록을 조정한 뒤 명시적으로 재시도할 수 있습니다. 호출 전후에 클레임을 검증해 내구성 있는 결과를 보호하지만, 이미 전송된 프로바이더 요청을 취소할 수는 없습니다.

독립적인 전문 워크플로 디스패치

PHP
use Queuety\Enums\WaitMode;
use Queuety\Queuety;

$specialist = Queuety::workflow('research_agent_run')
    ->then(ResearchTopicStep::class);

Queuety::workflow('brief_research')
    ->version('brief-research.v2')
    ->then(PlanResearchTasksStep::class)
    ->start_agents('agent_tasks', $specialist)
    ->wait_for_agents(mode: WaitMode::All, result_key: 'agent_results')
    ->then(SynthesizeBriefStep::class)
    ->dispatch([
        'brief_id' => 42,
        'credential_reference' => 'research-service',
    ]);

PlanResearchTasksStep는 agent_tasks을 제공합니다. 예를 들면 [['topic' => 'pricing'], ['topic' => 'customer reviews']]입니다. 각 작업은 독립적으로 검사할 수 있는 워크플로가 됩니다. 부모는 agent_results 아래에 완료된 자식 상태를 가지고 재개합니다. 계획 및 종합 클래스는 애플리케이션 단계이며, 그 안의 모든 모델 호출에도 동일한 단일 요청 규칙이 적용됩니다.

에이전트 오케스트레이션과 비동기 핸드오프를 참조하세요.