Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit de9e9fa

Browse files
committed
refactor: rename toolbox to lowercase
1 parent 7fa630b commit de9e9fa

File tree

68 files changed

+251
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+251
-249
lines changed

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,25 @@ To integrate LLMs with your application, LLM Chain supports [tool calling](https
138138
Tools are services that can be called by the LLM to provide additional features or process data.
139139

140140
Tool calling can be enabled by registering the processors in the chain:
141+
141142
```php
142-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
143-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
143+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
144+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
144145

145146
// Platform & LLM instantiation
146147

147148
$yourTool = new YourTool();
148149

149-
$toolBox = ToolBox::create($yourTool);
150-
$toolProcessor = new ChainProcessor($toolBox);
150+
$toolbox = Toolbox::create($yourTool);
151+
$toolProcessor = new ChainProcessor($toolbox);
151152

152153
$chain = new Chain($platform, $llm, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
153154
```
154155

155156
Custom tools can basically be any class, but must configure by the `#[AsTool]` attribute.
156157

157158
```php
158-
use PhpLlm\LlmChain\ToolBox\Attribute\AsTool;
159+
use PhpLlm\LlmChain\Toolbox\Attribute\AsTool;
159160

160161
#[AsTool('company_name', 'Provides the name of your company')]
161162
final class CompanyName
@@ -177,7 +178,7 @@ In the end, the tool's response needs to be a string, but LLM Chain converts arr
177178
You can configure the method to be called by the LLM with the `#[AsTool]` attribute and have multiple tools per class:
178179

179180
```php
180-
use PhpLlm\LlmChain\ToolBox\Attribute\AsTool;
181+
use PhpLlm\LlmChain\Toolbox\Attribute\AsTool;
181182

182183
#[AsTool(
183184
name: 'weather_current',
@@ -205,14 +206,15 @@ final readonly class OpenMeteo
205206

206207
#### Tool Parameters
207208

208-
LLM Chain generates a JSON Schema representation for all tools in the `ToolBox` based on the `#[AsTool]` attribute and
209+
LLM Chain generates a JSON Schema representation for all tools in the `Toolbox` based on the `#[AsTool]` attribute and
209210
method arguments and param comments in the doc block. Additionally, JSON Schema support validation rules, which are
210211
partially support by LLMs like GPT.
211212

212213
To leverage this, configure the `#[With]` attribute on the method arguments of your tool:
214+
213215
```php
214216
use PhpLlm\LlmChain\Chain\JsonSchema\Attribute\With;
215-
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
217+
use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool;
216218

217219
#[AsTool('my_tool', 'Example tool with parameters requirements.')]
218220
final class MyTool
@@ -240,17 +242,17 @@ See attribute class [With](src/Chain/JsonSchema/Attribute/With.php) for all avai
240242
#### Fault Tolerance
241243

242244
To gracefully handle errors that occur during tool calling, e.g. wrong tool names or runtime errors, you can use the
243-
`FaultTolerantToolBox` as a decorator for the `ToolBox`. It will catch the exceptions and return readable error messages
245+
`FaultTolerantToolbox` as a decorator for the `Toolbox`. It will catch the exceptions and return readable error messages
244246
to the LLM.
245247

246248
```php
247-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
248-
use PhpLlm\LlmChain\Chain\ToolBox\FaultTolerantToolBox;
249+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
250+
use PhpLlm\LlmChain\Chain\Toolbox\FaultTolerantToolbox;
249251

250-
// Platform, LLM & ToolBox instantiation
252+
// Platform, LLM & Toolbox instantiation
251253

252-
$toolBox = new FaultTolerantToolBox($innerToolBox);
253-
$toolProcessor = new ChainProcessor($toolBox);
254+
$toolbox = new FaultTolerantToolbox($innerToolbox);
255+
$toolProcessor = new ChainProcessor($toolbox);
254256

255257
$chain = new Chain($platform, $llm, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
256258
```
@@ -267,7 +269,7 @@ $this->chain->call($messages, ['tools' => ['tavily_search']]);
267269
#### Tool Result Interception
268270

269271
To react to the result of a tool, you can implement an EventListener or EventSubscriber, that listens to the
270-
`ToolCallsExecuted` event. This event is dispatched after the `ToolBox` executed all current tool calls and enables
272+
`ToolCallsExecuted` event. This event is dispatched after the `Toolbox` executed all current tool calls and enables
271273
you to skip the next LLM call by setting a response yourself:
272274

273275
```php
@@ -338,15 +340,15 @@ In the end the chain is used in combination with a retrieval tool on top of the
338340
use PhpLlm\LlmChain\Chain;
339341
use PhpLlm\LlmChain\Model\Message\Message;
340342
use PhpLlm\LlmChain\Model\Message\MessageBag;
341-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
342-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch;
343-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
343+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
344+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch;
345+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
344346

345347
// Initialize Platform & Models
346348

347349
$similaritySearch = new SimilaritySearch($embeddings, $store);
348-
$toolBox = ToolBox::create($similaritySearch);
349-
$processor = new ChainProcessor($toolBox);
350+
$toolbox = Toolbox::create($similaritySearch);
351+
$processor = new ChainProcessor($toolbox);
350352
$chain = new Chain($platform, $llm, [$processor], [$processor]);
351353

352354
$messages = new MessageBag(

examples/store-mongodb-similarity-search.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
77
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
88
use PhpLlm\LlmChain\Chain;
9-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
10-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch;
11-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
9+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
10+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch;
11+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1212
use PhpLlm\LlmChain\Document\Metadata;
1313
use PhpLlm\LlmChain\Document\TextDocument;
1414
use PhpLlm\LlmChain\Embedder;
@@ -61,8 +61,8 @@
6161
$llm = new GPT(GPT::GPT_4O_MINI);
6262

6363
$similaritySearch = new SimilaritySearch($platform, $embeddings, $store);
64-
$toolBox = ToolBox::create($similaritySearch);
65-
$processor = new ChainProcessor($toolBox);
64+
$toolbox = Toolbox::create($similaritySearch);
65+
$processor = new ChainProcessor($toolbox);
6666
$chain = new Chain($platform, $llm, [$processor], [$processor]);
6767

6868
$messages = new MessageBag(

examples/store-pinecone-similarity-search.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
66
use PhpLlm\LlmChain\Bridge\Pinecone\Store;
77
use PhpLlm\LlmChain\Chain;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
9-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch;
10-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
8+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
9+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch;
10+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1111
use PhpLlm\LlmChain\Document\Metadata;
1212
use PhpLlm\LlmChain\Document\TextDocument;
1313
use PhpLlm\LlmChain\Embedder;
@@ -52,8 +52,8 @@
5252
$llm = new GPT(GPT::GPT_4O_MINI);
5353

5454
$similaritySearch = new SimilaritySearch($platform, $embeddings, $store);
55-
$toolBox = ToolBox::create($similaritySearch);
56-
$processor = new ChainProcessor($toolBox);
55+
$toolbox = Toolbox::create($similaritySearch);
56+
$processor = new ChainProcessor($toolbox);
5757
$chain = new Chain($platform, $llm, [$processor], [$processor]);
5858

5959
$messages = new MessageBag(

examples/stream-tools-gpt-openai.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
99
use PhpLlm\LlmChain\Model\Message\Message;
1010
use PhpLlm\LlmChain\Model\Message\MessageBag;
1111
use Symfony\Component\Dotenv\Dotenv;
@@ -23,8 +23,8 @@
2323
$llm = new GPT(GPT::GPT_4O_MINI);
2424

2525
$wikipedia = new Wikipedia(HttpClient::create());
26-
$toolBox = ToolBox::create($wikipedia);
27-
$processor = new ChainProcessor($toolBox);
26+
$toolbox = Toolbox::create($wikipedia);
27+
$processor = new ChainProcessor($toolbox);
2828
$chain = new Chain($platform, $llm, [$processor], [$processor]);
2929
$messages = new MessageBag(Message::ofUser(<<<TXT
3030
First, define unicorn in 30 words.

examples/structured-output-clock.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use PhpLlm\LlmChain\Chain;
66
use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructuredOutputProcessor;
77
use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactory;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor as ToolProcessor;
9-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock;
10-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
8+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor as ToolProcessor;
9+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock;
10+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1111
use PhpLlm\LlmChain\Model\Message\Message;
1212
use PhpLlm\LlmChain\Model\Message\MessageBag;
1313
use Symfony\Component\Clock\Clock as SymfonyClock;
@@ -28,8 +28,8 @@
2828
$llm = new GPT(GPT::GPT_4O_MINI);
2929

3030
$clock = new Clock(new SymfonyClock());
31-
$toolBox = ToolBox::create($clock);
32-
$toolProcessor = new ToolProcessor($toolBox);
31+
$toolbox = Toolbox::create($clock);
32+
$toolProcessor = new ToolProcessor($toolbox);
3333
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
3434
$structuredOutputProcessor = new StructuredOutputProcessor(new ResponseFormatFactory(), $serializer);
3535
$chain = new Chain($platform, $llm, [$toolProcessor, $structuredOutputProcessor], [$toolProcessor, $structuredOutputProcessor]);

examples/toolbox-clock.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
99
use PhpLlm\LlmChain\Model\Message\Message;
1010
use PhpLlm\LlmChain\Model\Message\MessageBag;
1111
use Symfony\Component\Dotenv\Dotenv;
@@ -22,8 +22,8 @@
2222
$llm = new GPT(GPT::GPT_4O_MINI);
2323

2424
$clock = new Clock();
25-
$toolBox = ToolBox::create($clock);
26-
$processor = new ChainProcessor($toolBox);
25+
$toolbox = Toolbox::create($clock);
26+
$processor = new ChainProcessor($toolbox);
2727
$chain = new Chain($platform, $llm, [$processor], [$processor]);
2828

2929
$messages = new MessageBag(Message::ofUser('What date and time is it?'));

examples/toolbox-serpapi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\SerpApi;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\SerpApi;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
99
use PhpLlm\LlmChain\Model\Message\Message;
1010
use PhpLlm\LlmChain\Model\Message\MessageBag;
1111
use Symfony\Component\Dotenv\Dotenv;
@@ -22,8 +22,8 @@
2222
$llm = new GPT(GPT::GPT_4O_MINI);
2323

2424
$serpApi = new SerpApi(HttpClient::create(), $_ENV['SERP_API_KEY']);
25-
$toolBox = ToolBox::create($serpApi);
26-
$processor = new ChainProcessor($toolBox);
25+
$toolbox = Toolbox::create($serpApi);
26+
$processor = new ChainProcessor($toolbox);
2727
$chain = new Chain($platform, $llm, [$processor], [$processor]);
2828

2929
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));

examples/toolbox-tavily.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\Tavily;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Tavily;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
99
use PhpLlm\LlmChain\Model\Message\Message;
1010
use PhpLlm\LlmChain\Model\Message\MessageBag;
1111
use Symfony\Component\Dotenv\Dotenv;
@@ -22,8 +22,8 @@
2222
$llm = new GPT(GPT::GPT_4O_MINI);
2323

2424
$tavily = new Tavily(HttpClient::create(), $_ENV['TAVILY_API_KEY']);
25-
$toolBox = ToolBox::create($tavily);
26-
$processor = new ChainProcessor($toolBox);
25+
$toolbox = Toolbox::create($tavily);
26+
$processor = new ChainProcessor($toolbox);
2727
$chain = new Chain($platform, $llm, [$processor], [$processor]);
2828

2929
$messages = new MessageBag(Message::ofUser('What was the latest game result of Dallas Cowboys?'));

examples/toolbox-weather-event.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Event\ToolCallsExecuted;
8-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\OpenMeteo;
9-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Event\ToolCallsExecuted;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\OpenMeteo;
9+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1010
use PhpLlm\LlmChain\Model\Message\Message;
1111
use PhpLlm\LlmChain\Model\Message\MessageBag;
1212
use PhpLlm\LlmChain\Model\Response\StructuredResponse;
@@ -26,9 +26,9 @@
2626
$llm = new GPT(GPT::GPT_4O_MINI);
2727

2828
$openMeteo = new OpenMeteo(HttpClient::create());
29-
$toolBox = ToolBox::create($openMeteo);
29+
$toolbox = Toolbox::create($openMeteo);
3030
$eventDispatcher = new EventDispatcher();
31-
$processor = new ChainProcessor($toolBox, eventDispatcher: $eventDispatcher);
31+
$processor = new ChainProcessor($toolbox, eventDispatcher: $eventDispatcher);
3232
$chain = new Chain($platform, $llm, [$processor], [$processor]);
3333

3434
// Add tool call result listener to enforce chain exits direct with structured response for weather tools

examples/toolbox-wikipedia.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
44
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
6-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
7-
use PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
6+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia;
8+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
99
use PhpLlm\LlmChain\Model\Message\Message;
1010
use PhpLlm\LlmChain\Model\Message\MessageBag;
1111
use Symfony\Component\Dotenv\Dotenv;
@@ -23,8 +23,8 @@
2323
$llm = new GPT(GPT::GPT_4O_MINI);
2424

2525
$wikipedia = new Wikipedia(HttpClient::create());
26-
$toolBox = ToolBox::create($wikipedia);
27-
$processor = new ChainProcessor($toolBox);
26+
$toolbox = Toolbox::create($wikipedia);
27+
$processor = new ChainProcessor($toolbox);
2828
$chain = new Chain($platform, $llm, [$processor], [$processor]);
2929

3030
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));

0 commit comments

Comments
 (0)