You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$state = AgentState::empty()->withUserMessage('What is the weather in Paris?');
72
72
$result = $loop->execute($state);
73
73
// LLM calls the weather tool, gets result, then responds
74
-
// @doctest id="312b"
74
+
// @doctest id="2fc8"
75
75
```
76
76
77
77
## Tool Contracts
@@ -88,7 +88,7 @@ interface ToolInterface {
88
88
public function toToolSchema(): array; // JSON schema sent to LLM
89
89
public function descriptor(): CanDescribeTool; // metadata accessor
90
90
}
91
-
// @doctest id="c50f"
91
+
// @doctest id="4199"
92
92
```
93
93
94
94
### CanDescribeTool
@@ -102,7 +102,7 @@ interface CanDescribeTool {
102
102
public function metadata(): array; // summary for browsing/discovery
103
103
public function instructions(): array; // full specification with parameters
104
104
}
105
-
// @doctest id="e9f3"
105
+
// @doctest id="8ba5"
106
106
```
107
107
108
108
`metadata()` returns lightweight info (name, summary, namespace) for tool listings. `instructions()` returns the complete specification including parameters and return type.
@@ -127,7 +127,7 @@ class WeatherTool extends BaseTool
127
127
return "Weather in {$city}: 72F, sunny";
128
128
}
129
129
}
130
-
// @doctest id="cab2"
130
+
// @doctest id="87d2"
131
131
```
132
132
133
133
See [Building Tools](06-building-tools.md) for the full guide on creating custom tools.
@@ -59,7 +59,7 @@ class StatefulTool extends BaseTool
59
59
return "Step {$stepCount}: processing {$input}";
60
60
}
61
61
}
62
-
// @doctest id="ac6c"
62
+
// @doctest id="19e9"
63
63
```
64
64
65
65
## The ToolInterface
@@ -73,7 +73,7 @@ interface ToolInterface
73
73
public function toToolSchema(): array;
74
74
public function descriptor(): CanDescribeTool;
75
75
}
76
-
// @doctest id="4311"
76
+
// @doctest id="8adb"
77
77
```
78
78
79
79
-`use()` - execute the tool, returns `Result` (success or failure)
@@ -116,7 +116,7 @@ final readonly class MyToolDescriptor extends ToolDescriptor
116
116
);
117
117
}
118
118
}
119
-
// @doctest id="3d12"
119
+
// @doctest id="20b5"
120
120
```
121
121
122
122
Then wire it into your tool:
@@ -144,7 +144,7 @@ class MyTool extends BaseTool
144
144
return "Processed: {$input}";
145
145
}
146
146
}
147
-
// @doctest id="c262"
147
+
// @doctest id="eab4"
148
148
```
149
149
150
150
Most built-in tools use this pattern — `BashTool` has `BashToolDescriptor`, each file tool has its own descriptor, and so on. The `metadata()` and `instructions()` arrays power progressive disclosure: tool registries can show lightweight summaries via `metadata()`, while the LLM receives full specifications via `instructions()` when needed.
0 commit comments