Skip to content
docsv0.1.0

AgentOrchestrator

Agentic tool-use loop: alternates between asking an {@see LlmService} for the next step and executing any tool calls it requests via {@see McpClientService}, until the LLM returns a final response or {@see self::$maxSteps} is reached.

AgentOrchestrator::__construct()

public function __construct(Milpa\AiGateway\LlmService $llm, Milpa\AiGateway\McpClientService $mcpClient, int $maxSteps = 20, ?Psr\Log\LoggerInterface $logger = null, ?Milpa\ToolRuntime\Rendering\RendererRegistry $rendererRegistry = null):

Parameters

Parameters of __construct()
NameTypeDescription
$llmMilpa\AiGateway\LlmService
$mcpClientMilpa\AiGateway\McpClientService
$maxStepsint
$logger?Psr\Log\LoggerInterface
$rendererRegistry?Milpa\ToolRuntime\Rendering\RendererRegistry

AgentOrchestrator::getLastToolResult()

public function getLastToolResult(): ?Milpa\ToolRuntime\ToolResult

Get the last ToolResult from tool execution. Used by ProcessTelegramMessageJob to build keyboard from metadata.

AgentOrchestrator::setToolContext()

public function setToolContext(Milpa\ToolRuntime\Contracts\ToolContext $ctx): self

Set the tool context for channel-specific rendering.

Parameters

Parameters of setToolContext()
NameTypeDescription
$ctxMilpa\ToolRuntime\Contracts\ToolContext

AgentOrchestrator::run()

public function run(string $prompt, string $systemPrompt = 'You are a helpful assistant.', array $history = [], ?callable $onStep = null): string

Run the agent orchestrator loop.

Parameters

Parameters of run()
NameTypeDescription
$promptstringUser prompt
$systemPromptstringSystem instructions
$historylist<array<string, mixed>>Conversation history
$onStep(callable | null)Optional callback called at each step: fn(int $step, string $status) => void