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
| Name | Type | Description |
|---|---|---|
| $llm | Milpa\AiGateway\LlmService | |
| $mcpClient | Milpa\AiGateway\McpClientService | |
| $maxSteps | int | |
| $logger | ?Psr\Log\LoggerInterface | |
| $rendererRegistry | ?Milpa\ToolRuntime\Rendering\RendererRegistry |
AgentOrchestrator::getLastToolResult()
public function getLastToolResult(): ?Milpa\ToolRuntime\ToolResultGet the last ToolResult from tool execution. Used by ProcessTelegramMessageJob to build keyboard from metadata.
AgentOrchestrator::setToolContext()
public function setToolContext(Milpa\ToolRuntime\Contracts\ToolContext $ctx): selfSet the tool context for channel-specific rendering.
Parameters
| Name | Type | Description |
|---|---|---|
| $ctx | Milpa\ToolRuntime\Contracts\ToolContext |
AgentOrchestrator::run()
public function run(string $prompt, string $systemPrompt = 'You are a helpful assistant.', array $history = [], ?callable $onStep = null): stringRun the agent orchestrator loop.
Parameters
| Name | Type | Description |
|---|---|---|
| $prompt | string | User prompt |
| $systemPrompt | string | System instructions |
| $history | list<array<string, mixed>> | Conversation history |
| $onStep | (callable | null) | Optional callback called at each step: fn(int $step, string $status) => void |