Skip to content

Commit 14680ae

Browse files
committed
Cont prep for V2 release
1 parent 59d2cd7 commit 14680ae

File tree

114 files changed

+911
-865
lines changed

Some content is hidden

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

114 files changed

+911
-865
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="29c6"
34+
// @doctest id="e81d"
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="4b57"
56+
// @doctest id="bffa"
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="a23d"
69+
// @doctest id="f32f"
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="ab9a"
21+
// @doctest id="162b"
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="0747"
53+
// @doctest id="996c"
5454
```
5555

5656
## Customizing the Loop
@@ -81,7 +81,7 @@ $loop = AgentLoop::default()->withDriver(new ReActDriver(
8181
structuredOutput: $structuredOutput,
8282
model: 'gpt-4o',
8383
));
84-
// @doctest id="688b"
84+
// @doctest id="b92b"
8585
```
8686

8787
## System Prompt
@@ -90,7 +90,7 @@ $loop = AgentLoop::default()->withDriver(new ReActDriver(
9090
$state = AgentState::empty()
9191
->withSystemPrompt('You are a helpful assistant.')
9292
->withUserMessage('Hello!');
93-
// @doctest id="015f"
93+
// @doctest id="47e3"
9494
```
9595

9696
## Using AgentBuilder
@@ -110,7 +110,7 @@ $agent = AgentBuilder::base()
110110
->build();
111111

112112
$result = $agent->execute($state);
113-
// @doctest id="cd2e"
113+
// @doctest id="54bd"
114114
```
115115

116116
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="434d"
14+
// @doctest id="8062"
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="b66a"
34+
// @doctest id="f4b9"
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="9591"
45+
// @doctest id="14b8"
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="3408"
70+
// @doctest id="6f28"
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="e561"
14+
// @doctest id="0c0a"
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="4ec1"
29+
// @doctest id="6edc"
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="6c8b"
54+
// @doctest id="288f"
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="9e2e"
71+
// @doctest id="6d20"
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="f337"
85+
// @doctest id="e730"
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="a4ac"
114+
// @doctest id="dd6f"
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="439f"
132+
// @doctest id="d62e"
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="0ed4"
19+
// @doctest id="bb44"
2020
```
2121

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

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

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

5959
$tools = new Tools($weather, $calculator);
60-
// @doctest id="ac7d"
60+
// @doctest id="e419"
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="1c5a"
74+
// @doctest id="25ad"
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="2465"
91+
// @doctest id="e6bc"
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="b643"
105+
// @doctest id="6b26"
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="58aa"
130+
// @doctest id="5a3b"
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="eacf"
33+
// @doctest id="1625"
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="e5d3"
46+
// @doctest id="6d36"
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="d110"
62+
// @doctest id="1137"
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="641f"
76+
// @doctest id="8844"
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="d8ae"
119+
// @doctest id="7c43"
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="1c16"
147+
// @doctest id="baae"
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="9a0c"
161+
// @doctest id="1988"
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="44b4"
21+
// @doctest id="5e1c"
2222
```
2323

2424
## Message Compilers
@@ -30,7 +30,7 @@ interface CanCompileMessages
3030
{
3131
public function compile(AgentState $state): Messages;
3232
}
33-
// @doctest id="6408"
33+
// @doctest id="c0ab"
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,7 +50,7 @@ class MyCompiler implements CanCompileMessages
5050
return $state->messages();
5151
}
5252
}
53-
// @doctest id="15dc"
53+
// @doctest id="f5a8"
5454
```
5555

5656
Inject it into the loop's driver:
@@ -62,7 +62,7 @@ $driver = new ToolCallingDriver(
6262
messageCompiler: new MyCompiler(),
6363
);
6464
$loop = AgentLoop::default()->withDriver($driver);
65-
// @doctest id="3816"
65+
// @doctest id="9cec"
6666
```
6767

6868
Or via `AgentBuilder`:
@@ -74,7 +74,7 @@ use Cognesy\Agents\Capability\Core\UseContextCompiler;
7474
$agent = AgentBuilder::base()
7575
->withCapability(new UseContextCompiler(new MyCompiler()))
7676
->build();
77-
// @doctest id="c329"
77+
// @doctest id="0d9f"
7878
```
7979

8080
## Use Cases
@@ -117,7 +117,7 @@ class TokenLimitCompiler implements CanCompileMessages
117117
return Messages::fromArray($kept);
118118
}
119119
}
120-
// @doctest id="2780"
120+
// @doctest id="5e6f"
121121
```
122122

123123
Use as a decorator via `UseContextCompilerDecorator`:
@@ -130,7 +130,7 @@ $agent = AgentBuilder::base()
130130
fn(CanCompileMessages $inner) => new TokenLimitCompiler($inner, maxTokens: 4000)
131131
))
132132
->build();
133-
// @doctest id="0cd9"
133+
// @doctest id="b235"
134134
```
135135

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

0 commit comments

Comments
 (0)