Skip to content
docsv0.2.0

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

Parameters of __construct()
NameTypeDescription
$successboolWhether the operation succeeded
$datamixedResponse data
$message(string | null)Success message
$error(string | null)Error reason
$metaarray<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): self

Create from an existing ToolResult with added intelligence.

Parameters

Parameters of fromToolResult()
NameTypeDescription
$resultToolResultOriginal result
$intelligenceToolIntelligenceIntelligence to add
$actionstringTool/action name
$attemptstringHuman-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 = []): self

Create a success result with intelligence.

Parameters

Parameters of successWithIntelligence()
NameTypeDescription
$datamixedResponse data
$intelligenceToolIntelligenceIntelligence layer
$actionstringTool/action name
$attemptstringHuman-readable attempt description
$message(string | null)Success message
$metaarray<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 = []): self

Create an error result with intelligence (suggestions for recovery).

Parameters

Parameters of errorWithIntelligence()
NameTypeDescription
$errorstringError reason
$intelligenceToolIntelligenceIntelligence with suggestions
$actionstringTool/action name
$attemptstringHuman-readable attempt description
$datamixedOptional data (e.g., partial results)
$metaarray<string, mixed>Additional metadata

IntelligentToolResult::blockedWithIntelligence()

public static function blockedWithIntelligence(string $reason, Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence, string $action, string $attempt): self

Create a blocked result with alternative suggestions.

Parameters

Parameters of blockedWithIntelligence()
NameTypeDescription
$reasonstringBlock reason
$intelligenceToolIntelligenceIntelligence with alternatives
$actionstringTool/action name
$attemptstringHuman-readable attempt description

IntelligentToolResult::getIntelligence()

public function getIntelligence(): ?Milpa\ToolRuntime\Contracts\ToolIntelligence

Get the intelligence layer.

IntelligentToolResult::hasIntelligence()

public function hasIntelligence(): bool

Check if this result has intelligence.

IntelligentToolResult::getAction()

public function getAction(): ?string

Get the action name.

IntelligentToolResult::getAttempt()

public function getAttempt(): ?string

Get the attempt description.

IntelligentToolResult::getSuggestions()

public function getSuggestions(): array

Get suggestions from intelligence.

IntelligentToolResult::getWarnings()

public function getWarnings(): array

Get warnings from intelligence.

IntelligentToolResult::getNextActions()

public function getNextActions(): array

Get next actions from intelligence.

IntelligentToolResult::withIntelligence()

public function withIntelligence(Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence): self

Add intelligence to this result (creates new instance).

Parameters

Parameters of withIntelligence()
NameTypeDescription
$intelligenceMilpa\ToolRuntime\Contracts\ToolIntelligence

IntelligentToolResult::mergeIntelligence()

public function mergeIntelligence(Milpa\ToolRuntime\Contracts\ToolIntelligence $intelligence): self

Merge additional intelligence into existing (creates new instance).

Parameters

Parameters of mergeIntelligence()
NameTypeDescription
$intelligenceMilpa\ToolRuntime\Contracts\ToolIntelligence

IntelligentToolResult::jsonSerialize()

public function jsonSerialize(): array

Serialize to ITP format.

IntelligentToolResult::toStandardFormat()

public function toStandardFormat(): array

Convert to standard ToolResult format (without ITP wrapper). Useful for backwards compatibility with code expecting ToolResult format.

IntelligentToolResult::toCompactFormat()

public function toCompactFormat(): array

Convert to compact format (minimal response).