Skip to content

Commit 57c5a7b

Browse files
committed
Fixed test-all
1 parent 84734a4 commit 57c5a7b

File tree

108 files changed

+886
-954
lines changed

Some content is hidden

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

108 files changed

+886
-954
lines changed

docs-build/packages/agents/01-introduction.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $agent = AgentBuilder::base()
3131
->withCapability(new UseBash())
3232
->withCapability(new UseGuards(maxSteps: 10))
3333
->build();
34-
// @doctest id="b472"
34+
// @doctest id="9cc0"
3535
```
3636

3737
## Package Structure
@@ -53,7 +53,7 @@ Hook/ # HookStack, HookInterface, HookContext, built-in hooks
5353
Interception/ # CanInterceptAgentLifecycle, PassThroughInterceptor
5454
Template/ # Agent definitions, parsers, registry
5555
Tool/ # ToolInterface, BaseTool, FunctionTool, ToolExecutor
56-
// @doctest id="4297"
56+
// @doctest id="78ea"
5757
```
5858

5959
## Minimal Example
@@ -66,5 +66,5 @@ $state = AgentState::empty()->withUserMessage('Hello!');
6666
$result = $loop->execute($state);
6767

6868
echo $result->finalResponse()->toString();
69-
// @doctest id="f6ea"
69+
// @doctest id="a4b6"
7070
```

docs-build/packages/agents/02-basic-agent.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $result = $loop->execute($state);
1818

1919
echo $result->finalResponse()->toString();
2020
// "2 + 2 equals 4."
21-
// @doctest id="a0c8"
21+
// @doctest id="a05f"
2222
```
2323

2424
## What Happens
@@ -50,7 +50,7 @@ $result = $loop->execute($state);
5050

5151
echo $result->finalResponse()->toString();
5252
// "The weather in Paris is 72°F and sunny."
53-
// @doctest id="a6e4"
53+
// @doctest id="4372"
5454
```
5555

5656
## Customizing the Loop
@@ -65,7 +65,7 @@ $loop = AgentLoop::default()->withTool($myTool);
6565

6666
// Swap driver
6767
$loop = AgentLoop::default()->withDriver(new ReActDriver(model: 'gpt-4o'));
68-
// @doctest id="54ea"
68+
// @doctest id="a341"
6969
```
7070

7171
## System Prompt
@@ -74,7 +74,7 @@ $loop = AgentLoop::default()->withDriver(new ReActDriver(model: 'gpt-4o'));
7474
$state = AgentState::empty()
7575
->withSystemPrompt('You are a helpful assistant.')
7676
->withUserMessage('Hello!');
77-
// @doctest id="547f"
77+
// @doctest id="eed1"
7878
```
7979

8080
## Using AgentBuilder
@@ -94,7 +94,7 @@ $agent = AgentBuilder::base()
9494
->build();
9595

9696
$result = $agent->execute($state);
97-
// @doctest id="194e"
97+
// @doctest id="2535"
9898
```
9999

100100
See [AgentBuilder & Capabilities](13-agent-builder.md) for details.

docs-build/packages/agents/03-basic-concepts.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The orchestrator. Runs a step-based loop: call LLM, execute tools, check stop co
1111

1212
```
1313
BeforeExecution -> [ BeforeStep -> UseTools -> AfterStep -> ShouldStop? ] -> AfterExecution
14-
// @doctest id="3cdd"
14+
// @doctest id="b8cd"
1515
```
1616

1717
## AgentState
@@ -31,7 +31,7 @@ $state = AgentState::empty()
3131
->withSystemPrompt('You are helpful.')
3232
->withUserMessage('Hello')
3333
->withBudget(new AgentBudget(maxSteps: 10));
34-
// @doctest id="5db3"
34+
// @doctest id="cd34"
3535
```
3636

3737
## AgentContext
@@ -42,7 +42,7 @@ Holds the conversation data: messages, system prompt, metadata, and response for
4242
$state = AgentState::empty()
4343
->withSystemPrompt('You are helpful.')
4444
->withMetadata('user_id', 123);
45-
// @doctest id="78f6"
45+
// @doctest id="b6bb"
4646
```
4747

4848
## AgentStep
@@ -67,5 +67,5 @@ Tracks the current execution's transient state: status, completed steps, current
6767
$state->execution()->status(); // ExecutionStatus::InProgress
6868
$state->execution()->stepCount(); // 3
6969
$state->execution()->shouldStop(); // false
70-
// @doctest id="faa7"
70+
// @doctest id="c8c1"
7171
```

docs-build/packages/agents/04-controlling-the-loop.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: 'Run agents to completion with execute() or step through with itera
1111

1212
```php
1313
$finalState = $loop->execute($state);
14-
// @doctest id="88f9"
14+
// @doctest id="0f2f"
1515
```
1616

1717
`iterate()` yields state after each step, giving you full control:
@@ -26,7 +26,7 @@ foreach ($loop->iterate($state) as $stepState) {
2626
echo " Tool: {$exec->name()} -> {$exec->value()}\n";
2727
}
2828
}
29-
// @doctest id="81fb"
29+
// @doctest id="a45f"
3030
```
3131

3232
## Inspecting State
@@ -51,7 +51,7 @@ $toolExec = $state->lastToolExecution();
5151
$toolExec?->name(); // 'weather'
5252
$toolExec?->value(); // '72F, sunny'
5353
$toolExec?->hasError(); // false
54-
// @doctest id="58bc"
54+
// @doctest id="f983"
5555
```
5656

5757
## Reading the Agent's Response
@@ -68,7 +68,7 @@ all other cases: forced stops, errors, budget exhaustion, etc.
6868
```php
6969
$state->hasFinalResponse(); // true only on natural completion
7070
$state->finalResponse()->toString(); // strict: empty when interrupted
71-
// @doctest id="b3cf"
71+
// @doctest id="9b98"
7272
```
7373

7474
Use `finalResponse()` when you need to distinguish between a genuine
@@ -82,7 +82,7 @@ otherwise the last step's output messages regardless of step type.
8282

8383
```php
8484
$state->currentResponse()->toString(); // pragmatic: last output text
85-
// @doctest id="2629"
85+
// @doctest id="4a77"
8686
```
8787

8888
Use `currentResponse()` when you want to show *something* to the user
@@ -111,7 +111,7 @@ if ($state->hasFinalResponse()) {
111111
echo "Agent stopped: {$reason->value}\n";
112112
echo $state->currentResponse()->toString();
113113
}
114-
// @doctest id="f024"
114+
// @doctest id="d5f1"
115115
```
116116

117117
## Listening to Events
@@ -129,5 +129,5 @@ $loop->onEvent(AgentStepCompleted::class, function (AgentStepCompleted $event) {
129129
$loop->wiretap(function ($event) {
130130
echo get_class($event) . "\n";
131131
});
132-
// @doctest id="fdfa"
132+
// @doctest id="7b8f"
133133
```

docs-build/packages/agents/05-tools.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Cognesy\Agents\Collections\Tools;use Cognesy\Agents\Tool\Tools\MockTool;
1616

1717
$calculator = MockTool::returning('calculator', 'Performs math', '42');
1818
$tools = new Tools($calculator);
19-
// @doctest id="01a5"
19+
// @doctest id="4b9d"
2020
```
2121

2222
## Using FunctionTool
@@ -33,7 +33,7 @@ $tool = FunctionTool::fromCallable(
3333
);
3434

3535
$tools = new Tools($tool);
36-
// @doctest id="7801"
36+
// @doctest id="a9cb"
3737
```
3838

3939
## Multiple Tools
@@ -57,7 +57,7 @@ $calculator = FunctionTool::fromCallable(
5757
);
5858

5959
$tools = new Tools($weather, $calculator);
60-
// @doctest id="15f0"
60+
// @doctest id="eb37"
6161
```
6262

6363
## Agent with Tools
@@ -71,7 +71,7 @@ $loop = AgentLoop::default()->withTools($tools);
7171
$state = AgentState::empty()->withUserMessage('What is the weather in Paris?');
7272
$result = $loop->execute($state);
7373
// LLM calls the weather tool, gets result, then responds
74-
// @doctest id="312b"
74+
// @doctest id="2fc8"
7575
```
7676

7777
## Tool Contracts
@@ -88,7 +88,7 @@ interface ToolInterface {
8888
public function toToolSchema(): array; // JSON schema sent to LLM
8989
public function descriptor(): CanDescribeTool; // metadata accessor
9090
}
91-
// @doctest id="c50f"
91+
// @doctest id="4199"
9292
```
9393

9494
### CanDescribeTool
@@ -102,7 +102,7 @@ interface CanDescribeTool {
102102
public function metadata(): array; // summary for browsing/discovery
103103
public function instructions(): array; // full specification with parameters
104104
}
105-
// @doctest id="e9f3"
105+
// @doctest id="8ba5"
106106
```
107107

108108
`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
127127
return "Weather in {$city}: 72F, sunny";
128128
}
129129
}
130-
// @doctest id="cab2"
130+
// @doctest id="87d2"
131131
```
132132

133133
See [Building Tools](06-building-tools.md) for the full guide on creating custom tools.

docs-build/packages/agents/06-building-tools.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GetWeather extends BaseTool
3030
return "Weather in {$city}: 22 {$unit}";
3131
}
3232
}
33-
// @doctest id="8984"
33+
// @doctest id="ad58"
3434
```
3535

3636
## Using FunctionTool
@@ -43,7 +43,7 @@ use Cognesy\Agents\Tool\Tools\FunctionTool;
4343
$tool = FunctionTool::fromCallable(function (string $query): string {
4444
return "Results for: {$query}";
4545
});
46-
// @doctest id="4203"
46+
// @doctest id="3cdc"
4747
```
4848

4949
## Accessing Agent State
@@ -59,7 +59,7 @@ class StatefulTool extends BaseTool
5959
return "Step {$stepCount}: processing {$input}";
6060
}
6161
}
62-
// @doctest id="ac6c"
62+
// @doctest id="19e9"
6363
```
6464

6565
## The ToolInterface
@@ -73,7 +73,7 @@ interface ToolInterface
7373
public function toToolSchema(): array;
7474
public function descriptor(): CanDescribeTool;
7575
}
76-
// @doctest id="4311"
76+
// @doctest id="8adb"
7777
```
7878

7979
- `use()` - execute the tool, returns `Result` (success or failure)
@@ -116,7 +116,7 @@ final readonly class MyToolDescriptor extends ToolDescriptor
116116
);
117117
}
118118
}
119-
// @doctest id="3d12"
119+
// @doctest id="20b5"
120120
```
121121

122122
Then wire it into your tool:
@@ -144,7 +144,7 @@ class MyTool extends BaseTool
144144
return "Processed: {$input}";
145145
}
146146
}
147-
// @doctest id="c262"
147+
// @doctest id="eab4"
148148
```
149149

150150
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.
@@ -158,5 +158,5 @@ $tool = MockTool::returning('my_tool', 'Does something', 'fixed result');
158158

159159
// Or with custom logic
160160
$tool = new MockTool('my_tool', 'Does something', fn($x) => strtoupper($x));
161-
// @doctest id="7613"
161+
// @doctest id="640e"
162162
```

docs-build/packages/agents/07-context-and-compilers.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $state = AgentState::empty()
1818
$state->context()->systemPrompt();
1919
$state->context()->messages();
2020
$state->context()->metadata();
21-
// @doctest id="cf34"
21+
// @doctest id="badc"
2222
```
2323

2424
## Message Compilers
@@ -30,7 +30,7 @@ interface CanCompileMessages
3030
{
3131
public function compile(AgentState $state): Messages;
3232
}
33-
// @doctest id="4470"
33+
// @doctest id="578b"
3434
```
3535

3636
The default compiler assembles messages from the agent's context. You can replace it to control exactly what the LLM sees.
@@ -50,15 +50,15 @@ class MyCompiler implements CanCompileMessages
5050
return $state->messages();
5151
}
5252
}
53-
// @doctest id="770b"
53+
// @doctest id="a048"
5454
```
5555

5656
Inject it into the loop's driver:
5757

5858
```php
5959
$driver = new ToolCallingDriver(messageCompiler: new MyCompiler());
6060
$loop = AgentLoop::default()->withDriver($driver);
61-
// @doctest id="b869"
61+
// @doctest id="7055"
6262
```
6363

6464
Or via `AgentBuilder`:
@@ -70,7 +70,7 @@ use Cognesy\Agents\Capability\Core\UseContextCompiler;
7070
$agent = AgentBuilder::base()
7171
->withCapability(new UseContextCompiler(new MyCompiler()))
7272
->build();
73-
// @doctest id="3976"
73+
// @doctest id="a26c"
7474
```
7575

7676
## Use Cases
@@ -113,7 +113,7 @@ class TokenLimitCompiler implements CanCompileMessages
113113
return Messages::fromArray($kept);
114114
}
115115
}
116-
// @doctest id="b369"
116+
// @doctest id="857f"
117117
```
118118

119119
Use as a decorator via `UseContextCompilerDecorator`:
@@ -126,7 +126,7 @@ $agent = AgentBuilder::base()
126126
fn(CanCompileMessages $inner) => new TokenLimitCompiler($inner, maxTokens: 4000)
127127
))
128128
->build();
129-
// @doctest id="c0f7"
129+
// @doctest id="e987"
130130
```
131131

132132
The decorator pattern wraps the default compiler, so you get standard message assembly plus your custom logic on top.

0 commit comments

Comments
 (0)