@warlock.js/ai 4.1.1
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/README.md +72 -0
- package/cjs/index.cjs +8625 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/agent/agent-config.type.d.mts +160 -0
- package/esm/agent/agent-config.type.d.mts.map +1 -0
- package/esm/agent/agent-input-builder.mjs +111 -0
- package/esm/agent/agent-input-builder.mjs.map +1 -0
- package/esm/agent/agent-log-event.mjs +101 -0
- package/esm/agent/agent-log-event.mjs.map +1 -0
- package/esm/agent/agent-stream.d.mts +47 -0
- package/esm/agent/agent-stream.d.mts.map +1 -0
- package/esm/agent/agent-stream.mjs +82 -0
- package/esm/agent/agent-stream.mjs.map +1 -0
- package/esm/agent/agent-to-stream-event.mjs +86 -0
- package/esm/agent/agent-to-stream-event.mjs.map +1 -0
- package/esm/agent/agent.d.mts +38 -0
- package/esm/agent/agent.d.mts.map +1 -0
- package/esm/agent/agent.mjs +974 -0
- package/esm/agent/agent.mjs.map +1 -0
- package/esm/agent/index.d.mts +3 -0
- package/esm/agent/index.mjs +4 -0
- package/esm/agent/json-stream-guard.mjs +400 -0
- package/esm/agent/json-stream-guard.mjs.map +1 -0
- package/esm/ai.d.mts +64 -0
- package/esm/ai.d.mts.map +1 -0
- package/esm/ai.mjs +65 -0
- package/esm/ai.mjs.map +1 -0
- package/esm/config.d.mts +79 -0
- package/esm/config.d.mts.map +1 -0
- package/esm/config.mjs +43 -0
- package/esm/config.mjs.map +1 -0
- package/esm/contracts/agent/agent-options.type.d.mts +132 -0
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -0
- package/esm/contracts/agent/agent.contract.d.mts +92 -0
- package/esm/contracts/agent/agent.contract.d.mts.map +1 -0
- package/esm/contracts/agent/index.d.mts +2 -0
- package/esm/contracts/attachment.type.d.mts +100 -0
- package/esm/contracts/attachment.type.d.mts.map +1 -0
- package/esm/contracts/content-part.type.d.mts +55 -0
- package/esm/contracts/content-part.type.d.mts.map +1 -0
- package/esm/contracts/conversation-message.type.d.mts +51 -0
- package/esm/contracts/conversation-message.type.d.mts.map +1 -0
- package/esm/contracts/embedder.contract.d.mts +69 -0
- package/esm/contracts/embedder.contract.d.mts.map +1 -0
- package/esm/contracts/end.type.d.mts +53 -0
- package/esm/contracts/end.type.d.mts.map +1 -0
- package/esm/contracts/end.type.mjs +47 -0
- package/esm/contracts/end.type.mjs.map +1 -0
- package/esm/contracts/events/agent-events.type.d.mts +71 -0
- package/esm/contracts/events/agent-events.type.d.mts.map +1 -0
- package/esm/contracts/events/complete-event.type.d.mts +33 -0
- package/esm/contracts/events/complete-event.type.d.mts.map +1 -0
- package/esm/contracts/events/event-identity.type.d.mts +30 -0
- package/esm/contracts/events/event-identity.type.d.mts.map +1 -0
- package/esm/contracts/events/event-map.type.d.mts +80 -0
- package/esm/contracts/events/event-map.type.d.mts.map +1 -0
- package/esm/contracts/events/index.d.mts +7 -0
- package/esm/contracts/events/supervisor-events.type.d.mts +162 -0
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -0
- package/esm/contracts/events/usage-event.type.d.mts +39 -0
- package/esm/contracts/events/usage-event.type.d.mts.map +1 -0
- package/esm/contracts/events/workflow-events.type.d.mts +51 -0
- package/esm/contracts/events/workflow-events.type.d.mts.map +1 -0
- package/esm/contracts/executable.contract.d.mts +25 -0
- package/esm/contracts/executable.contract.d.mts.map +1 -0
- package/esm/contracts/finish-reason.type.d.mts +17 -0
- package/esm/contracts/finish-reason.type.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +63 -0
- package/esm/contracts/middleware/index.d.mts +3 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts +99 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts +34 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware.contract.d.mts +140 -0
- package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -0
- package/esm/contracts/model-tool-call-request.type.d.mts +58 -0
- package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -0
- package/esm/contracts/model.contract.d.mts +164 -0
- package/esm/contracts/model.contract.d.mts.map +1 -0
- package/esm/contracts/placeholders.type.d.mts +23 -0
- package/esm/contracts/placeholders.type.d.mts.map +1 -0
- package/esm/contracts/result/agent-result.type.d.mts +33 -0
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -0
- package/esm/contracts/result/attempt-entry.type.d.mts +40 -0
- package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.d.mts +137 -0
- package/esm/contracts/result/base-report.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.mjs +17 -0
- package/esm/contracts/result/base-report.type.mjs.map +1 -0
- package/esm/contracts/result/base-result.type.d.mts +26 -0
- package/esm/contracts/result/base-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execute-result.type.d.mts +40 -0
- package/esm/contracts/result/execute-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execution-report.type.d.mts +50 -0
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -0
- package/esm/contracts/result/index.d.mts +14 -0
- package/esm/contracts/result/llm-trip.type.d.mts +36 -0
- package/esm/contracts/result/llm-trip.type.d.mts.map +1 -0
- package/esm/contracts/result/model-pricing.type.d.mts +51 -0
- package/esm/contracts/result/model-pricing.type.d.mts.map +1 -0
- package/esm/contracts/result/session-send-result.type.d.mts +29 -0
- package/esm/contracts/result/session-send-result.type.d.mts.map +1 -0
- package/esm/contracts/result/step-result.type.d.mts +43 -0
- package/esm/contracts/result/step-result.type.d.mts.map +1 -0
- package/esm/contracts/result/supervisor-result.type.d.mts +86 -0
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -0
- package/esm/contracts/result/tool-call.type.d.mts +44 -0
- package/esm/contracts/result/tool-call.type.d.mts.map +1 -0
- package/esm/contracts/result/usage.type.d.mts +57 -0
- package/esm/contracts/result/usage.type.d.mts.map +1 -0
- package/esm/contracts/result/workflow-result.type.d.mts +45 -0
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -0
- package/esm/contracts/sdk-adapter.contract.d.mts +77 -0
- package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -0
- package/esm/contracts/stream/stream-event.type.d.mts +68 -0
- package/esm/contracts/stream/stream-event.type.d.mts.map +1 -0
- package/esm/contracts/stream/stream.contract.d.mts +61 -0
- package/esm/contracts/stream/stream.contract.d.mts.map +1 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts +78 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts +97 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts +189 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts +235 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts +124 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/index.d.mts +16 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts +254 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +117 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/next.type.d.mts +25 -0
- package/esm/contracts/supervisor/next.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/route-context.type.d.mts +91 -0
- package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts +67 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +356 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +90 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts +24 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +49 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +16 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts +126 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -0
- package/esm/contracts/system-prompt.contract.d.mts +118 -0
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -0
- package/esm/contracts/tool.contract.d.mts +161 -0
- package/esm/contracts/tool.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/index.d.mts +6 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts +17 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -0
- package/esm/contracts/workflow/retry-config.type.d.mts +19 -0
- package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -0
- package/esm/contracts/workflow/step.contract.d.mts +189 -0
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts +45 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts +24 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow.contract.d.mts +142 -0
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.d.mts +49 -0
- package/esm/errors/agent-cancelled-error.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.mjs +43 -0
- package/esm/errors/agent-cancelled-error.mjs.map +1 -0
- package/esm/errors/agent-execution-error.d.mts +32 -0
- package/esm/errors/agent-execution-error.d.mts.map +1 -0
- package/esm/errors/agent-execution-error.mjs +35 -0
- package/esm/errors/agent-execution-error.mjs.map +1 -0
- package/esm/errors/agent-max-trips-error.d.mts +45 -0
- package/esm/errors/agent-max-trips-error.d.mts.map +1 -0
- package/esm/errors/agent-max-trips-error.mjs +41 -0
- package/esm/errors/agent-max-trips-error.mjs.map +1 -0
- package/esm/errors/ai-error.d.mts +94 -0
- package/esm/errors/ai-error.d.mts.map +1 -0
- package/esm/errors/ai-error.mjs +68 -0
- package/esm/errors/ai-error.mjs.map +1 -0
- package/esm/errors/budget-exceeded-error.d.mts +41 -0
- package/esm/errors/budget-exceeded-error.d.mts.map +1 -0
- package/esm/errors/budget-exceeded-error.mjs +31 -0
- package/esm/errors/budget-exceeded-error.mjs.map +1 -0
- package/esm/errors/content-filter-error.d.mts +33 -0
- package/esm/errors/content-filter-error.d.mts.map +1 -0
- package/esm/errors/content-filter-error.mjs +28 -0
- package/esm/errors/content-filter-error.mjs.map +1 -0
- package/esm/errors/context-length-exceeded-error.d.mts +38 -0
- package/esm/errors/context-length-exceeded-error.d.mts.map +1 -0
- package/esm/errors/context-length-exceeded-error.mjs +31 -0
- package/esm/errors/context-length-exceeded-error.mjs.map +1 -0
- package/esm/errors/error-category.type.d.mts +30 -0
- package/esm/errors/error-category.type.d.mts.map +1 -0
- package/esm/errors/error-code.type.d.mts +19 -0
- package/esm/errors/error-code.type.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.d.mts +55 -0
- package/esm/errors/guardrail-violation-error.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.mjs +41 -0
- package/esm/errors/guardrail-violation-error.mjs.map +1 -0
- package/esm/errors/index.d.mts +29 -0
- package/esm/errors/index.mjs +29 -0
- package/esm/errors/invalid-request-error.d.mts +27 -0
- package/esm/errors/invalid-request-error.d.mts.map +1 -0
- package/esm/errors/invalid-request-error.mjs +31 -0
- package/esm/errors/invalid-request-error.mjs.map +1 -0
- package/esm/errors/max-iterations-error.d.mts +31 -0
- package/esm/errors/max-iterations-error.d.mts.map +1 -0
- package/esm/errors/max-iterations-error.mjs +32 -0
- package/esm/errors/max-iterations-error.mjs.map +1 -0
- package/esm/errors/max-steps-exceeded-error.d.mts +20 -0
- package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -0
- package/esm/errors/max-steps-exceeded-error.mjs +21 -0
- package/esm/errors/max-steps-exceeded-error.mjs.map +1 -0
- package/esm/errors/provider-auth-error.d.mts +22 -0
- package/esm/errors/provider-auth-error.d.mts.map +1 -0
- package/esm/errors/provider-auth-error.mjs +26 -0
- package/esm/errors/provider-auth-error.mjs.map +1 -0
- package/esm/errors/provider-error.d.mts +38 -0
- package/esm/errors/provider-error.d.mts.map +1 -0
- package/esm/errors/provider-error.mjs +42 -0
- package/esm/errors/provider-error.mjs.map +1 -0
- package/esm/errors/provider-rate-limit-error.d.mts +34 -0
- package/esm/errors/provider-rate-limit-error.d.mts.map +1 -0
- package/esm/errors/provider-rate-limit-error.mjs +31 -0
- package/esm/errors/provider-rate-limit-error.mjs.map +1 -0
- package/esm/errors/provider-timeout-error.d.mts +22 -0
- package/esm/errors/provider-timeout-error.d.mts.map +1 -0
- package/esm/errors/provider-timeout-error.mjs +26 -0
- package/esm/errors/provider-timeout-error.mjs.map +1 -0
- package/esm/errors/quota-exceeded-error.d.mts +36 -0
- package/esm/errors/quota-exceeded-error.d.mts.map +1 -0
- package/esm/errors/quota-exceeded-error.mjs +40 -0
- package/esm/errors/quota-exceeded-error.mjs.map +1 -0
- package/esm/errors/routing-error.d.mts +23 -0
- package/esm/errors/routing-error.d.mts.map +1 -0
- package/esm/errors/routing-error.mjs +23 -0
- package/esm/errors/routing-error.mjs.map +1 -0
- package/esm/errors/schema-validation-error.d.mts +40 -0
- package/esm/errors/schema-validation-error.d.mts.map +1 -0
- package/esm/errors/schema-validation-error.mjs +37 -0
- package/esm/errors/schema-validation-error.mjs.map +1 -0
- package/esm/errors/step-failed-error.d.mts +20 -0
- package/esm/errors/step-failed-error.d.mts.map +1 -0
- package/esm/errors/step-failed-error.mjs +19 -0
- package/esm/errors/step-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-cancelled-error.d.mts +29 -0
- package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -0
- package/esm/errors/supervisor-cancelled-error.mjs +29 -0
- package/esm/errors/supervisor-cancelled-error.mjs.map +1 -0
- package/esm/errors/supervisor-drift-error.d.mts +31 -0
- package/esm/errors/supervisor-drift-error.d.mts.map +1 -0
- package/esm/errors/supervisor-drift-error.mjs +30 -0
- package/esm/errors/supervisor-drift-error.mjs.map +1 -0
- package/esm/errors/supervisor-failed-error.d.mts +40 -0
- package/esm/errors/supervisor-failed-error.d.mts.map +1 -0
- package/esm/errors/supervisor-failed-error.mjs +43 -0
- package/esm/errors/supervisor-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-routing-error.d.mts +44 -0
- package/esm/errors/supervisor-routing-error.d.mts.map +1 -0
- package/esm/errors/supervisor-routing-error.mjs +39 -0
- package/esm/errors/supervisor-routing-error.mjs.map +1 -0
- package/esm/errors/tool-execution-error.d.mts +35 -0
- package/esm/errors/tool-execution-error.d.mts.map +1 -0
- package/esm/errors/tool-execution-error.mjs +32 -0
- package/esm/errors/tool-execution-error.mjs.map +1 -0
- package/esm/errors/workflow-cancelled-error.d.mts +23 -0
- package/esm/errors/workflow-cancelled-error.d.mts.map +1 -0
- package/esm/errors/workflow-cancelled-error.mjs +23 -0
- package/esm/errors/workflow-cancelled-error.mjs.map +1 -0
- package/esm/errors/workflow-drift-error.d.mts +25 -0
- package/esm/errors/workflow-drift-error.d.mts.map +1 -0
- package/esm/errors/workflow-drift-error.mjs +24 -0
- package/esm/errors/workflow-drift-error.mjs.map +1 -0
- package/esm/errors/workflow-error.d.mts +15 -0
- package/esm/errors/workflow-error.d.mts.map +1 -0
- package/esm/errors/workflow-error.mjs +18 -0
- package/esm/errors/workflow-error.mjs.map +1 -0
- package/esm/index.d.mts +137 -0
- package/esm/index.mjs +81 -0
- package/esm/middleware/builtins/budget.d.mts +103 -0
- package/esm/middleware/builtins/budget.d.mts.map +1 -0
- package/esm/middleware/builtins/budget.mjs +100 -0
- package/esm/middleware/builtins/budget.mjs.map +1 -0
- package/esm/middleware/builtins/guardrail.d.mts +92 -0
- package/esm/middleware/builtins/guardrail.d.mts.map +1 -0
- package/esm/middleware/builtins/guardrail.mjs +76 -0
- package/esm/middleware/builtins/guardrail.mjs.map +1 -0
- package/esm/middleware/builtins/semantic-cache.d.mts +106 -0
- package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -0
- package/esm/middleware/builtins/semantic-cache.mjs +149 -0
- package/esm/middleware/builtins/semantic-cache.mjs.map +1 -0
- package/esm/middleware/helpers/compose.d.mts +42 -0
- package/esm/middleware/helpers/compose.d.mts.map +1 -0
- package/esm/middleware/helpers/compose.mjs +52 -0
- package/esm/middleware/helpers/compose.mjs.map +1 -0
- package/esm/middleware/helpers/for-tool.d.mts +55 -0
- package/esm/middleware/helpers/for-tool.d.mts.map +1 -0
- package/esm/middleware/helpers/for-tool.mjs +80 -0
- package/esm/middleware/helpers/for-tool.mjs.map +1 -0
- package/esm/middleware/helpers/index.d.mts +2 -0
- package/esm/middleware/index.d.mts +8 -0
- package/esm/middleware/index.mjs +10 -0
- package/esm/middleware/pipeline.d.mts +70 -0
- package/esm/middleware/pipeline.d.mts.map +1 -0
- package/esm/middleware/pipeline.mjs +100 -0
- package/esm/middleware/pipeline.mjs.map +1 -0
- package/esm/middleware/utils/extract-user-text.d.mts +33 -0
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -0
- package/esm/middleware/utils/extract-user-text.mjs +40 -0
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -0
- package/esm/middleware/utils/index.d.mts +2 -0
- package/esm/middleware/utils/namespaced-state.d.mts +60 -0
- package/esm/middleware/utils/namespaced-state.d.mts.map +1 -0
- package/esm/middleware/utils/namespaced-state.mjs +60 -0
- package/esm/middleware/utils/namespaced-state.mjs.map +1 -0
- package/esm/mock/index.d.mts +4 -0
- package/esm/mock/index.mjs +5 -0
- package/esm/mock/mock-agent.d.mts +41 -0
- package/esm/mock/mock-agent.d.mts.map +1 -0
- package/esm/mock/mock-agent.mjs +39 -0
- package/esm/mock/mock-agent.mjs.map +1 -0
- package/esm/mock/mock-config.type.d.mts +31 -0
- package/esm/mock/mock-config.type.d.mts.map +1 -0
- package/esm/mock/mock-model.d.mts +94 -0
- package/esm/mock/mock-model.d.mts.map +1 -0
- package/esm/mock/mock-model.mjs +150 -0
- package/esm/mock/mock-model.mjs.map +1 -0
- package/esm/mock/mock-sdk.d.mts +25 -0
- package/esm/mock/mock-sdk.d.mts.map +1 -0
- package/esm/mock/mock-sdk.mjs +37 -0
- package/esm/mock/mock-sdk.mjs.map +1 -0
- package/esm/supervisor/as-tool.d.mts +45 -0
- package/esm/supervisor/as-tool.d.mts.map +1 -0
- package/esm/supervisor/as-tool.mjs +80 -0
- package/esm/supervisor/as-tool.mjs.map +1 -0
- package/esm/supervisor/cancellation.d.mts +12 -0
- package/esm/supervisor/cancellation.d.mts.map +1 -0
- package/esm/supervisor/cancellation.mjs +22 -0
- package/esm/supervisor/cancellation.mjs.map +1 -0
- package/esm/supervisor/decide.mjs +272 -0
- package/esm/supervisor/decide.mjs.map +1 -0
- package/esm/supervisor/emitter.d.mts +27 -0
- package/esm/supervisor/emitter.d.mts.map +1 -0
- package/esm/supervisor/emitter.mjs +47 -0
- package/esm/supervisor/emitter.mjs.map +1 -0
- package/esm/supervisor/entries.d.mts +141 -0
- package/esm/supervisor/entries.d.mts.map +1 -0
- package/esm/supervisor/entries.mjs +206 -0
- package/esm/supervisor/entries.mjs.map +1 -0
- package/esm/supervisor/execution.d.mts +637 -0
- package/esm/supervisor/execution.d.mts.map +1 -0
- package/esm/supervisor/execution.mjs +1868 -0
- package/esm/supervisor/execution.mjs.map +1 -0
- package/esm/supervisor/index.d.mts +11 -0
- package/esm/supervisor/index.mjs +12 -0
- package/esm/supervisor/router-prompt.d.mts +56 -0
- package/esm/supervisor/router-prompt.d.mts.map +1 -0
- package/esm/supervisor/router-prompt.mjs +52 -0
- package/esm/supervisor/router-prompt.mjs.map +1 -0
- package/esm/supervisor/signature.d.mts +28 -0
- package/esm/supervisor/signature.d.mts.map +1 -0
- package/esm/supervisor/signature.mjs +89 -0
- package/esm/supervisor/signature.mjs.map +1 -0
- package/esm/supervisor/snapshot.d.mts +54 -0
- package/esm/supervisor/snapshot.d.mts.map +1 -0
- package/esm/supervisor/snapshot.mjs +77 -0
- package/esm/supervisor/snapshot.mjs.map +1 -0
- package/esm/supervisor/supervisor-stream.d.mts +29 -0
- package/esm/supervisor/supervisor-stream.d.mts.map +1 -0
- package/esm/supervisor/supervisor-stream.mjs +89 -0
- package/esm/supervisor/supervisor-stream.mjs.map +1 -0
- package/esm/supervisor/supervisor.d.mts +27 -0
- package/esm/supervisor/supervisor.d.mts.map +1 -0
- package/esm/supervisor/supervisor.mjs +138 -0
- package/esm/supervisor/supervisor.mjs.map +1 -0
- package/esm/system-prompt/instruction.d.mts +52 -0
- package/esm/system-prompt/instruction.d.mts.map +1 -0
- package/esm/system-prompt/instruction.mjs +57 -0
- package/esm/system-prompt/instruction.mjs.map +1 -0
- package/esm/system-prompt/persona.d.mts +52 -0
- package/esm/system-prompt/persona.d.mts.map +1 -0
- package/esm/system-prompt/persona.mjs +57 -0
- package/esm/system-prompt/persona.mjs.map +1 -0
- package/esm/system-prompt/render-placeholders.d.mts +31 -0
- package/esm/system-prompt/render-placeholders.d.mts.map +1 -0
- package/esm/system-prompt/render-placeholders.mjs +58 -0
- package/esm/system-prompt/render-placeholders.mjs.map +1 -0
- package/esm/system-prompt/system-prompt.d.mts +117 -0
- package/esm/system-prompt/system-prompt.d.mts.map +1 -0
- package/esm/system-prompt/system-prompt.mjs +137 -0
- package/esm/system-prompt/system-prompt.mjs.map +1 -0
- package/esm/tool/index.d.mts +1 -0
- package/esm/tool/index.mjs +3 -0
- package/esm/tool/tool.d.mts +64 -0
- package/esm/tool/tool.d.mts.map +1 -0
- package/esm/tool/tool.mjs +184 -0
- package/esm/tool/tool.mjs.map +1 -0
- package/esm/utils/compute-cost.d.mts +58 -0
- package/esm/utils/compute-cost.d.mts.map +1 -0
- package/esm/utils/compute-cost.mjs +87 -0
- package/esm/utils/compute-cost.mjs.map +1 -0
- package/esm/utils/extract-json-payload.d.mts +33 -0
- package/esm/utils/extract-json-payload.d.mts.map +1 -0
- package/esm/utils/extract-json-payload.mjs +39 -0
- package/esm/utils/extract-json-payload.mjs.map +1 -0
- package/esm/utils/generate-run-id.d.mts +20 -0
- package/esm/utils/generate-run-id.d.mts.map +1 -0
- package/esm/utils/generate-run-id.mjs +23 -0
- package/esm/utils/generate-run-id.mjs.map +1 -0
- package/esm/utils/index.d.mts +9 -0
- package/esm/utils/index.mjs +11 -0
- package/esm/utils/json-schema.d.mts +57 -0
- package/esm/utils/json-schema.d.mts.map +1 -0
- package/esm/utils/json-schema.mjs +89 -0
- package/esm/utils/json-schema.mjs.map +1 -0
- package/esm/utils/prepare-attachment-part.d.mts +36 -0
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -0
- package/esm/utils/prepare-attachment-part.mjs +140 -0
- package/esm/utils/prepare-attachment-part.mjs.map +1 -0
- package/esm/utils/resolve-attachment.d.mts +33 -0
- package/esm/utils/resolve-attachment.d.mts.map +1 -0
- package/esm/utils/resolve-attachment.mjs +73 -0
- package/esm/utils/resolve-attachment.mjs.map +1 -0
- package/esm/utils/safe-json-parse.d.mts +14 -0
- package/esm/utils/safe-json-parse.d.mts.map +1 -0
- package/esm/utils/safe-json-parse.mjs +22 -0
- package/esm/utils/safe-json-parse.mjs.map +1 -0
- package/esm/utils/stamp-report-lineage.d.mts +61 -0
- package/esm/utils/stamp-report-lineage.d.mts.map +1 -0
- package/esm/utils/stamp-report-lineage.mjs +47 -0
- package/esm/utils/stamp-report-lineage.mjs.map +1 -0
- package/esm/utils/token-count.d.mts +15 -0
- package/esm/utils/token-count.d.mts.map +1 -0
- package/esm/utils/token-count.mjs +18 -0
- package/esm/utils/token-count.mjs.map +1 -0
- package/esm/workflow/as-tool.mjs +55 -0
- package/esm/workflow/as-tool.mjs.map +1 -0
- package/esm/workflow/cancellation.mjs +44 -0
- package/esm/workflow/cancellation.mjs.map +1 -0
- package/esm/workflow/emitter.mjs +40 -0
- package/esm/workflow/emitter.mjs.map +1 -0
- package/esm/workflow/engine.mjs +362 -0
- package/esm/workflow/engine.mjs.map +1 -0
- package/esm/workflow/index.d.mts +3 -0
- package/esm/workflow/index.mjs +5 -0
- package/esm/workflow/retry.mjs +32 -0
- package/esm/workflow/retry.mjs.map +1 -0
- package/esm/workflow/router.mjs +56 -0
- package/esm/workflow/router.mjs.map +1 -0
- package/esm/workflow/run-scoped-emitter.mjs +32 -0
- package/esm/workflow/run-scoped-emitter.mjs.map +1 -0
- package/esm/workflow/signature.d.mts +7 -0
- package/esm/workflow/signature.d.mts.map +1 -0
- package/esm/workflow/signature.mjs +34 -0
- package/esm/workflow/signature.mjs.map +1 -0
- package/esm/workflow/snapshot.mjs +71 -0
- package/esm/workflow/snapshot.mjs.map +1 -0
- package/esm/workflow/state.mjs +37 -0
- package/esm/workflow/state.mjs.map +1 -0
- package/esm/workflow/step-runner.mjs +371 -0
- package/esm/workflow/step-runner.mjs.map +1 -0
- package/esm/workflow/step.d.mts +19 -0
- package/esm/workflow/step.d.mts.map +1 -0
- package/esm/workflow/step.mjs +37 -0
- package/esm/workflow/step.mjs.map +1 -0
- package/esm/workflow/workflow.d.mts +12 -0
- package/esm/workflow/workflow.d.mts.map +1 -0
- package/esm/workflow/workflow.mjs +116 -0
- package/esm/workflow/workflow.mjs.map +1 -0
- package/llms-full.txt +2293 -0
- package/llms.txt +20 -0
- package/package.json +37 -0
- package/skills/README.md +53 -0
- package/skills/ai-basics/SKILL.md +95 -0
- package/skills/attach-ai-middleware/SKILL.md +184 -0
- package/skills/define-ai-tool/SKILL.md +186 -0
- package/skills/embed-text/SKILL.md +105 -0
- package/skills/handle-ai-errors/SKILL.md +194 -0
- package/skills/log-ai-calls/SKILL.md +141 -0
- package/skills/persist-ai-data/SKILL.md +207 -0
- package/skills/pick-ai-provider/SKILL.md +164 -0
- package/skills/run-ai-agent/SKILL.md +267 -0
- package/skills/run-ai-workflow/SKILL.md +258 -0
- package/skills/run-supervisor/SKILL.md +309 -0
- package/skills/write-system-prompt/SKILL.md +129 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: run-supervisor
|
|
3
|
+
description: 'Multi-intent routing with ai.supervisor({...}) — classifier (iter-0 dispatch), router agent OR route callback, intents as agents / workflows / callbacks, fan-out, evaluate quality loop, ack receptionist. Triggers: `ai.supervisor`, `supervisor.execute`, `supervisor.resume`, `intents`, `router`, `route`, `classifier`, `evaluate`, `ack`, `artifactsSchema`, `END`, `ctx.intents.X.execute`; ''route one input across specialists'', ''multi-intent dispatch'', ''fan-out then evaluate'', ''classifier then router''; typical import `import { ai } from "@warlock.js/ai"`. Skip: fixed pipelines — `@warlock.js/ai/run-ai-workflow/SKILL.md`; single agent — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langgraph`, `crewai`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `ai.supervisor()` — multi-intent routing
|
|
7
|
+
|
|
8
|
+
A supervisor takes one input, picks which intent(s) handle it, runs them, optionally evaluates the result, and either terminates or iterates. Stateless between runs unless you wire `snapshotStore` for resume.
|
|
9
|
+
|
|
10
|
+
## When to reach for it
|
|
11
|
+
|
|
12
|
+
- **`agent`** — one model + tools, single task. Doesn't fit when the right specialist depends on the input.
|
|
13
|
+
- **`workflow`** — fixed step order. Doesn't fit when routing decisions need an LLM or vary per request.
|
|
14
|
+
- **`supervisor`** — when the right specialist is decided per-call and you may iterate to a goal.
|
|
15
|
+
- **`orchestrator` (v2)** — when the *session* matters: long-running conversations.
|
|
16
|
+
|
|
17
|
+
## Three dispatch surfaces
|
|
18
|
+
|
|
19
|
+
| | When it fires | Iterations |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `classifier` | iter-0 prelude — picks the FIRST intent | 1 |
|
|
22
|
+
| `router` | iter 0+ (no classifier); iter 1+ (with classifier) | 1..maxIterations |
|
|
23
|
+
| `route` | iter 0+ (no classifier); iter 1+ (with classifier) | 1..maxIterations |
|
|
24
|
+
|
|
25
|
+
`router` and `route` are mutually exclusive. `classifier` composes with either. Classifier alone (no router/route) → terminates after iter 0.
|
|
26
|
+
|
|
27
|
+
`classifier` is mutually exclusive with `initialAgent`.
|
|
28
|
+
|
|
29
|
+
Quick decision tree:
|
|
30
|
+
- Pure classification → `classifier` alone.
|
|
31
|
+
- Multi-step reasoning → `router` + `intents` with rich descriptions.
|
|
32
|
+
- Deterministic routing → `route` callback.
|
|
33
|
+
- Classify-then-iterate → `classifier` + `router`/`route`.
|
|
34
|
+
|
|
35
|
+
## Two routing modes — `route` XOR `router`
|
|
36
|
+
|
|
37
|
+
### Deterministic — `route(ctx)`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const triageBot = ai.supervisor({
|
|
41
|
+
name: "triage",
|
|
42
|
+
intents: { billing, shipping, returns },
|
|
43
|
+
route: (ctx) => {
|
|
44
|
+
const text = typeof ctx.input === "string" ? ctx.input.toLowerCase() : "";
|
|
45
|
+
if (text.includes("refund")) return "billing";
|
|
46
|
+
if (text.includes("ship")) return "shipping";
|
|
47
|
+
return "returns";
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`route` returns `string | string[] | typeof END`. Array → fan-out.
|
|
53
|
+
|
|
54
|
+
### LLM-driven — `router` agent
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const routerAgent = ai.agent({
|
|
58
|
+
output: v.object({ next: v.string(), reasoning: v.string() }),
|
|
59
|
+
// ...
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const supportBot = ai.supervisor({
|
|
63
|
+
router: routerAgent,
|
|
64
|
+
intents: { billing, shipping, returns, escalate },
|
|
65
|
+
evaluate: (ctx) =>
|
|
66
|
+
Object.values(ctx.result).some((b: any) => b.data?.resolved)
|
|
67
|
+
? { satisfied: true }
|
|
68
|
+
: undefined,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The router agent's output MUST include `next: string | string[] | typeof END`; `reasoning: string` is optional but recommended.
|
|
73
|
+
|
|
74
|
+
`evaluate` pairs with both `router` AND `route` — state-driven termination is useful in either dispatch mode.
|
|
75
|
+
|
|
76
|
+
## The `intents` map — five accepted shapes
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
intents: {
|
|
80
|
+
billing: billingAgent, // (a) AgentContract
|
|
81
|
+
escalate: escalationWorkflow, // (b) WorkflowInstance
|
|
82
|
+
refund: async (ctx) => ({ refundId: await callRefundAPI(ctx.input) }), // (c) callback
|
|
83
|
+
triage: { // (d) agent entry
|
|
84
|
+
agent: triageAgent,
|
|
85
|
+
description: "First-pass classifier",
|
|
86
|
+
placeholders: (ctx) => ({ ticket: ctx.input }),
|
|
87
|
+
output: v.object({ category: v.string() }),
|
|
88
|
+
},
|
|
89
|
+
cancel: { // (e) callback entry
|
|
90
|
+
run: async (ctx) => ({ cancelledId: await cancelOrder(ctx.input) }),
|
|
91
|
+
description: "Cancel on customer request",
|
|
92
|
+
output: v.object({ cancelledId: v.string() }),
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Runtime detects shape in order: `function → "run" in value → "agent" in value → instanceof`. Mixed dispatch fields (`{ agent, run }` together) throw at construction.
|
|
98
|
+
|
|
99
|
+
**Under a router**, every intent MUST have a non-empty `description` so the LLM has signal. Bare callback shorthand has no description — upgrade to `{ run, description }` under a router.
|
|
100
|
+
|
|
101
|
+
## State model
|
|
102
|
+
|
|
103
|
+
A supervisor builds up typed `state` across iterations. Each intent contributes a slice; final state validates against the supervisor's `output` schema.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
type RefundOutput = { category: string; order?: { id: string }; reply: string };
|
|
107
|
+
|
|
108
|
+
const refundSupervisor = ai.supervisor<RefundOutput>({
|
|
109
|
+
name: "refund-support",
|
|
110
|
+
output: outputSchema,
|
|
111
|
+
intents: {
|
|
112
|
+
classify: { agent: classifierAgent, output: v.object({ category: v.string() }) },
|
|
113
|
+
lookupOrder: {
|
|
114
|
+
run: async (ctx) => ({ order: await ordersRepo.find(extractId(ctx.input)) }),
|
|
115
|
+
},
|
|
116
|
+
compose: { agent: replyAgent, output: v.object({ reply: v.string() }) },
|
|
117
|
+
},
|
|
118
|
+
router: routerAgent,
|
|
119
|
+
evaluate: (ctx) => (ctx.state.reply ? { satisfied: true } : undefined),
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Each branch's output strip-merges into state per its declared `output` schema. Last-write-wins on fan-out conflict (warning logged).
|
|
124
|
+
|
|
125
|
+
## Per-intent `next` — skip the router
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
intents: {
|
|
129
|
+
classify: {
|
|
130
|
+
agent: classifierAgent,
|
|
131
|
+
next: (ctx) => ctx.state.category === "refund" ? "lookupOrder" : "escalate",
|
|
132
|
+
},
|
|
133
|
+
lookupOrder: {
|
|
134
|
+
run: async (ctx) => ({ order: await ordersRepo.find(extractId(ctx.input)) }),
|
|
135
|
+
next: (ctx) => ctx.state.order ? "compose" : "escalate",
|
|
136
|
+
},
|
|
137
|
+
compose: { agent: replyAgent, next: () => END },
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Returns: `string` (intent name), `string[]` (fan-out), `END` (terminate), `undefined` (fall back to router). Order of authority: `evaluate` → `intent.next` → `router/route`.
|
|
142
|
+
|
|
143
|
+
## Stream-mode intents
|
|
144
|
+
|
|
145
|
+
For chat-style prose replies, opt out of structured-output coercion:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
intents: {
|
|
149
|
+
smalltalk: {
|
|
150
|
+
agent: smalltalkAgent,
|
|
151
|
+
mode: "stream",
|
|
152
|
+
streamTo: "reply", // raw text → state.reply
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Token deltas surface as `supervisor.agent.streaming`. `mode: "stream"` + `output` together throws — they're mutually exclusive. Stream mode is agent-only (workflows can't stream this way).
|
|
158
|
+
|
|
159
|
+
## `ack` — fast preamble
|
|
160
|
+
|
|
161
|
+
When the router agent / first specialist takes 5+ seconds and users feel it:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
ack: (ctx) => ({ ack: "Got it, one moment..." }) // bare callback
|
|
165
|
+
ack: { run: (ctx) => ({ ack: pickHedge(ctx.input) }), output: v.object({ ack: v.string() }) }
|
|
166
|
+
ack: { agent: tinyAckAgent, placeholders: (ctx) => ({ tier: ctx.context.customerTier as string }) }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Fires on iter-0 only, in parallel with the routing decision. **Same-model trap:** if ack uses the same model+provider as the router, ack often takes longer than the router. The callback forms (1+2) are right for the common case.
|
|
170
|
+
|
|
171
|
+
## Classifier — `classifier`
|
|
172
|
+
|
|
173
|
+
Iter-0 prelude. Output locked to `{ intent, reasoning?, confidence? }`.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
classifier: classifyAgent
|
|
177
|
+
// or with refine:
|
|
178
|
+
classifier: {
|
|
179
|
+
agent: classifyAgent,
|
|
180
|
+
refine: (ctx) => {
|
|
181
|
+
const { confidence } = ctx.result.data;
|
|
182
|
+
if ((confidence ?? 1) < 0.7) return { intent: "fallback" };
|
|
183
|
+
return undefined;
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`refine` shapes: `undefined` (keep), `END` (halt), `{ intent: "x", ...slice }` (override + merge), `{ ...slice }` (keep intent, merge).
|
|
189
|
+
|
|
190
|
+
LLM-reported `confidence` is poorly calibrated — use it as a soft signal alongside heuristics.
|
|
191
|
+
|
|
192
|
+
## Tool artifacts — `ctx.artifacts`
|
|
193
|
+
|
|
194
|
+
Tools mutate `ctx.artifacts`; supervisor merges into `state` at iteration end.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
ai.supervisor({
|
|
198
|
+
artifactsSchema: v.object({ blocks: v.array(blockSchema).optional() }),
|
|
199
|
+
finalizeArtifacts: (state, artifacts) => ({
|
|
200
|
+
...state,
|
|
201
|
+
blocks: [...(state.blocks ?? []), ...(artifacts.blocks ?? [])],
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Default merger — auto-spread (`{...state, ...artifacts}`). `finalizeArtifacts` for concat / dedupe across iterations. Bag resets every iteration.
|
|
207
|
+
|
|
208
|
+
## Callback intents — `ctx.intents.X.execute()` + `ctx.run` / `ctx.stream`
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
intents: {
|
|
212
|
+
"special-refund": async (ctx) => {
|
|
213
|
+
if ((ctx.input as { amount: number }).amount > 1_000) {
|
|
214
|
+
await ctx.intents["audit-log"].execute(); // dispatch registered intent
|
|
215
|
+
}
|
|
216
|
+
return await callRefundAPI(ctx.input);
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
// Inline (non-registered) execution
|
|
220
|
+
classify: async (ctx) => {
|
|
221
|
+
const { data } = await ctx.run(classifierAgent, ctx.input);
|
|
222
|
+
return { category: (data as { label: string }).label };
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
chatInline: async (ctx) => {
|
|
226
|
+
const stream = ctx.stream(someAgent, enrich(ctx.input));
|
|
227
|
+
const final = await stream.result;
|
|
228
|
+
return { reply: final.text };
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Cycle protection: per-branch call stack. Re-entry on same intent → `SUPERVISOR_DISPATCH_CYCLE`.
|
|
234
|
+
|
|
235
|
+
## Per-call options
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
await supportBot.execute(message, {
|
|
239
|
+
context: { userId, db, traceId }, // request-scoped bag, never persisted
|
|
240
|
+
history: priorMessages, // Message[] forwarded to router + agents
|
|
241
|
+
sessionId: "sess_user_42", // stamps onto every report node
|
|
242
|
+
signal: AbortSignal.timeout(60_000),
|
|
243
|
+
runId: "support-2026-04-26-7", // for snapshot resume
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
`history` precedence: per-call → factory `config.history`. Slice with `historyWindow.{router,agents,ack}` (default ack = 0, router/agents = unbounded) or per-entry `history(ctx)` override.
|
|
248
|
+
|
|
249
|
+
## Iteration model
|
|
250
|
+
|
|
251
|
+
1. Router/route picks `next` (or `END`).
|
|
252
|
+
2. Picked intents dispatch (parallel for fan-out).
|
|
253
|
+
3. `evaluate` (if provided) inspects results.
|
|
254
|
+
4. If satisfied or `END` → terminate. Otherwise → loop.
|
|
255
|
+
|
|
256
|
+
Hard cap via `maxIterations` (default 10). Hitting cap surfaces `MaxIterationsError`.
|
|
257
|
+
|
|
258
|
+
## Streaming
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
const stream = supportBot.stream(message);
|
|
262
|
+
|
|
263
|
+
for await (const event of stream) {
|
|
264
|
+
if (event.type === "supervisor.agent.streaming") {
|
|
265
|
+
process.stdout.write(event.delta);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const result = await stream.result;
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Token-level streaming requires the dispatched agents to be streamed (supervisor calls `agent.stream()` internally). Callbacks don't stream tokens.
|
|
273
|
+
|
|
274
|
+
## Snapshot resume
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import { ai } from "@warlock.js/ai";
|
|
278
|
+
import { cache } from "@warlock.js/cache";
|
|
279
|
+
|
|
280
|
+
ai.config({ defaultStore: cache.driver("redis", { client }) });
|
|
281
|
+
|
|
282
|
+
await supportBot.execute(message, { runId: "support-7" }); // fresh
|
|
283
|
+
await supportBot.resume("support-7"); // after crash
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Signature drift detection throws `SupervisorDriftError` on shape mismatch — `force: true` bypasses. See [`@warlock.js/ai/persist-ai-data/SKILL.md`](@warlock.js/ai/persist-ai-data/SKILL.md).
|
|
287
|
+
|
|
288
|
+
## `asTool()` — supervisor as a tool
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
const supportTool = supportBot.asTool({
|
|
292
|
+
description: "Route a customer support request to the right specialist",
|
|
293
|
+
inputSchema: v.object({ message: v.string() }),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const escalationAgent = ai.agent({ model, tools: [supportTool] });
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Design reference
|
|
300
|
+
|
|
301
|
+
`domains/ai/design/supervisor.md` — full design rationale.
|
|
302
|
+
|
|
303
|
+
## See also
|
|
304
|
+
|
|
305
|
+
- [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — dispatchable units
|
|
306
|
+
- [`@warlock.js/ai/run-ai-workflow/SKILL.md`](@warlock.js/ai/run-ai-workflow/SKILL.md) — when steps are known up front
|
|
307
|
+
- [`@warlock.js/ai/persist-ai-data/SKILL.md`](@warlock.js/ai/persist-ai-data/SKILL.md) — `snapshotStore` + resume
|
|
308
|
+
- [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md) — `semanticCache` fits under each agent's middleware
|
|
309
|
+
- [`@warlock.js/ai/define-ai-tool/SKILL.md`](@warlock.js/ai/define-ai-tool/SKILL.md) — tool artifacts side-channel
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: write-system-prompt
|
|
3
|
+
description: 'Compose system prompts via ai.systemPrompt() / ai.persona() / ai.instruction() — immutable builders with {{placeholder}} substitution. Triggers: `ai.systemPrompt`, `ai.persona`, `ai.instruction`, `SystemPromptBlockContract`, `PersonaContract`, `InstructionContract`, `placeholders`, `{{placeholder|default}}`; ''write a system prompt'', ''compose persona + instructions'', ''per-call prompt override'', ''mustache placeholder''; typical import `import { ai } from "@warlock.js/ai"`. Skip: agent factory wiring — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langchain` `PromptTemplate`, raw f-strings.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# System prompts — immutable builders
|
|
7
|
+
|
|
8
|
+
Three factories — `ai.systemPrompt()`, `ai.persona()`, `ai.instruction()` — compose into the `systemPrompt` option accepted by every agent / workflow step.
|
|
9
|
+
|
|
10
|
+
## The namespace
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { ai } from "@warlock.js/ai";
|
|
14
|
+
|
|
15
|
+
ai.systemPrompt(); // empty — chain .persona(), .instruction() onto it
|
|
16
|
+
ai.systemPrompt("literal text"); // one-shot string form
|
|
17
|
+
ai.systemPrompt([block1, block2]); // array form — blocks render in declaration order
|
|
18
|
+
|
|
19
|
+
ai.persona(text); // PersonaContract block
|
|
20
|
+
ai.instruction(text); // InstructionContract block
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Two shapes, same result
|
|
24
|
+
|
|
25
|
+
### String form — one-shot
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
ai.agent({
|
|
29
|
+
model,
|
|
30
|
+
systemPrompt: "You are a concise senior TypeScript engineer.",
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Builder form — composable
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const prompt = ai.systemPrompt()
|
|
38
|
+
.persona("You are Alex, a senior TypeScript engineer.")
|
|
39
|
+
.instruction("Explain things assuming the reader is a Go developer.")
|
|
40
|
+
.instruction("Always cite the relevant TypeScript handbook section.");
|
|
41
|
+
|
|
42
|
+
const myAgent = ai.agent({ model, systemPrompt: prompt });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Array form — explicit order
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
ai.systemPrompt([
|
|
49
|
+
ai.persona("You are Alex, a TypeScript expert."),
|
|
50
|
+
ai.instruction("Respond in {{language|English}}."),
|
|
51
|
+
]);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Block ordering
|
|
55
|
+
|
|
56
|
+
`SystemPrompt` stores `blocks: readonly SystemPromptBlockContract[]` — not separate persona + instructions fields. Rendering honors insertion order.
|
|
57
|
+
|
|
58
|
+
- **Chained `.persona(x)`** — replaces the existing persona in place, or prepends when none exists. Default persona-first layout.
|
|
59
|
+
- **Chained `.instruction(y)`** — appends.
|
|
60
|
+
- **Array form** — verbatim.
|
|
61
|
+
|
|
62
|
+
## Immutability — safe forking
|
|
63
|
+
|
|
64
|
+
Every mutation returns a **new** `SystemPrompt`. The original is never touched:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const base = ai.systemPrompt().persona(alex).instruction(cite);
|
|
68
|
+
const arabic = base.instruction("Prefer Arabic comments");
|
|
69
|
+
|
|
70
|
+
// base still has 2 blocks, arabic has 3. Neither affects the other.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`Persona` and `Instruction` follow the same rule — their `text` is `readonly`.
|
|
74
|
+
|
|
75
|
+
## Mustache placeholders
|
|
76
|
+
|
|
77
|
+
`{{key}}` and `{{key|defaultValue}}` substitute at render time:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const prompt = ai.systemPrompt()
|
|
81
|
+
.persona("You are Alex, a TypeScript expert.")
|
|
82
|
+
.instruction("Respond in {{language|English}}.");
|
|
83
|
+
|
|
84
|
+
await myAgent.execute("Why use generics?", {
|
|
85
|
+
placeholders: { language: "Arabic" },
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or set defaults on the agent — per-call values override them:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
ai.agent({ model, systemPrompt: prompt, placeholders: { language: "Arabic" } });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Substitution works on the **rendered** concatenation of every block, so `{{key}}` inside a persona and inside an instruction both resolve against the same placeholder bag.
|
|
96
|
+
|
|
97
|
+
## Per-call overrides
|
|
98
|
+
|
|
99
|
+
Replace the agent's system prompt for a single run:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
await myAgent.execute(input, { systemPrompt: alternativePrompt });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Useful for A/B testing, request-scoped personalization, or turn-by-turn prompt variation.
|
|
106
|
+
|
|
107
|
+
## Tagged discriminator (not `instanceof`)
|
|
108
|
+
|
|
109
|
+
All blocks implement `SystemPromptBlockContract { readonly type: string; readonly text; resolve() }`. Runtime discrimination uses the string `type` tag (`"persona"`, `"instruction"`, future kinds) — **not** `instanceof`.
|
|
110
|
+
|
|
111
|
+
Why: `instanceof` breaks across duplicate package copies (different `node_modules` trees), realms, bundler scopes.
|
|
112
|
+
|
|
113
|
+
## Pattern — forking a base prompt
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const base = ai.systemPrompt()
|
|
117
|
+
.persona("You are a support agent for Acme Corp.")
|
|
118
|
+
.instruction("Cite policy §{{policy}} when denying a refund.");
|
|
119
|
+
|
|
120
|
+
const enterprise = base.instruction("Escalate immediately for Enterprise customers.");
|
|
121
|
+
const trial = base.instruction("Offer a 14-day extension before closing the ticket.");
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Three distinct prompts, one common foundation. Base is immutable — safe to share.
|
|
125
|
+
|
|
126
|
+
## See also
|
|
127
|
+
|
|
128
|
+
- [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — `systemPrompt` on factory + per-call override
|
|
129
|
+
- [`@warlock.js/ai/run-ai-workflow/SKILL.md`](@warlock.js/ai/run-ai-workflow/SKILL.md) — per-step agent references inherit their own system prompt
|