Skip to content

Commit 5f24f01

Browse files
committed
Cont agents refactoring
1 parent da3fe1e commit 5f24f01

File tree

140 files changed

+6690
-1196
lines changed

Some content is hidden

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

140 files changed

+6690
-1196
lines changed

docs-build/packages/addons/agent_hooks.mdx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $agent = AgentBuilder::new()
4444
})
4545

4646
->build();
47-
// @doctest id="0399"
47+
// @doctest id="ffce"
4848
```
4949

5050
## Lifecycle Events
@@ -104,7 +104,7 @@ HookOutcome::block('Dangerous command detected');
104104

105105
// Stop the entire agent execution
106106
HookOutcome::stop('Budget exceeded');
107-
// @doctest id="ec5c"
107+
// @doctest id="12cc"
108108
```
109109

110110
### Semantic Differences
@@ -146,7 +146,7 @@ function afterTool(ToolHookContext $ctx): HookOutcome {
146146

147147
return HookOutcome::proceed();
148148
}
149-
// @doctest id="5324"
149+
// @doctest id="f459"
150150
```
151151

152152
### StepHookContext
@@ -167,7 +167,7 @@ function onStep(StepHookContext $ctx): HookOutcome {
167167

168168
return HookOutcome::proceed();
169169
}
170-
// @doctest id="7e81"
170+
// @doctest id="667d"
171171
```
172172

173173
### StopHookContext
@@ -187,7 +187,7 @@ function onStop(StopHookContext $ctx): HookOutcome {
187187

188188
return HookOutcome::proceed(); // Allow stop
189189
}
190-
// @doctest id="482f"
190+
// @doctest id="87e1"
191191
```
192192

193193
### ExecutionHookContext
@@ -206,7 +206,7 @@ function onExecution(ExecutionHookContext $ctx): HookOutcome {
206206

207207
return HookOutcome::proceed();
208208
}
209-
// @doctest id="8e05"
209+
// @doctest id="e2ea"
210210
```
211211

212212
### FailureHookContext
@@ -223,7 +223,7 @@ function onFailure(FailureHookContext $ctx): HookOutcome {
223223

224224
return HookOutcome::proceed();
225225
}
226-
// @doctest id="ea9a"
226+
// @doctest id="8e63"
227227
```
228228

229229
## Matchers
@@ -247,7 +247,7 @@ new ToolNameMatcher('*'); // Match all
247247

248248
// Regex patterns
249249
new ToolNameMatcher('/^(read|write)_.+$/');
250-
// @doctest id="9f59"
250+
// @doctest id="1611"
251251
```
252252

253253
### EventTypeMatcher
@@ -263,7 +263,7 @@ new EventTypeMatcher(HookEvent::PreToolUse);
263263

264264
// Multiple events
265265
new EventTypeMatcher(HookEvent::BeforeStep, HookEvent::AfterStep);
266-
// @doctest id="2c61"
266+
// @doctest id="dc09"
267267
```
268268

269269
### CompositeMatcher
@@ -294,7 +294,7 @@ $matcher = CompositeMatcher::and(
294294
),
295295
new CallableMatcher(fn($ctx) => $ctx->state()->metadata()->get('safe_mode')),
296296
);
297-
// @doctest id="d1ae"
297+
// @doctest id="c1d8"
298298
```
299299

300300
### CallableMatcher
@@ -307,7 +307,7 @@ use Cognesy\Addons\Agent\Hooks\Matchers\CallableMatcher;
307307
$matcher = new CallableMatcher(function (HookContext $ctx): bool {
308308
return $ctx->state()->metadata()->get('priority') === 'high';
309309
});
310-
// @doctest id="d275"
310+
// @doctest id="7986"
311311
```
312312

313313
## Priority
@@ -324,7 +324,7 @@ $builder
324324

325325
// Logging hooks run last (low priority)
326326
->onAfterToolUse($logger, priority: -100);
327-
// @doctest id="3e91"
327+
// @doctest id="8242"
328328
```
329329

330330
**Priority Guidelines:**
@@ -352,7 +352,7 @@ $builder->onAfterToolUse(
352352
priority: int = 0,
353353
matcher: string|HookMatcher|null = null,
354354
);
355-
// @doctest id="6227"
355+
// @doctest id="635a"
356356
```
357357

358358
### Step Hooks
@@ -367,7 +367,7 @@ $builder->onBeforeStep(
367367
$builder->onAfterStep(
368368
callback: callable, // (AgentState) -> AgentState
369369
);
370-
// @doctest id="c1ae"
370+
// @doctest id="0beb"
371371
```
372372

373373
### Execution Hooks
@@ -384,7 +384,7 @@ $builder->onExecutionEnd(
384384
callback: callable, // (ExecutionHookContext) -> HookOutcome|void
385385
priority: int = 0,
386386
);
387-
// @doctest id="fcc9"
387+
// @doctest id="c247"
388388
```
389389

390390
### Continuation Hooks
@@ -401,7 +401,7 @@ $builder->onSubagentStop(
401401
callback: callable, // (StopHookContext) -> HookOutcome|void
402402
priority: int = 0,
403403
);
404-
// @doctest id="6f4c"
404+
// @doctest id="6ec5"
405405
```
406406

407407
### Error Hooks
@@ -412,7 +412,7 @@ $builder->onAgentFailed(
412412
callback: callable, // (FailureHookContext) -> HookOutcome|void
413413
priority: int = 0,
414414
);
415-
// @doctest id="277b"
415+
// @doctest id="4298"
416416
```
417417

418418
### Unified Registration
@@ -428,7 +428,7 @@ $builder->addHook(
428428
hook: new CallableHook($callback, $matcher),
429429
priority: 100,
430430
);
431-
// @doctest id="00a3"
431+
// @doctest id="cbbd"
432432
```
433433

434434
## Creating Custom Hooks
@@ -457,7 +457,7 @@ class RateLimitHook implements Hook
457457
return $next($context);
458458
}
459459
}
460-
// @doctest id="66b6"
460+
// @doctest id="d10e"
461461
```
462462

463463
## Using HookStack Directly
@@ -482,7 +482,7 @@ if ($outcome->isBlocked()) {
482482
} elseif ($outcome->isStopped()) {
483483
// Handle stopped
484484
}
485-
// @doctest id="f4b9"
485+
// @doctest id="6a76"
486486
```
487487

488488
## Backward Compatibility
@@ -498,7 +498,7 @@ use Cognesy\Addons\Agent\Hooks\Adapters\StateProcessorAdapter;
498498

499499
$processor = new YourStateProcessor();
500500
$hook = new StateProcessorAdapter($processor, position: 'after');
501-
// @doctest id="4f94"
501+
// @doctest id="c6af"
502502
```
503503

504504
### ContinuationCriteriaAdapter
@@ -508,7 +508,7 @@ use Cognesy\Addons\Agent\Hooks\Adapters\ContinuationCriteriaAdapter;
508508

509509
$criterion = new YourContinuationCriterion();
510510
$hook = new ContinuationCriteriaAdapter($criterion);
511-
// @doctest id="0318"
511+
// @doctest id="aba7"
512512
```
513513

514514
## Common Patterns
@@ -533,7 +533,7 @@ $builder->onBeforeToolUse(
533533
priority: 100, // Run first
534534
matcher: 'bash',
535535
);
536-
// @doctest id="5086"
536+
// @doctest id="801e"
537537
```
538538

539539
### Execution Timing
@@ -550,7 +550,7 @@ $builder
550550
$duration = microtime(true) - $started;
551551
$this->metrics->record('execution_duration', $duration);
552552
});
553-
// @doctest id="4847"
553+
// @doctest id="de29"
554554
```
555555

556556
### Conditional Continuation
@@ -573,7 +573,7 @@ $builder->onStop(function (StopHookContext $ctx): HookOutcome {
573573

574574
return HookOutcome::proceed();
575575
});
576-
// @doctest id="8f96"
576+
// @doctest id="1599"
577577
```
578578

579579
### Error Recovery Logging
@@ -599,7 +599,7 @@ $builder->onAgentFailed(function (FailureHookContext $ctx): void {
599599
$this->alerting->sendCritical($exception);
600600
}
601601
});
602-
// @doctest id="2b2b"
602+
// @doctest id="4bba"
603603
```
604604

605605
## Architecture
@@ -631,7 +631,7 @@ $builder->onAgentFailed(function (FailureHookContext $ctx): void {
631631
│ │ execution│ │ action │ │ entirely │ │
632632
│ └──────────┘ └──────────┘ └──────────┘ │
633633
└─────────────────────────────────────────────────────────────┘
634-
// @doctest id="fda3"
634+
// @doctest id="fd6e"
635635
```
636636

637637
## File Structure
@@ -672,5 +672,5 @@ packages/addons/src/Agent/Hooks/
672672
└── Adapters/
673673
├── StateProcessorAdapter.php
674674
└── ContinuationCriteriaAdapter.php
675-
// @doctest id="c407"
675+
// @doctest id="0815"
676676
```

docs-build/packages/http/1-overview.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ HttpClient
9494
└── withRequest() - Create pending request for execution
9595
└── pool() - Execute multiple requests concurrently
9696
└── withPool() - Create pending pool for deferred execution
97-
// @doctest id="b2a6"
97+
// @doctest id="c545"
9898
```
9999

100100
### Middleware Layer
@@ -105,7 +105,7 @@ The middleware system allows for processing requests and responses through a cha
105105
Request -> Middleware 1 -> Middleware 2 -> ... -> Driver -> External API
106106
107107
Response <- Middleware 1 <- Middleware 2 <- ... <- Driver <- HTTP Response
108-
// @doctest id="8181"
108+
// @doctest id="d9ed"
109109
```
110110

111111
Key components:
@@ -123,7 +123,7 @@ CanHandleHttpRequest (interface)
123123
├── SymfonyDriver
124124
├── LaravelDriver
125125
└── MockHttpDriver (for testing)
126-
// @doctest id="b739"
126+
// @doctest id="a5b8"
127127
```
128128

129129
### Adapter Layer
@@ -136,7 +136,7 @@ HttpResponse (interface)
136136
├── SymfonyHttpResponse
137137
├── LaravelHttpResponse
138138
└── MockHttpResponse
139-
// @doctest id="8873"
139+
// @doctest id="92a3"
140140
```
141141

142142
## Supported HTTP Clients

0 commit comments

Comments
 (0)