groundswell 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +188 -0
- package/README.md +99 -5
- package/dist/__tests__/adversarial/attachChild-performance.test.d.ts +16 -0
- package/dist/__tests__/adversarial/attachChild-performance.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/attachChild-performance.test.js +187 -0
- package/dist/__tests__/adversarial/attachChild-performance.test.js.map +1 -0
- package/dist/__tests__/adversarial/circular-reference.test.d.ts +13 -0
- package/dist/__tests__/adversarial/circular-reference.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/circular-reference.test.js +92 -0
- package/dist/__tests__/adversarial/circular-reference.test.js.map +1 -0
- package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts +16 -0
- package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/complex-circular-reference.test.js +127 -0
- package/dist/__tests__/adversarial/complex-circular-reference.test.js.map +1 -0
- package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts +21 -0
- package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/concurrent-task-failures.test.js +667 -0
- package/dist/__tests__/adversarial/concurrent-task-failures.test.js.map +1 -0
- package/dist/__tests__/adversarial/deep-analysis.test.d.ts +6 -0
- package/dist/__tests__/adversarial/deep-analysis.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/deep-analysis.test.js +877 -0
- package/dist/__tests__/adversarial/deep-analysis.test.js.map +1 -0
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts +13 -0
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js +186 -0
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js.map +1 -0
- package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts +6 -0
- package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/e2e-prd-validation.test.js +626 -0
- package/dist/__tests__/adversarial/e2e-prd-validation.test.js.map +1 -0
- package/dist/__tests__/adversarial/edge-case.test.d.ts +6 -0
- package/dist/__tests__/adversarial/edge-case.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/edge-case.test.js +857 -0
- package/dist/__tests__/adversarial/edge-case.test.js.map +1 -0
- package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts +20 -0
- package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/error-merge-strategy.test.js +907 -0
- package/dist/__tests__/adversarial/error-merge-strategy.test.js.map +1 -0
- package/dist/__tests__/adversarial/incremental-performance.test.d.ts +2 -0
- package/dist/__tests__/adversarial/incremental-performance.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/incremental-performance.test.js +113 -0
- package/dist/__tests__/adversarial/incremental-performance.test.js.map +1 -0
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts +22 -0
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js +383 -0
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js.map +1 -0
- package/dist/__tests__/adversarial/observer-propagation.test.d.ts +21 -0
- package/dist/__tests__/adversarial/observer-propagation.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/observer-propagation.test.js +404 -0
- package/dist/__tests__/adversarial/observer-propagation.test.js.map +1 -0
- package/dist/__tests__/adversarial/parent-validation.test.d.ts +13 -0
- package/dist/__tests__/adversarial/parent-validation.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/parent-validation.test.js +128 -0
- package/dist/__tests__/adversarial/parent-validation.test.js.map +1 -0
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts +20 -0
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.js +482 -0
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.js.map +1 -0
- package/dist/__tests__/adversarial/prd-compliance.test.d.ts +6 -0
- package/dist/__tests__/adversarial/prd-compliance.test.d.ts.map +1 -0
- package/dist/__tests__/adversarial/prd-compliance.test.js +886 -0
- package/dist/__tests__/adversarial/prd-compliance.test.js.map +1 -0
- package/dist/__tests__/compatibility/backward-compatibility.test.d.ts +22 -0
- package/dist/__tests__/compatibility/backward-compatibility.test.d.ts.map +1 -0
- package/dist/__tests__/compatibility/backward-compatibility.test.js +1843 -0
- package/dist/__tests__/compatibility/backward-compatibility.test.js.map +1 -0
- package/dist/__tests__/helpers/index.d.ts +10 -0
- package/dist/__tests__/helpers/index.d.ts.map +1 -0
- package/dist/__tests__/helpers/index.js +10 -0
- package/dist/__tests__/helpers/index.js.map +1 -0
- package/dist/__tests__/helpers/tree-verification.d.ts +90 -0
- package/dist/__tests__/helpers/tree-verification.d.ts.map +1 -0
- package/dist/__tests__/helpers/tree-verification.js +202 -0
- package/dist/__tests__/helpers/tree-verification.js.map +1 -0
- package/dist/__tests__/integration/agent-workflow.test.d.ts +2 -0
- package/dist/__tests__/integration/agent-workflow.test.d.ts.map +1 -0
- package/dist/__tests__/integration/agent-workflow.test.js +256 -0
- package/dist/__tests__/integration/agent-workflow.test.js.map +1 -0
- package/dist/__tests__/integration/bidirectional-consistency.test.d.ts +14 -0
- package/dist/__tests__/integration/bidirectional-consistency.test.d.ts.map +1 -0
- package/dist/__tests__/integration/bidirectional-consistency.test.js +668 -0
- package/dist/__tests__/integration/bidirectional-consistency.test.js.map +1 -0
- package/dist/__tests__/integration/observer-logging.test.d.ts +2 -0
- package/dist/__tests__/integration/observer-logging.test.d.ts.map +1 -0
- package/dist/__tests__/integration/observer-logging.test.js +517 -0
- package/dist/__tests__/integration/observer-logging.test.js.map +1 -0
- package/dist/__tests__/integration/tree-mirroring.test.d.ts +2 -0
- package/dist/__tests__/integration/tree-mirroring.test.d.ts.map +1 -0
- package/dist/__tests__/integration/tree-mirroring.test.js +117 -0
- package/dist/__tests__/integration/tree-mirroring.test.js.map +1 -0
- package/dist/__tests__/integration/workflow-reparenting.test.d.ts +12 -0
- package/dist/__tests__/integration/workflow-reparenting.test.d.ts.map +1 -0
- package/dist/__tests__/integration/workflow-reparenting.test.js +239 -0
- package/dist/__tests__/integration/workflow-reparenting.test.js.map +1 -0
- package/dist/__tests__/unit/agent.test.d.ts +2 -0
- package/dist/__tests__/unit/agent.test.d.ts.map +1 -0
- package/dist/__tests__/unit/agent.test.js +143 -0
- package/dist/__tests__/unit/agent.test.js.map +1 -0
- package/dist/__tests__/unit/cache-key.test.d.ts +5 -0
- package/dist/__tests__/unit/cache-key.test.d.ts.map +1 -0
- package/dist/__tests__/unit/cache-key.test.js +145 -0
- package/dist/__tests__/unit/cache-key.test.js.map +1 -0
- package/dist/__tests__/unit/cache.test.d.ts +5 -0
- package/dist/__tests__/unit/cache.test.d.ts.map +1 -0
- package/dist/__tests__/unit/cache.test.js +132 -0
- package/dist/__tests__/unit/cache.test.js.map +1 -0
- package/dist/__tests__/unit/context.test.d.ts +2 -0
- package/dist/__tests__/unit/context.test.d.ts.map +1 -0
- package/dist/__tests__/unit/context.test.js +220 -0
- package/dist/__tests__/unit/context.test.js.map +1 -0
- package/dist/__tests__/unit/decorators.test.d.ts +2 -0
- package/dist/__tests__/unit/decorators.test.d.ts.map +1 -0
- package/dist/__tests__/unit/decorators.test.js +162 -0
- package/dist/__tests__/unit/decorators.test.js.map +1 -0
- package/dist/__tests__/unit/introspection-tools.test.d.ts +5 -0
- package/dist/__tests__/unit/introspection-tools.test.d.ts.map +1 -0
- package/dist/__tests__/unit/introspection-tools.test.js +191 -0
- package/dist/__tests__/unit/introspection-tools.test.js.map +1 -0
- package/dist/__tests__/unit/logger.test.d.ts +2 -0
- package/dist/__tests__/unit/logger.test.d.ts.map +1 -0
- package/dist/__tests__/unit/logger.test.js +241 -0
- package/dist/__tests__/unit/logger.test.js.map +1 -0
- package/dist/__tests__/unit/observable.test.d.ts +2 -0
- package/dist/__tests__/unit/observable.test.d.ts.map +1 -0
- package/dist/__tests__/unit/observable.test.js +251 -0
- package/dist/__tests__/unit/observable.test.js.map +1 -0
- package/dist/__tests__/unit/prompt.test.d.ts +2 -0
- package/dist/__tests__/unit/prompt.test.d.ts.map +1 -0
- package/dist/__tests__/unit/prompt.test.js +113 -0
- package/dist/__tests__/unit/prompt.test.js.map +1 -0
- package/dist/__tests__/unit/reflection.test.d.ts +5 -0
- package/dist/__tests__/unit/reflection.test.d.ts.map +1 -0
- package/dist/__tests__/unit/reflection.test.js +160 -0
- package/dist/__tests__/unit/reflection.test.js.map +1 -0
- package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts +2 -0
- package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts.map +1 -0
- package/dist/__tests__/unit/tree-debugger-incremental.test.js +136 -0
- package/dist/__tests__/unit/tree-debugger-incremental.test.js.map +1 -0
- package/dist/__tests__/unit/tree-debugger.test.d.ts +2 -0
- package/dist/__tests__/unit/tree-debugger.test.d.ts.map +1 -0
- package/dist/__tests__/unit/tree-debugger.test.js +69 -0
- package/dist/__tests__/unit/tree-debugger.test.js.map +1 -0
- package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts +2 -0
- package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts.map +1 -0
- package/dist/__tests__/unit/utils/workflow-error-utils.test.js +154 -0
- package/dist/__tests__/unit/utils/workflow-error-utils.test.js.map +1 -0
- package/dist/__tests__/unit/workflow-detachChild.test.d.ts +2 -0
- package/dist/__tests__/unit/workflow-detachChild.test.d.ts.map +1 -0
- package/dist/__tests__/unit/workflow-detachChild.test.js +76 -0
- package/dist/__tests__/unit/workflow-detachChild.test.js.map +1 -0
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts +2 -0
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts.map +1 -0
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js +122 -0
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js.map +1 -0
- package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts +2 -0
- package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts.map +1 -0
- package/dist/__tests__/unit/workflow-isDescendantOf.test.js +140 -0
- package/dist/__tests__/unit/workflow-isDescendantOf.test.js.map +1 -0
- package/dist/__tests__/unit/workflow.test.d.ts +2 -0
- package/dist/__tests__/unit/workflow.test.d.ts.map +1 -0
- package/dist/__tests__/unit/workflow.test.js +330 -0
- package/dist/__tests__/unit/workflow.test.js.map +1 -0
- package/dist/cache/cache-key.d.ts +66 -0
- package/dist/cache/cache-key.d.ts.map +1 -0
- package/dist/cache/cache-key.js +195 -0
- package/dist/cache/cache-key.js.map +1 -0
- package/dist/cache/cache.d.ts +104 -0
- package/dist/cache/cache.d.ts.map +1 -0
- package/dist/cache/cache.js +179 -0
- package/dist/cache/cache.js.map +1 -0
- package/{src/cache/index.ts → dist/cache/index.d.ts} +1 -1
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/core/agent.d.ts +112 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +426 -0
- package/dist/core/agent.js.map +1 -0
- package/{src/core/context.ts → dist/core/context.d.ts} +16 -67
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +80 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/event-tree.d.ts +72 -0
- package/dist/core/event-tree.d.ts.map +1 -0
- package/dist/core/event-tree.js +211 -0
- package/dist/core/event-tree.js.map +1 -0
- package/{src/core/factory.ts → dist/core/factory.d.ts} +6 -27
- package/dist/core/factory.d.ts.map +1 -0
- package/dist/core/factory.js +110 -0
- package/dist/core/factory.js.map +1 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +2 -10
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +50 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +91 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/mcp-handler.d.ts +69 -0
- package/dist/core/mcp-handler.d.ts.map +1 -0
- package/dist/core/mcp-handler.js +143 -0
- package/dist/core/mcp-handler.js.map +1 -0
- package/dist/core/prompt.d.ts +80 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +120 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/workflow-context.d.ts +57 -0
- package/dist/core/workflow-context.d.ts.map +1 -0
- package/dist/core/workflow-context.js +263 -0
- package/dist/core/workflow-context.js.map +1 -0
- package/dist/core/workflow.d.ts +241 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +464 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/debugger/index.d.ts +2 -0
- package/dist/debugger/index.d.ts.map +1 -0
- package/{src/debugger/index.ts → dist/debugger/index.js} +1 -0
- package/dist/debugger/index.js.map +1 -0
- package/dist/debugger/tree-debugger.d.ts +71 -0
- package/dist/debugger/tree-debugger.d.ts.map +1 -0
- package/dist/debugger/tree-debugger.js +198 -0
- package/dist/debugger/tree-debugger.js.map +1 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/{src/decorators/index.ts → dist/decorators/index.js} +1 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/observed-state.d.ts +32 -0
- package/dist/decorators/observed-state.d.ts.map +1 -0
- package/dist/decorators/observed-state.js +79 -0
- package/dist/decorators/observed-state.js.map +1 -0
- package/dist/decorators/step.d.ts +15 -0
- package/dist/decorators/step.d.ts.map +1 -0
- package/dist/decorators/step.js +110 -0
- package/dist/decorators/step.js.map +1 -0
- package/dist/decorators/task.d.ts +50 -0
- package/dist/decorators/task.d.ts.map +1 -0
- package/dist/decorators/task.js +118 -0
- package/dist/decorators/task.js.map +1 -0
- package/dist/examples/index.d.ts +3 -0
- package/dist/examples/index.d.ts.map +1 -0
- package/{src/examples/index.ts → dist/examples/index.js} +1 -0
- package/dist/examples/index.js.map +1 -0
- package/dist/examples/tdd-orchestrator.d.ts +15 -0
- package/dist/examples/tdd-orchestrator.d.ts.map +1 -0
- package/dist/examples/tdd-orchestrator.js +121 -0
- package/dist/examples/tdd-orchestrator.js.map +1 -0
- package/dist/examples/test-cycle-workflow.d.ts +14 -0
- package/dist/examples/test-cycle-workflow.d.ts.map +1 -0
- package/dist/examples/test-cycle-workflow.js +116 -0
- package/dist/examples/test-cycle-workflow.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/reflection/index.d.ts +5 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/{src/reflection/index.ts → dist/reflection/index.js} +1 -1
- package/dist/reflection/index.js.map +1 -0
- package/dist/reflection/reflection.d.ts +84 -0
- package/dist/reflection/reflection.d.ts.map +1 -0
- package/dist/reflection/reflection.js +329 -0
- package/dist/reflection/reflection.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/introspection.d.ts +165 -0
- package/dist/tools/introspection.d.ts.map +1 -0
- package/dist/tools/introspection.js +324 -0
- package/dist/tools/introspection.js.map +1 -0
- package/dist/types/agent.d.ts +66 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +6 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/decorators.d.ts +31 -0
- package/dist/types/decorators.d.ts.map +1 -0
- package/dist/types/decorators.js +2 -0
- package/dist/types/decorators.js.map +1 -0
- package/dist/types/error-strategy.d.ts +13 -0
- package/dist/types/error-strategy.d.ts.map +1 -0
- package/dist/types/error-strategy.js +2 -0
- package/dist/types/error-strategy.js.map +1 -0
- package/dist/types/error.d.ts +20 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +2 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/events.d.ts +87 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/logging.d.ts +24 -0
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/types/logging.js +2 -0
- package/dist/types/logging.js.map +1 -0
- package/dist/types/observer.d.ts +18 -0
- package/dist/types/observer.d.ts.map +1 -0
- package/dist/types/observer.js +2 -0
- package/dist/types/observer.js.map +1 -0
- package/dist/types/prompt.d.ts +31 -0
- package/dist/types/prompt.d.ts.map +1 -0
- package/dist/types/prompt.js +6 -0
- package/dist/types/prompt.js.map +1 -0
- package/dist/types/reflection.d.ts +96 -0
- package/dist/types/reflection.d.ts.map +1 -0
- package/dist/types/reflection.js +24 -0
- package/dist/types/reflection.js.map +1 -0
- package/dist/types/sdk-primitives.d.ts +118 -0
- package/dist/types/sdk-primitives.d.ts.map +1 -0
- package/dist/types/sdk-primitives.js +6 -0
- package/dist/types/sdk-primitives.js.map +1 -0
- package/{src/types/snapshot.ts → dist/types/snapshot.d.ts} +5 -5
- package/dist/types/snapshot.d.ts.map +1 -0
- package/dist/types/snapshot.js +2 -0
- package/dist/types/snapshot.js.map +1 -0
- package/dist/types/workflow-context.d.ts +139 -0
- package/dist/types/workflow-context.d.ts.map +1 -0
- package/dist/types/workflow-context.js +8 -0
- package/dist/types/workflow-context.js.map +1 -0
- package/dist/types/workflow.d.ts +30 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/dist/types/workflow.js +2 -0
- package/dist/types/workflow.js.map +1 -0
- package/dist/utils/id.d.ts +6 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +12 -0
- package/dist/utils/id.js.map +1 -0
- package/{src/utils/index.ts → dist/utils/index.d.ts} +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/observable.d.ts +54 -0
- package/dist/utils/observable.d.ts.map +1 -0
- package/dist/utils/observable.js +82 -0
- package/dist/utils/observable.js.map +1 -0
- package/dist/utils/workflow-error-utils.d.ts +22 -0
- package/dist/utils/workflow-error-utils.d.ts.map +1 -0
- package/dist/utils/workflow-error-utils.js +45 -0
- package/dist/utils/workflow-error-utils.js.map +1 -0
- package/package.json +7 -2
- package/.claude/settings.local.json +0 -9
- package/.claude/system_prompts/task-breakdown.md +0 -100
- package/PRPs/001-hierarchical-workflow-engine.md +0 -2438
- package/PRPs/PRDs/001-hierarchical-workflow-engine.md +0 -543
- package/PRPs/PRDs/002-agent-prompt.md +0 -390
- package/PRPs/PRDs/003-agent-prompt.md +0 -943
- package/PRPs/PRDs/004-agent-prompt.md +0 -1136
- package/PRPs/PRDs/tasks-001.json +0 -492
- package/PRPs/README.md +0 -83
- package/PRPs/templates/prp_base.md +0 -222
- package/docs/agent.md +0 -422
- package/docs/prompt.md +0 -419
- package/docs/workflow.md +0 -600
- package/examples/README.md +0 -244
- package/examples/examples/01-basic-workflow.ts +0 -100
- package/examples/examples/02-decorator-options.ts +0 -217
- package/examples/examples/03-parent-child.ts +0 -241
- package/examples/examples/04-observers-debugger.ts +0 -340
- package/examples/examples/05-error-handling.ts +0 -387
- package/examples/examples/06-concurrent-tasks.ts +0 -352
- package/examples/examples/07-agent-loops.ts +0 -432
- package/examples/examples/08-sdk-features.ts +0 -667
- package/examples/examples/09-reflection.ts +0 -573
- package/examples/examples/10-introspection.ts +0 -550
- package/examples/index.ts +0 -143
- package/examples/utils/helpers.ts +0 -57
- package/llms_full.txt +0 -5890
- package/plan/P1P2/PRP.md +0 -527
- package/plan/P1P2/research/LRU_CACHE_BEST_PRACTICES.md +0 -1929
- package/plan/P1P2/research/LRU_CACHE_CODE_PATTERNS.md +0 -857
- package/plan/P1P2/research/LRU_CACHE_INTEGRATION_GUIDE.md +0 -738
- package/plan/P1P2/research/LRU_CACHE_RESEARCH_INDEX.md +0 -424
- package/plan/P1P2/research/REFLECTION_INDEX.md +0 -291
- package/plan/P1P2/research/REFLECTION_RESEARCH_REPORT.md +0 -1342
- package/plan/P1P2/research/RESEARCH_SUMMARY.md +0 -342
- package/plan/P1P2/research/anthropic-sdk.md +0 -174
- package/plan/P1P2/research/async-local-storage.md +0 -200
- package/plan/P1P2/research/reflection-code-patterns.md +0 -1205
- package/plan/P1P2/research/reflection-decision-matrix.md +0 -421
- package/plan/P1P2/research/reflection-implementation-guide.md +0 -1341
- package/plan/P1P2/research/reflection-integration-guide.md +0 -834
- package/plan/P1P2/research/reflection-patterns.md +0 -1468
- package/plan/P1P2/research/reflection-quick-reference.md +0 -558
- package/plan/P1P2/research/zod-schema.md +0 -152
- package/plan/P3P4/PRP.md +0 -1388
- package/plan/P3P4/research/caching-lru.md +0 -116
- package/plan/P3P4/research/introspection-tools.md +0 -177
- package/plan/P3P4/research/reflection-patterns.md +0 -117
- package/plan/P4P5/PRP.md +0 -1136
- package/plan/P4P5/research/RESEARCH_SUMMARY.md +0 -151
- package/plan/architecture/external_deps.md +0 -358
- package/plan/architecture/system_context.md +0 -242
- package/plan/backlog.json +0 -867
- package/plan/research/INTROSPECTION_RESEARCH_SUMMARY.md +0 -378
- package/plan/research/README-INTROSPECTION.md +0 -352
- package/plan/research/agent-introspection-patterns.md +0 -1085
- package/plan/research/introspection-security-guide.md +0 -928
- package/plan/research/introspection-tool-examples.md +0 -875
- package/scripts/generate-llms-full.ts +0 -206
- package/src/__tests__/integration/agent-workflow.test.ts +0 -256
- package/src/__tests__/integration/tree-mirroring.test.ts +0 -114
- package/src/__tests__/unit/agent.test.ts +0 -169
- package/src/__tests__/unit/cache-key.test.ts +0 -182
- package/src/__tests__/unit/cache.test.ts +0 -172
- package/src/__tests__/unit/context.test.ts +0 -138
- package/src/__tests__/unit/decorators.test.ts +0 -100
- package/src/__tests__/unit/introspection-tools.test.ts +0 -277
- package/src/__tests__/unit/prompt.test.ts +0 -135
- package/src/__tests__/unit/reflection.test.ts +0 -210
- package/src/__tests__/unit/tree-debugger.test.ts +0 -85
- package/src/__tests__/unit/workflow.test.ts +0 -81
- package/src/cache/cache-key.ts +0 -244
- package/src/cache/cache.ts +0 -236
- package/src/core/agent.ts +0 -573
- package/src/core/event-tree.ts +0 -260
- package/src/core/logger.ts +0 -87
- package/src/core/mcp-handler.ts +0 -184
- package/src/core/prompt.ts +0 -150
- package/src/core/workflow-context.ts +0 -349
- package/src/core/workflow.ts +0 -302
- package/src/debugger/tree-debugger.ts +0 -210
- package/src/decorators/observed-state.ts +0 -95
- package/src/decorators/step.ts +0 -139
- package/src/decorators/task.ts +0 -96
- package/src/examples/tdd-orchestrator.ts +0 -65
- package/src/examples/test-cycle-workflow.ts +0 -64
- package/src/index.ts +0 -140
- package/src/reflection/reflection.ts +0 -407
- package/src/tools/index.ts +0 -36
- package/src/tools/introspection.ts +0 -464
- package/src/types/agent.ts +0 -90
- package/src/types/decorators.ts +0 -25
- package/src/types/error-strategy.ts +0 -13
- package/src/types/error.ts +0 -20
- package/src/types/events.ts +0 -74
- package/src/types/index.ts +0 -55
- package/src/types/logging.ts +0 -24
- package/src/types/observer.ts +0 -18
- package/src/types/prompt.ts +0 -40
- package/src/types/reflection.ts +0 -117
- package/src/types/sdk-primitives.ts +0 -128
- package/src/types/workflow-context.ts +0 -163
- package/src/types/workflow.ts +0 -37
- package/src/utils/id.ts +0 -11
- package/src/utils/observable.ts +0 -77
- package/tasks.json +0 -0
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -16
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
# AI Reflection and Self-Correction Research - Summary
|
|
2
|
-
|
|
3
|
-
## Research Completion Report
|
|
4
|
-
|
|
5
|
-
**Project**: Best practices for implementing AI reflection/self-correction patterns in agent orchestration systems
|
|
6
|
-
|
|
7
|
-
**Completion Date**: December 8, 2025
|
|
8
|
-
|
|
9
|
-
**Total Research Content**: 24,500+ words across 8 comprehensive documents
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Deliverables
|
|
14
|
-
|
|
15
|
-
### Core Documents Created
|
|
16
|
-
|
|
17
|
-
1. **REFLECTION_RESEARCH_REPORT.md** (45 KB, 9,500+ words)
|
|
18
|
-
- Comprehensive foundational research
|
|
19
|
-
- 11 major sections covering theory, implementation, and best practices
|
|
20
|
-
- Topics: reflection patterns, prompt templates, introspection tools, security, common pitfalls
|
|
21
|
-
- Research references and citations from 2024-2025
|
|
22
|
-
|
|
23
|
-
2. **reflection-implementation-guide.md** (37 KB, 5,200+ words)
|
|
24
|
-
- Production-ready code examples
|
|
25
|
-
- 7 implementation patterns in Python and TypeScript
|
|
26
|
-
- Loop detection systems
|
|
27
|
-
- Token budget management
|
|
28
|
-
- Security validation frameworks
|
|
29
|
-
- Hierarchical reflection systems
|
|
30
|
-
- Integration examples
|
|
31
|
-
|
|
32
|
-
3. **reflection-quick-reference.md** (14 KB, 2,100+ words)
|
|
33
|
-
- Decision trees for when to use reflection
|
|
34
|
-
- Approach selection matrices
|
|
35
|
-
- 4 configuration profiles (Speed, Quality, Balanced, Safety-Critical)
|
|
36
|
-
- Prompt templates with complexity levels
|
|
37
|
-
- Performance benchmarks
|
|
38
|
-
- Troubleshooting guides
|
|
39
|
-
- Security checklists
|
|
40
|
-
|
|
41
|
-
4. **REFLECTION_INDEX.md** (9.1 KB, 1,200+ words)
|
|
42
|
-
- Navigation guide for the research package
|
|
43
|
-
- Quick-start guides by use case
|
|
44
|
-
- Key research findings summary
|
|
45
|
-
- FAQ section
|
|
46
|
-
- 5-minute getting started guide
|
|
47
|
-
|
|
48
|
-
### Additional Research Documents (Pre-existing)
|
|
49
|
-
|
|
50
|
-
5. **reflection-patterns.md** - Detailed pattern analysis
|
|
51
|
-
6. **reflection-decision-matrix.md** - Advanced decision frameworks
|
|
52
|
-
7. **reflection-integration-guide.md** - Framework-specific integration
|
|
53
|
-
8. **reflection-code-patterns.md** - Additional code patterns
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## Research Coverage
|
|
58
|
-
|
|
59
|
-
### 1. Reflection Patterns for LLM Agents
|
|
60
|
-
|
|
61
|
-
Covered 6 major approaches:
|
|
62
|
-
- Automatic retry with self-correction
|
|
63
|
-
- Multi-level reflection (prompt, agent, workflow, system levels)
|
|
64
|
-
- Error analysis and context injection
|
|
65
|
-
- Reflexion framework (evidence-grounded)
|
|
66
|
-
- Language Agent Tree Search (LATS) with Monte Carlo search
|
|
67
|
-
- Spontaneous Self-Correction (SPOC) - 2025 research
|
|
68
|
-
|
|
69
|
-
### 2. Implementation Patterns
|
|
70
|
-
|
|
71
|
-
Documented patterns:
|
|
72
|
-
- Reflection prompt templates (5 main templates, task-specific variations)
|
|
73
|
-
- Maximum retry limits and exponential backoff strategies
|
|
74
|
-
- State preservation during reflection cycles
|
|
75
|
-
- Token budget allocation and management
|
|
76
|
-
- Loop detection mechanisms (4 strategies)
|
|
77
|
-
- Context window management and compression
|
|
78
|
-
|
|
79
|
-
### 3. Introspection Tools for Agents
|
|
80
|
-
|
|
81
|
-
Defined 6 core introspection tools:
|
|
82
|
-
- `get_agent_metadata` - Agent capabilities and status
|
|
83
|
-
- `read_parent_context` - Parent goals and constraints
|
|
84
|
-
- `read_sibling_context` - Sibling agents' work
|
|
85
|
-
- `read_execution_history` - Own prior attempts
|
|
86
|
-
- `read_workflow_state` - Overall progress
|
|
87
|
-
- `check_resource_constraints` - Token/time remaining
|
|
88
|
-
|
|
89
|
-
Security model for introspection:
|
|
90
|
-
- Role-based access control (RBAC)
|
|
91
|
-
- Credential masking and filtering
|
|
92
|
-
- Execution isolation
|
|
93
|
-
- Permission matrices
|
|
94
|
-
|
|
95
|
-
### 4. Best Practices from Existing Frameworks
|
|
96
|
-
|
|
97
|
-
Research integrated from:
|
|
98
|
-
- **LangChain/LangGraph**: Reflection loops with state management
|
|
99
|
-
- **CrewAI**: Hierarchical process with manager agent review
|
|
100
|
-
- **Reflexion Paper**: Evidence-grounded feedback mechanisms
|
|
101
|
-
- **AutoGPT**: Error analysis and feedback loops
|
|
102
|
-
- **OpenAI/Anthropic**: Built-in reasoning and reflection
|
|
103
|
-
|
|
104
|
-
### 5. Common Pitfalls and Prevention
|
|
105
|
-
|
|
106
|
-
Documented 4 major pitfalls with solutions:
|
|
107
|
-
1. **Infinite Loops**: Detection strategies and recovery mechanisms
|
|
108
|
-
2. **Context Window Bloat**: Compression, summarization, external memory
|
|
109
|
-
3. **Diminishing Returns**: Quality threshold and stopping conditions
|
|
110
|
-
4. **Stale Context**: Timestamp validation and refresh strategies
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
## Key Findings from Research
|
|
115
|
-
|
|
116
|
-
### Finding 1: External Feedback is Critical
|
|
117
|
-
- With external feedback: 80-95% effectiveness
|
|
118
|
-
- Without external feedback: 30-50% effectiveness
|
|
119
|
-
- Implication: Always implement feedback mechanisms before reflection
|
|
120
|
-
|
|
121
|
-
### Finding 2: Minimal Signals Help
|
|
122
|
-
- Simple "Try again" signals improve performance 60%+
|
|
123
|
-
- Minimal "Wait" triggers reduce self-correction blind spots by 89.3%
|
|
124
|
-
- Implication: Even basic reflection is worthwhile
|
|
125
|
-
|
|
126
|
-
### Finding 3: 2-3 Cycles is Optimal
|
|
127
|
-
- Diminishing returns after 3 cycles
|
|
128
|
-
- Sweet spot: 2-3 reflection attempts
|
|
129
|
-
- Additional cycles add cost with minimal benefit
|
|
130
|
-
|
|
131
|
-
### Finding 4: Information Richness Matters
|
|
132
|
-
- Best: Instructions + Explanation + Solution
|
|
133
|
-
- Good: Evidence-grounded with citations
|
|
134
|
-
- Acceptable: Advice/suggestions
|
|
135
|
-
- Limited: Keywords or simple retry
|
|
136
|
-
|
|
137
|
-
### Finding 5: Multi-Agent Reflection Outperforms Self-Reflection
|
|
138
|
-
- Self-correction blind spot affects ~64.5% of non-reasoning models
|
|
139
|
-
- Multi-agent (critic + generator) shows 90% effectiveness
|
|
140
|
-
- Tool-interactive with validation shows 85% effectiveness
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
## Security Considerations Documented
|
|
145
|
-
|
|
146
|
-
### Attack Vectors Addressed
|
|
147
|
-
1. Prompt injection via reflection feedback
|
|
148
|
-
2. Credential exposure in execution history
|
|
149
|
-
3. Unauthorized context access across agents
|
|
150
|
-
4. Agent context leakage
|
|
151
|
-
5. Denial of service via loop-based attacks
|
|
152
|
-
|
|
153
|
-
### Defense Patterns
|
|
154
|
-
1. Plan-Then-Execute pattern (action whitelist)
|
|
155
|
-
2. Action-Selector pattern (hardcoded safe actions)
|
|
156
|
-
3. Dual-Agent quarantine model (Privileged + Quarantined)
|
|
157
|
-
4. Input sanitization and validation
|
|
158
|
-
5. Role-based access control (RBAC)
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## Code Examples Provided
|
|
163
|
-
|
|
164
|
-
### Python Examples
|
|
165
|
-
- Reflexion pattern with evidence grounding (class-based)
|
|
166
|
-
- Loop detection with similarity analysis
|
|
167
|
-
- Context window management with budget allocation
|
|
168
|
-
- Hierarchical reflection framework with multi-level support
|
|
169
|
-
- Error analysis and context injection patterns
|
|
170
|
-
|
|
171
|
-
### TypeScript Examples
|
|
172
|
-
- Basic reflection loop with quality evaluation
|
|
173
|
-
- Loop detection system with 4 detection strategies
|
|
174
|
-
- Secure reflection executor with input validation
|
|
175
|
-
- Metrics collection and performance tracking
|
|
176
|
-
- Orchestration integration example
|
|
177
|
-
|
|
178
|
-
All examples include:
|
|
179
|
-
- Error handling
|
|
180
|
-
- Type safety
|
|
181
|
-
- Security validation
|
|
182
|
-
- Production-ready structure
|
|
183
|
-
- Integration hooks
|
|
184
|
-
|
|
185
|
-
---
|
|
186
|
-
|
|
187
|
-
## Configuration Frameworks
|
|
188
|
-
|
|
189
|
-
### Provided Profiles
|
|
190
|
-
1. **Speed-Optimized**: max_attempts=1, minimal overhead
|
|
191
|
-
2. **Quality-Optimized**: max_attempts=3, full reflection
|
|
192
|
-
3. **Balanced** (Recommended): max_attempts=2, trade-off
|
|
193
|
-
4. **Safety-Critical**: max_attempts=3, strict validation
|
|
194
|
-
|
|
195
|
-
### Configuration Parameters
|
|
196
|
-
- max_attempts: 1-3 (typically 2-3)
|
|
197
|
-
- reflection_style: minimal, self_critique, evidence_grounded, multi_agent
|
|
198
|
-
- token_budget: 20K-150K depending on task
|
|
199
|
-
- timeout: 10s-120s depending on complexity
|
|
200
|
-
- quality_threshold: 0.8 (80% good enough)
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## Quick Reference Materials
|
|
205
|
-
|
|
206
|
-
Created for fast decision-making:
|
|
207
|
-
1. Decision tree (1 page) - Determine if reflection is needed
|
|
208
|
-
2. Approach selection matrix (by task type)
|
|
209
|
-
3. Prompt templates (4 complexity levels)
|
|
210
|
-
4. Performance benchmarks (code generation, analysis, writing)
|
|
211
|
-
5. Token budget calculator (with examples)
|
|
212
|
-
6. Stopping conditions checklist (6 conditions)
|
|
213
|
-
7. Security checklist (10 items)
|
|
214
|
-
8. Integration checklist (12 items)
|
|
215
|
-
9. Troubleshooting guide (8 common issues)
|
|
216
|
-
10. FAQ (7 key questions)
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## Sources and References
|
|
221
|
-
|
|
222
|
-
Research synthesized from:
|
|
223
|
-
- **Academic Papers** (2024-2025):
|
|
224
|
-
- Self-Reflection in LLM Agents (effectiveness study)
|
|
225
|
-
- When Can LLMs Actually Correct Their Own Mistakes (critical survey)
|
|
226
|
-
- Self-Correction Bench (blind spot analysis)
|
|
227
|
-
- Design Patterns for Securing LLM Agents (prompt injection defense)
|
|
228
|
-
|
|
229
|
-
- **Framework Documentation**:
|
|
230
|
-
- LangGraph/LangChain reflection tutorials
|
|
231
|
-
- CrewAI hierarchical process documentation
|
|
232
|
-
- OpenAI API documentation
|
|
233
|
-
- Anthropic Claude documentation
|
|
234
|
-
|
|
235
|
-
- **Industry Sources**:
|
|
236
|
-
- OWASP Gen AI Security Project
|
|
237
|
-
- 2025 LLM security guidelines
|
|
238
|
-
- DeepLearning.AI agentic patterns course
|
|
239
|
-
- IBM, Microsoft, Google DeepMind research
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
|
-
## How to Use This Research
|
|
244
|
-
|
|
245
|
-
### For Implementation
|
|
246
|
-
1. Start with REFLECTION_INDEX.md (navigation guide)
|
|
247
|
-
2. Use decision tree in reflection-quick-reference.md
|
|
248
|
-
3. Select approach from matrix
|
|
249
|
-
4. Copy code from reflection-implementation-guide.md
|
|
250
|
-
5. Review security considerations in REFLECTION_RESEARCH_REPORT.md
|
|
251
|
-
|
|
252
|
-
### For Learning
|
|
253
|
-
1. Read Section 1 of REFLECTION_RESEARCH_REPORT.md (concepts)
|
|
254
|
-
2. Study framework examples (Section 5)
|
|
255
|
-
3. Review code patterns (reflection-implementation-guide.md)
|
|
256
|
-
4. Understand pitfalls (Section 5 of main report)
|
|
257
|
-
|
|
258
|
-
### For Maintenance
|
|
259
|
-
1. Reference monitoring section (Section 9)
|
|
260
|
-
2. Use metrics collection code (reflection-implementation-guide.md Section 6)
|
|
261
|
-
3. Create dashboard based on essential metrics
|
|
262
|
-
4. Monitor for issues using troubleshooting guide
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Next Steps for Your Project
|
|
267
|
-
|
|
268
|
-
Based on this research, recommend:
|
|
269
|
-
|
|
270
|
-
1. **Architecture Design**
|
|
271
|
-
- Choose reflection approach based on use cases
|
|
272
|
-
- Plan introspection tool access model
|
|
273
|
-
- Design security boundaries
|
|
274
|
-
|
|
275
|
-
2. **Implementation**
|
|
276
|
-
- Select configuration profile (Balanced recommended)
|
|
277
|
-
- Implement loop detection first
|
|
278
|
-
- Add token budgeting
|
|
279
|
-
- Integrate with LLM client
|
|
280
|
-
|
|
281
|
-
3. **Testing**
|
|
282
|
-
- Unit test reflection patterns
|
|
283
|
-
- Load test token budgets
|
|
284
|
-
- Security test with adversarial inputs
|
|
285
|
-
- Measure quality improvements
|
|
286
|
-
|
|
287
|
-
4. **Monitoring**
|
|
288
|
-
- Set up metrics collection
|
|
289
|
-
- Create performance dashboard
|
|
290
|
-
- Define alerting rules
|
|
291
|
-
- Track ROI of reflection
|
|
292
|
-
|
|
293
|
-
5. **Documentation**
|
|
294
|
-
- Document reflection configuration per task
|
|
295
|
-
- Document introspection access policies
|
|
296
|
-
- Create runbooks for common issues
|
|
297
|
-
- Train teams on system usage
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
|
|
301
|
-
## Research Quality Metrics
|
|
302
|
-
|
|
303
|
-
- Total words: 24,500+
|
|
304
|
-
- Number of code examples: 15+
|
|
305
|
-
- Sections with prompts: 5 major sections
|
|
306
|
-
- Security patterns documented: 5
|
|
307
|
-
- Implementation patterns: 7
|
|
308
|
-
- Configuration profiles: 4
|
|
309
|
-
- Decision matrices: 2+
|
|
310
|
-
- Quick reference guides: 10+
|
|
311
|
-
- Code completeness: Production-ready
|
|
312
|
-
|
|
313
|
-
---
|
|
314
|
-
|
|
315
|
-
## Document Access
|
|
316
|
-
|
|
317
|
-
All research files are located at:
|
|
318
|
-
**`./plan/P1P2/research/`**
|
|
319
|
-
|
|
320
|
-
Files:
|
|
321
|
-
- REFLECTION_RESEARCH_REPORT.md
|
|
322
|
-
- reflection-implementation-guide.md
|
|
323
|
-
- reflection-quick-reference.md
|
|
324
|
-
- REFLECTION_INDEX.md
|
|
325
|
-
- reflection-patterns.md
|
|
326
|
-
- reflection-decision-matrix.md
|
|
327
|
-
- reflection-integration-guide.md
|
|
328
|
-
- reflection-code-patterns.md
|
|
329
|
-
|
|
330
|
-
---
|
|
331
|
-
|
|
332
|
-
## Version and Date
|
|
333
|
-
|
|
334
|
-
- **Package Version**: 1.0
|
|
335
|
-
- **Created**: December 8, 2025
|
|
336
|
-
- **Based on Research**: 2024-2025 papers and frameworks
|
|
337
|
-
- **Status**: Complete and ready for implementation
|
|
338
|
-
|
|
339
|
-
---
|
|
340
|
-
|
|
341
|
-
This comprehensive research package provides everything needed to understand and implement AI reflection and self-correction patterns in agent orchestration systems. The combination of theory, practical code, decision frameworks, and security guidance creates a complete resource for building reliable, efficient, and safe reflection systems.
|
|
342
|
-
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
# Anthropic SDK Research
|
|
2
|
-
|
|
3
|
-
## Official Documentation URLs
|
|
4
|
-
|
|
5
|
-
| Resource | URL |
|
|
6
|
-
|----------|-----|
|
|
7
|
-
| **NPM Package** | https://www.npmjs.com/package/@anthropic-ai/sdk |
|
|
8
|
-
| **GitHub Repository** | https://github.com/anthropics/anthropic-sdk-typescript |
|
|
9
|
-
| **API Reference** | https://github.com/anthropics/anthropic-sdk-typescript/blob/main/api.md |
|
|
10
|
-
| **Helpers Documentation** | https://github.com/anthropics/anthropic-sdk-typescript/blob/main/helpers.md |
|
|
11
|
-
| **Tool Use Guide** | https://platform.claude.com/docs/en/agents-and-tools/tool-use/implement-tool-use |
|
|
12
|
-
| **Streaming Messages** | https://platform.claude.com/docs/en/api/messages-streaming |
|
|
13
|
-
|
|
14
|
-
## Key TypeScript Interfaces
|
|
15
|
-
|
|
16
|
-
### MessageCreateParams
|
|
17
|
-
```typescript
|
|
18
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
19
|
-
|
|
20
|
-
const params: Anthropic.MessageCreateParams = {
|
|
21
|
-
model: 'claude-sonnet-4-20250514',
|
|
22
|
-
max_tokens: 1024,
|
|
23
|
-
messages: [{ role: 'user', content: 'Hello, Claude' }],
|
|
24
|
-
system?: string,
|
|
25
|
-
tools?: Tool[],
|
|
26
|
-
temperature?: number,
|
|
27
|
-
stop_sequences?: string[],
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Message (Response)
|
|
32
|
-
```typescript
|
|
33
|
-
interface Message {
|
|
34
|
-
id: string;
|
|
35
|
-
type: 'message';
|
|
36
|
-
role: 'assistant';
|
|
37
|
-
model: string;
|
|
38
|
-
content: ContentBlock[];
|
|
39
|
-
stop_reason: 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence';
|
|
40
|
-
stop_sequence: string | null;
|
|
41
|
-
usage: {
|
|
42
|
-
input_tokens: number;
|
|
43
|
-
output_tokens: number;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### ContentBlock Types
|
|
49
|
-
```typescript
|
|
50
|
-
type ContentBlock = TextBlock | ToolUseBlock;
|
|
51
|
-
|
|
52
|
-
interface TextBlock {
|
|
53
|
-
type: 'text';
|
|
54
|
-
text: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface ToolUseBlock {
|
|
58
|
-
type: 'tool_use';
|
|
59
|
-
id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
input: Record<string, unknown>;
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Tool Definition
|
|
66
|
-
```typescript
|
|
67
|
-
interface Tool {
|
|
68
|
-
name: string;
|
|
69
|
-
description: string;
|
|
70
|
-
input_schema: {
|
|
71
|
-
type: 'object';
|
|
72
|
-
properties: Record<string, unknown>;
|
|
73
|
-
required?: string[];
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Tool Use Pattern
|
|
79
|
-
|
|
80
|
-
### Define Tools
|
|
81
|
-
```typescript
|
|
82
|
-
const tools: Anthropic.Tool[] = [{
|
|
83
|
-
name: 'get_weather',
|
|
84
|
-
description: 'Get the current weather in a given location',
|
|
85
|
-
input_schema: {
|
|
86
|
-
type: 'object',
|
|
87
|
-
properties: {
|
|
88
|
-
location: { type: 'string', description: 'City name' }
|
|
89
|
-
},
|
|
90
|
-
required: ['location']
|
|
91
|
-
}
|
|
92
|
-
}];
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Handle Tool Use Response
|
|
96
|
-
```typescript
|
|
97
|
-
if (response.stop_reason === 'tool_use') {
|
|
98
|
-
const toolUses = response.content.filter(
|
|
99
|
-
(block) => block.type === 'tool_use'
|
|
100
|
-
) as Anthropic.ToolUseBlock[];
|
|
101
|
-
|
|
102
|
-
// Execute tools and return results
|
|
103
|
-
const toolResults = toolUses.map(toolUse => ({
|
|
104
|
-
type: 'tool_result' as const,
|
|
105
|
-
tool_use_id: toolUse.id,
|
|
106
|
-
content: executeToolAndGetResult(toolUse)
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
// Continue conversation with tool results
|
|
110
|
-
const finalResponse = await client.messages.create({
|
|
111
|
-
model: 'claude-sonnet-4-20250514',
|
|
112
|
-
max_tokens: 1024,
|
|
113
|
-
tools,
|
|
114
|
-
messages: [
|
|
115
|
-
{ role: 'user', content: originalMessage },
|
|
116
|
-
{ role: 'assistant', content: response.content },
|
|
117
|
-
{ role: 'user', content: toolResults }
|
|
118
|
-
]
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Streaming API
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
const stream = await client.messages.stream({
|
|
127
|
-
model: 'claude-sonnet-4-20250514',
|
|
128
|
-
max_tokens: 1024,
|
|
129
|
-
messages: [{ role: 'user', content: 'Hello' }]
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
for await (const event of stream) {
|
|
133
|
-
switch (event.type) {
|
|
134
|
-
case 'message_start':
|
|
135
|
-
case 'content_block_start':
|
|
136
|
-
case 'content_block_delta':
|
|
137
|
-
case 'content_block_stop':
|
|
138
|
-
case 'message_delta':
|
|
139
|
-
case 'message_stop':
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Or use helper methods
|
|
144
|
-
for await (const text of stream.textStream) {
|
|
145
|
-
process.stdout.write(text);
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## Error Handling
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
153
|
-
|
|
154
|
-
const client = new Anthropic({
|
|
155
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
156
|
-
maxRetries: 2
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
const response = await client.messages.create(params);
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if (error instanceof Anthropic.RateLimitError) {
|
|
163
|
-
// Handle rate limiting with retry-after header
|
|
164
|
-
} else if (error instanceof Anthropic.APIError) {
|
|
165
|
-
// Handle API errors
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## SDK Requirements
|
|
171
|
-
|
|
172
|
-
- **TypeScript**: 4.9+
|
|
173
|
-
- **Node.js**: 18+ (20 LTS recommended)
|
|
174
|
-
- **Package Version**: @anthropic-ai/sdk@^0.71.1
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
# AsyncLocalStorage Research
|
|
2
|
-
|
|
3
|
-
## Official Documentation URLs
|
|
4
|
-
|
|
5
|
-
| Resource | URL |
|
|
6
|
-
|----------|-----|
|
|
7
|
-
| **Node.js Async Context** | https://nodejs.org/api/async_context.html |
|
|
8
|
-
| **async_hooks Module** | https://nodejs.org/api/async_hooks.html |
|
|
9
|
-
|
|
10
|
-
## Core API Methods
|
|
11
|
-
|
|
12
|
-
### Creating Instance
|
|
13
|
-
```typescript
|
|
14
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
15
|
-
|
|
16
|
-
interface WorkflowContext {
|
|
17
|
-
executionId: string;
|
|
18
|
-
agentId: string;
|
|
19
|
-
stepName: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const workflowContext = new AsyncLocalStorage<WorkflowContext>();
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Establishing Context with .run()
|
|
26
|
-
```typescript
|
|
27
|
-
const result = await workflowContext.run(
|
|
28
|
-
{ executionId: 'exec-123', agentId: 'agent-1', stepName: 'init' },
|
|
29
|
-
async () => {
|
|
30
|
-
// Context is active here and in all nested async calls
|
|
31
|
-
const store = workflowContext.getStore();
|
|
32
|
-
console.log(store.executionId); // 'exec-123'
|
|
33
|
-
|
|
34
|
-
await someAsyncOperation(); // Context propagates automatically
|
|
35
|
-
return 'completed';
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Accessing Context with .getStore()
|
|
41
|
-
```typescript
|
|
42
|
-
function doSomething() {
|
|
43
|
-
const store = workflowContext.getStore();
|
|
44
|
-
if (store === undefined) {
|
|
45
|
-
throw new Error('Called outside workflow context');
|
|
46
|
-
}
|
|
47
|
-
console.log(`Execution: ${store.executionId}`);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Other Methods
|
|
52
|
-
```typescript
|
|
53
|
-
// enterWith - persist context for sync execution
|
|
54
|
-
workflowContext.enterWith(store);
|
|
55
|
-
|
|
56
|
-
// exit - run code outside context
|
|
57
|
-
workflowContext.exit(() => {
|
|
58
|
-
workflowContext.getStore(); // undefined
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// snapshot - capture context for later use
|
|
62
|
-
const captured = workflowContext.run(123, () =>
|
|
63
|
-
workflowContext.snapshot()
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// disable - disable instance
|
|
67
|
-
workflowContext.disable();
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Usage Pattern for Agent/Prompt Context
|
|
71
|
-
|
|
72
|
-
### Workflow Step Context Propagation
|
|
73
|
-
```typescript
|
|
74
|
-
const workflowContext = new AsyncLocalStorage<WorkflowContext>();
|
|
75
|
-
|
|
76
|
-
// In workflow orchestrator
|
|
77
|
-
async function executeWorkflow(workflow: Workflow) {
|
|
78
|
-
const context: WorkflowContext = {
|
|
79
|
-
executionId: generateId(),
|
|
80
|
-
workflowId: workflow.id,
|
|
81
|
-
agentId: workflow.agentId,
|
|
82
|
-
timestamp: Date.now()
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return workflowContext.run(context, async () => {
|
|
86
|
-
// All nested calls automatically inherit context
|
|
87
|
-
await workflow.execute();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// In Agent.prompt() - automatically has access to context
|
|
92
|
-
class Agent {
|
|
93
|
-
async prompt(message: string): Promise<string> {
|
|
94
|
-
const context = workflowContext.getStore();
|
|
95
|
-
if (!context) {
|
|
96
|
-
// Standalone call - no workflow context
|
|
97
|
-
return await this.callLLMStandalone(message);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Automatically includes execution context
|
|
101
|
-
return await this.callLLMWithContext(message, context);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Nested Context Updates
|
|
107
|
-
```typescript
|
|
108
|
-
async function executeStep(step: WorkflowStep, parentContext: WorkflowContext) {
|
|
109
|
-
const stepContext: WorkflowContext = {
|
|
110
|
-
...parentContext,
|
|
111
|
-
stepName: step.name,
|
|
112
|
-
metadata: {
|
|
113
|
-
...parentContext.metadata,
|
|
114
|
-
stepStartTime: Date.now()
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
return workflowContext.run(stepContext, () => step.execute());
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
## Best Practices
|
|
123
|
-
|
|
124
|
-
### Performance
|
|
125
|
-
- Overhead is < 10%, acceptable for most applications
|
|
126
|
-
- Do NOT create more than 10-15 instances per application
|
|
127
|
-
- Create ONE global instance per logical context type
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
// Good: Single shared instance
|
|
131
|
-
export const workflowContext = new AsyncLocalStorage<WorkflowContext>();
|
|
132
|
-
|
|
133
|
-
// Bad: Creating instances per request
|
|
134
|
-
const context = new AsyncLocalStorage(); // Don't do this
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Error Handling
|
|
138
|
-
```typescript
|
|
139
|
-
// Errors propagate correctly
|
|
140
|
-
try {
|
|
141
|
-
workflowContext.run({ data: 'test' }, () => {
|
|
142
|
-
throw new Error('Something went wrong');
|
|
143
|
-
});
|
|
144
|
-
} catch (e) {
|
|
145
|
-
// Error thrown, context auto-exits
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Always check for undefined
|
|
149
|
-
function requireContext<T>(als: AsyncLocalStorage<T>, op: string): T {
|
|
150
|
-
const store = als.getStore();
|
|
151
|
-
if (store === undefined) {
|
|
152
|
-
throw new Error(`${op} called outside context`);
|
|
153
|
-
}
|
|
154
|
-
return store;
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### TypeScript Integration
|
|
159
|
-
```typescript
|
|
160
|
-
export const executionContext = new AsyncLocalStorage<ExecutionContext>();
|
|
161
|
-
|
|
162
|
-
// Type-safe getter
|
|
163
|
-
export function getExecutionContext(): ExecutionContext {
|
|
164
|
-
const context = executionContext.getStore();
|
|
165
|
-
if (!context) {
|
|
166
|
-
throw new Error('Execution context not available');
|
|
167
|
-
}
|
|
168
|
-
return context;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Type-safe runner
|
|
172
|
-
export async function runInContext<T>(
|
|
173
|
-
context: ExecutionContext,
|
|
174
|
-
fn: () => Promise<T>
|
|
175
|
-
): Promise<T> {
|
|
176
|
-
return executionContext.run(context, fn);
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## Testing Patterns
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
describe('Agent with Context', () => {
|
|
184
|
-
it('should have access to execution context', async () => {
|
|
185
|
-
const testContext = { executionId: 'test-123', agentId: 'agent-1' };
|
|
186
|
-
|
|
187
|
-
const result = await executionContext.run(testContext, async () => {
|
|
188
|
-
return await agent.prompt('test message');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
expect(result).toBeDefined();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should throw when called outside context', async () => {
|
|
195
|
-
await expect(agent.prompt('test')).rejects.toThrow(
|
|
196
|
-
'Execution context not available'
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
```
|