IntelligentToolResult
Extended ToolResult with Intelligence layer. Follows the Intelligent Tool Protocol (ITP) format: { "action": "create_note", "attempt": "Create note 'Design ideas'", "response": {...}, "success": true, "reason": null, "intelligence": { "suggestions": [...], "warnings": [...], "next_actions": [...], "context": {...}, "business_rules": {...} }, "meta": {...} }
IntelligentToolResult::__construct()
public function __construct(bool $success, ?mixed $data = null, ?string $message = null, ?string $error = null, array $meta = [], ?Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence = null, ?string $action = null, ?string $attempt = null):Parameters
| Name | Type | Description |
|---|---|---|
| $success | bool | Whether the operation succeeded |
| $data | mixed | Response data |
| $message | (string | null) | Success message |
| $error | (string | null) | Error reason |
| $meta | array<string, mixed> | Additional metadata |
| $intelligence | (ToolIntelligence | null) | Intelligence layer |
| $action | (string | null) | Tool/action name |
| $attempt | (string | null) | Human-readable description of what was attempted |
IntelligentToolResult::fromToolResult()
public static function fromToolResult(Milpa\ToolRuntime\ToolResult $result, Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence, string $action, string $attempt): selfCreate from an existing ToolResult with added intelligence.
Parameters
| Name | Type | Description |
|---|---|---|
| $result | ToolResult | Original result |
| $intelligence | ToolIntelligence | Intelligence to add |
| $action | string | Tool/action name |
| $attempt | string | Human-readable attempt description |
IntelligentToolResult::successWithIntelligence()
public static function successWithIntelligence(?mixed $data, Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence, string $action, string $attempt, ?string $message = null, array $meta = []): selfCreate a success result with intelligence.
Parameters
| Name | Type | Description |
|---|---|---|
| $data | mixed | Response data |
| $intelligence | ToolIntelligence | Intelligence layer |
| $action | string | Tool/action name |
| $attempt | string | Human-readable attempt description |
| $message | (string | null) | Success message |
| $meta | array<string, mixed> | Additional metadata |
IntelligentToolResult::errorWithIntelligence()
public static function errorWithIntelligence(string $error, Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence, string $action, string $attempt, ?mixed $data = null, array $meta = []): selfCreate an error result with intelligence (suggestions for recovery).
Parameters
| Name | Type | Description |
|---|---|---|
| $error | string | Error reason |
| $intelligence | ToolIntelligence | Intelligence with suggestions |
| $action | string | Tool/action name |
| $attempt | string | Human-readable attempt description |
| $data | mixed | Optional data (e.g., partial results) |
| $meta | array<string, mixed> | Additional metadata |
IntelligentToolResult::blockedWithIntelligence()
public static function blockedWithIntelligence(string $reason, Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence, string $action, string $attempt): selfCreate a blocked result with alternative suggestions.
Parameters
| Name | Type | Description |
|---|---|---|
| $reason | string | Block reason |
| $intelligence | ToolIntelligence | Intelligence with alternatives |
| $action | string | Tool/action name |
| $attempt | string | Human-readable attempt description |
IntelligentToolResult::getIntelligence()
public function getIntelligence(): ?Milpa\ToolRuntime\Contracts\ToolIntelligenceGet the intelligence layer.
IntelligentToolResult::hasIntelligence()
public function hasIntelligence(): boolCheck if this result has intelligence.
IntelligentToolResult::getAction()
public function getAction(): ?stringGet the action name.
IntelligentToolResult::getAttempt()
public function getAttempt(): ?stringGet the attempt description.
IntelligentToolResult::getSuggestions()
public function getSuggestions(): arrayGet suggestions from intelligence.
IntelligentToolResult::getWarnings()
public function getWarnings(): arrayGet warnings from intelligence.
IntelligentToolResult::getNextActions()
public function getNextActions(): arrayGet next actions from intelligence.
IntelligentToolResult::withIntelligence()
public function withIntelligence(Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence): selfAdd intelligence to this result (creates new instance).
Parameters
| Name | Type | Description |
|---|---|---|
| $intelligence | Milpa\ToolRuntime\Contracts\ToolIntelligence |
IntelligentToolResult::mergeIntelligence()
public function mergeIntelligence(Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence): selfMerge additional intelligence into existing (creates new instance).
Parameters
| Name | Type | Description |
|---|---|---|
| $intelligence | Milpa\ToolRuntime\Contracts\ToolIntelligence |
IntelligentToolResult::jsonSerialize()
public function jsonSerialize(): arraySerialize to ITP format.
IntelligentToolResult::toStandardFormat()
public function toStandardFormat(): arrayConvert to standard ToolResult format (without ITP wrapper). Useful for backwards compatibility with code expecting ToolResult format.
IntelligentToolResult::toCompactFormat()
public function toCompactFormat(): arrayConvert to compact format (minimal response).