Skip to content

Commit 131aecd

Browse files
committed
Isolating packages/agents - in progress
1 parent caba931 commit 131aecd

File tree

367 files changed

+23361
-686
lines changed

Some content is hidden

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

367 files changed

+23361
-686
lines changed

.github/workflows/split.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
- local: 'packages/addons'
2222
repo: 'cognesy/instructor-addons'
2323
name: 'instructor-addons'
24+
- local: 'packages/agents'
25+
repo: 'cognesy/instructor-agents'
26+
name: 'instructor-agents'
2427
- local: 'packages/agent-ctrl'
2528
repo: 'cognesy/instructor-agent-ctrl'
2629
name: 'instructor-agent-ctrl'

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"autoload": {
2626
"psr-4": {
2727
"Cognesy\\Addons\\": "packages/addons/src/",
28+
"Cognesy\\Agents\\": "packages/agents/src/",
2829
"Cognesy\\AgentCtrl\\": "packages/agent-ctrl/src/",
2930
"Cognesy\\Auxiliary\\": "packages/auxiliary/src/",
3031
"Cognesy\\Config\\": "packages/config/src/",
@@ -57,6 +58,7 @@
5758
"Cognesy\\Tell\\": "packages/tell/src/",
5859
"Cognesy\\Experimental\\": "packages/experimental/src/",
5960
"Cognesy\\Addons\\Tests\\": "packages/addons/tests/",
61+
"Cognesy\\Agents\\Tests\\": "packages/agents/tests/",
6062
"Cognesy\\AgentCtrl\\Tests\\": "packages/agent-ctrl/tests/",
6163
"Cognesy\\Config\\Tests\\": "packages/config/tests/",
6264
"Cognesy\\Dynamic\\Tests\\": "packages/dynamic/tests/",

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="5cd8"
47+
// @doctest id="db9a"
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="b041"
107+
// @doctest id="4cb4"
108108
```
109109

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

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

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

168168
return HookOutcome::proceed();
169169
}
170-
// @doctest id="d68c"
170+
// @doctest id="e067"
171171
```
172172

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

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

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

207207
return HookOutcome::proceed();
208208
}
209-
// @doctest id="255d"
209+
// @doctest id="e470"
210210
```
211211

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

224224
return HookOutcome::proceed();
225225
}
226-
// @doctest id="9a69"
226+
// @doctest id="bd27"
227227
```
228228

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

248248
// Regex patterns
249249
new ToolNameMatcher('/^(read|write)_.+$/');
250-
// @doctest id="8837"
250+
// @doctest id="723c"
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="dc5f"
266+
// @doctest id="caf8"
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="59c8"
297+
// @doctest id="4903"
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="764a"
310+
// @doctest id="6636"
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="7e23"
327+
// @doctest id="3b70"
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="940e"
355+
// @doctest id="4b0c"
356356
```
357357

358358
### Step Hooks
@@ -367,7 +367,7 @@ $builder->onBeforeStep(
367367
$builder->onAfterStep(
368368
callback: callable, // (AgentState) -> AgentState
369369
);
370-
// @doctest id="9bcb"
370+
// @doctest id="0c8b"
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="6696"
387+
// @doctest id="8eae"
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="9afe"
404+
// @doctest id="99d3"
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="d17f"
415+
// @doctest id="615c"
416416
```
417417

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

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

463463
## Using HookStack Directly
@@ -482,7 +482,7 @@ if ($outcome->isBlocked()) {
482482
} elseif ($outcome->isStopped()) {
483483
// Handle stopped
484484
}
485-
// @doctest id="497d"
485+
// @doctest id="3630"
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="d3a3"
501+
// @doctest id="d9e4"
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="92d8"
511+
// @doctest id="c55f"
512512
```
513513

514514
## Common Patterns
@@ -533,7 +533,7 @@ $builder->onBeforeToolUse(
533533
priority: 100, // Run first
534534
matcher: 'bash',
535535
);
536-
// @doctest id="4e00"
536+
// @doctest id="297b"
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="e1b8"
553+
// @doctest id="4be1"
554554
```
555555

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

574574
return HookOutcome::proceed();
575575
});
576-
// @doctest id="8b0a"
576+
// @doctest id="0415"
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="3791"
602+
// @doctest id="ed57"
603603
```
604604

605605
## Architecture
@@ -631,7 +631,7 @@ $builder->onAgentFailed(function (FailureHookContext $ctx): void {
631631
│ │ execution│ │ action │ │ entirely │ │
632632
│ └──────────┘ └──────────┘ └──────────┘ │
633633
└─────────────────────────────────────────────────────────────┘
634-
// @doctest id="94a3"
634+
// @doctest id="a2da"
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="778a"
675+
// @doctest id="2e68"
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="92ca"
97+
// @doctest id="cf1a"
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="b10b"
108+
// @doctest id="14b0"
109109
```
110110

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

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

142142
## Supported HTTP Clients

0 commit comments

Comments
 (0)