@dogpile/sdk 0.3.1 → 0.5.0
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 +201 -0
- package/README.md +1 -0
- package/dist/browser/index.js +2328 -237
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/openai-compatible.d.ts +11 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -1
- package/dist/providers/openai-compatible.js +88 -2
- package/dist/providers/openai-compatible.js.map +1 -1
- package/dist/runtime/audit.d.ts +42 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +73 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/broadcast.d.ts.map +1 -1
- package/dist/runtime/broadcast.js +39 -36
- package/dist/runtime/broadcast.js.map +1 -1
- package/dist/runtime/cancellation.d.ts +26 -0
- package/dist/runtime/cancellation.d.ts.map +1 -1
- package/dist/runtime/cancellation.js +38 -1
- package/dist/runtime/cancellation.js.map +1 -1
- package/dist/runtime/coordinator.d.ts +79 -1
- package/dist/runtime/coordinator.d.ts.map +1 -1
- package/dist/runtime/coordinator.js +979 -61
- package/dist/runtime/coordinator.js.map +1 -1
- package/dist/runtime/decisions.d.ts +25 -3
- package/dist/runtime/decisions.d.ts.map +1 -1
- package/dist/runtime/decisions.js +241 -3
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/defaults.d.ts +37 -1
- package/dist/runtime/defaults.d.ts.map +1 -1
- package/dist/runtime/defaults.js +359 -4
- package/dist/runtime/defaults.js.map +1 -1
- package/dist/runtime/engine.d.ts +17 -4
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +770 -35
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/health.d.ts +51 -0
- package/dist/runtime/health.d.ts.map +1 -0
- package/dist/runtime/health.js +85 -0
- package/dist/runtime/health.js.map +1 -0
- package/dist/runtime/introspection.d.ts +96 -0
- package/dist/runtime/introspection.d.ts.map +1 -0
- package/dist/runtime/introspection.js +31 -0
- package/dist/runtime/introspection.js.map +1 -0
- package/dist/runtime/metrics.d.ts +44 -0
- package/dist/runtime/metrics.d.ts.map +1 -0
- package/dist/runtime/metrics.js +12 -0
- package/dist/runtime/metrics.js.map +1 -0
- package/dist/runtime/model.d.ts.map +1 -1
- package/dist/runtime/model.js +34 -7
- package/dist/runtime/model.js.map +1 -1
- package/dist/runtime/provenance.d.ts +25 -0
- package/dist/runtime/provenance.d.ts.map +1 -0
- package/dist/runtime/provenance.js +13 -0
- package/dist/runtime/provenance.js.map +1 -0
- package/dist/runtime/sequential.d.ts.map +1 -1
- package/dist/runtime/sequential.js +47 -37
- package/dist/runtime/sequential.js.map +1 -1
- package/dist/runtime/shared.d.ts.map +1 -1
- package/dist/runtime/shared.js +39 -36
- package/dist/runtime/shared.js.map +1 -1
- package/dist/runtime/tracing.d.ts +31 -0
- package/dist/runtime/tracing.d.ts.map +1 -0
- package/dist/runtime/tracing.js +18 -0
- package/dist/runtime/tracing.js.map +1 -0
- package/dist/runtime/validation.d.ts +10 -0
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/runtime/validation.js +73 -0
- package/dist/runtime/validation.js.map +1 -1
- package/dist/types/events.d.ts +339 -12
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/replay.d.ts +7 -1
- package/dist/types/replay.d.ts.map +1 -1
- package/dist/types.d.ts +255 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +39 -1
- package/src/index.ts +15 -0
- package/src/providers/openai-compatible.ts +83 -3
- package/src/runtime/audit.ts +121 -0
- package/src/runtime/broadcast.ts +40 -37
- package/src/runtime/cancellation.ts +59 -1
- package/src/runtime/coordinator.ts +1221 -61
- package/src/runtime/decisions.ts +307 -4
- package/src/runtime/defaults.ts +389 -4
- package/src/runtime/engine.ts +1004 -35
- package/src/runtime/health.ts +136 -0
- package/src/runtime/introspection.ts +122 -0
- package/src/runtime/metrics.ts +45 -0
- package/src/runtime/model.ts +38 -6
- package/src/runtime/provenance.ts +43 -0
- package/src/runtime/sequential.ts +49 -38
- package/src/runtime/shared.ts +40 -37
- package/src/runtime/tracing.ts +35 -0
- package/src/runtime/validation.ts +81 -0
- package/src/types/events.ts +369 -12
- package/src/types/replay.ts +14 -1
- package/src/types.ts +279 -4
package/src/types/replay.ts
CHANGED
|
@@ -110,7 +110,14 @@ export type ReplayTraceProtocolDecisionType =
|
|
|
110
110
|
| "complete-tool-call"
|
|
111
111
|
| "collect-broadcast-round"
|
|
112
112
|
| "stop-for-budget"
|
|
113
|
-
| "finalize-output"
|
|
113
|
+
| "finalize-output"
|
|
114
|
+
| "start-sub-run"
|
|
115
|
+
| "complete-sub-run"
|
|
116
|
+
| "fail-sub-run"
|
|
117
|
+
| "mark-sub-run-parent-aborted"
|
|
118
|
+
| "mark-sub-run-budget-clamped"
|
|
119
|
+
| "queue-sub-run"
|
|
120
|
+
| "mark-sub-run-concurrency-clamped";
|
|
114
121
|
|
|
115
122
|
/**
|
|
116
123
|
* Protocol-level decision appended during execution.
|
|
@@ -136,6 +143,10 @@ export interface ReplayTraceProtocolDecision {
|
|
|
136
143
|
readonly callId?: string;
|
|
137
144
|
/** Provider involved in the decision, when model-scoped. */
|
|
138
145
|
readonly providerId?: string;
|
|
146
|
+
/** Child run involved in a delegated sub-run decision. */
|
|
147
|
+
readonly childRunId?: string;
|
|
148
|
+
/** FIFO queue position for sub-run queue decisions. */
|
|
149
|
+
readonly queuePosition?: number;
|
|
139
150
|
/** Tool call involved in the decision, when tool-scoped. */
|
|
140
151
|
readonly toolCallId?: string;
|
|
141
152
|
/** Tool identity involved in the decision, when tool-scoped. */
|
|
@@ -170,6 +181,8 @@ export interface ReplayTraceProviderCall {
|
|
|
170
181
|
readonly callId: string;
|
|
171
182
|
/** Configured model provider id. */
|
|
172
183
|
readonly providerId: string;
|
|
184
|
+
/** Resolved model identifier (same fallback as provenance events). */
|
|
185
|
+
readonly modelId: string;
|
|
173
186
|
/** ISO-8601 timestamp before the provider call started. */
|
|
174
187
|
readonly startedAt: string;
|
|
175
188
|
/** ISO-8601 timestamp after the provider call completed. */
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { DogpileTracer } from "./runtime/tracing.js";
|
|
2
|
+
import type { Logger } from "./runtime/logger.js";
|
|
3
|
+
import type { MetricsHook } from "./runtime/metrics.js";
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Primitive JSON value accepted in serializable trace metadata.
|
|
3
7
|
*/
|
|
@@ -87,6 +91,14 @@ export type DogpileProviderInvalidRequestError = DogpileErrorBase<"provider-inva
|
|
|
87
91
|
export type DogpileProviderInvalidResponseError = DogpileErrorBase<"provider-invalid-response">;
|
|
88
92
|
export type DogpileProviderNotFoundError = DogpileErrorBase<"provider-not-found">;
|
|
89
93
|
export type DogpileProviderRateLimitedError = DogpileErrorBase<"provider-rate-limited">;
|
|
94
|
+
/**
|
|
95
|
+
* Provider timeout errors may include `detail.source?: "provider" | "engine"`.
|
|
96
|
+
*
|
|
97
|
+
* Absence is backwards-compatible and should be interpreted as `"provider"`.
|
|
98
|
+
* `"engine"` means a child engine's own deadline expired before the provider
|
|
99
|
+
* returned; parent budget propagation remains `code: "aborted"` with
|
|
100
|
+
* `detail.reason: "timeout"`.
|
|
101
|
+
*/
|
|
90
102
|
export type DogpileProviderTimeoutError = DogpileErrorBase<"provider-timeout">;
|
|
91
103
|
export type DogpileProviderUnavailableError = DogpileErrorBase<"provider-unavailable">;
|
|
92
104
|
export type DogpileProviderUnsupportedError = DogpileErrorBase<"provider-unsupported">;
|
|
@@ -876,6 +888,8 @@ export interface ModelOutputChunk {
|
|
|
876
888
|
export interface ConfiguredModelProvider {
|
|
877
889
|
/** Stable provider id recorded in traces. */
|
|
878
890
|
readonly id: string;
|
|
891
|
+
/** Optional resolved model identifier. When set, provenance events carry this value; when absent, the SDK falls back to `id`. */
|
|
892
|
+
readonly modelId?: string;
|
|
879
893
|
/** Generate a response for one protocol-managed model request. */
|
|
880
894
|
generate(request: ModelRequest): Promise<ModelResponse>;
|
|
881
895
|
/**
|
|
@@ -887,6 +901,14 @@ export interface ConfiguredModelProvider {
|
|
|
887
901
|
* support incremental output and for callers that prefer batch execution.
|
|
888
902
|
*/
|
|
889
903
|
stream?(request: ModelRequest): AsyncIterable<ModelOutputChunk>;
|
|
904
|
+
/**
|
|
905
|
+
* Optional provider hints for the runtime. Absent or omitted is treated as
|
|
906
|
+
* `remote` for concurrency clamping (CONCURRENCY-02 / Phase 3 D-01).
|
|
907
|
+
*/
|
|
908
|
+
readonly metadata?: {
|
|
909
|
+
/** Locality hint for dispatch clamping. Absent -> "remote" for clamping. */
|
|
910
|
+
readonly locality?: "local" | "remote";
|
|
911
|
+
};
|
|
890
912
|
}
|
|
891
913
|
|
|
892
914
|
/**
|
|
@@ -1284,16 +1306,19 @@ export type {
|
|
|
1284
1306
|
|
|
1285
1307
|
// Events: see src/types/events.ts
|
|
1286
1308
|
import type {
|
|
1309
|
+
AbortedEvent,
|
|
1287
1310
|
AgentDecision,
|
|
1288
1311
|
AgentParticipation,
|
|
1289
1312
|
BroadcastContribution,
|
|
1290
1313
|
BroadcastEvent,
|
|
1291
1314
|
BudgetStopEvent,
|
|
1315
|
+
DelegateAgentDecision,
|
|
1292
1316
|
FinalEvent,
|
|
1293
1317
|
ModelActivityEvent,
|
|
1294
1318
|
ModelOutputChunkEvent,
|
|
1295
1319
|
ModelRequestEvent,
|
|
1296
1320
|
ModelResponseEvent,
|
|
1321
|
+
ParticipateAgentDecision,
|
|
1297
1322
|
RoleAssignmentEvent,
|
|
1298
1323
|
RunEvent,
|
|
1299
1324
|
StreamCompletionEvent,
|
|
@@ -1301,6 +1326,13 @@ import type {
|
|
|
1301
1326
|
StreamEvent,
|
|
1302
1327
|
StreamLifecycleEvent,
|
|
1303
1328
|
StreamOutputEvent,
|
|
1329
|
+
SubRunBudgetClampedEvent,
|
|
1330
|
+
SubRunCompletedEvent,
|
|
1331
|
+
SubRunConcurrencyClampedEvent,
|
|
1332
|
+
SubRunFailedEvent,
|
|
1333
|
+
SubRunParentAbortedEvent,
|
|
1334
|
+
SubRunQueuedEvent,
|
|
1335
|
+
SubRunStartedEvent,
|
|
1304
1336
|
ToolActivityEvent,
|
|
1305
1337
|
ToolCallEvent,
|
|
1306
1338
|
ToolResultEvent,
|
|
@@ -1308,8 +1340,11 @@ import type {
|
|
|
1308
1340
|
TurnEvent
|
|
1309
1341
|
} from "./types/events.js";
|
|
1310
1342
|
export type {
|
|
1343
|
+
AbortedEvent,
|
|
1311
1344
|
AgentDecision,
|
|
1312
1345
|
AgentParticipation,
|
|
1346
|
+
DelegateAgentDecision,
|
|
1347
|
+
ParticipateAgentDecision,
|
|
1313
1348
|
BroadcastContribution,
|
|
1314
1349
|
BroadcastEvent,
|
|
1315
1350
|
BudgetStopEvent,
|
|
@@ -1325,6 +1360,13 @@ export type {
|
|
|
1325
1360
|
StreamEvent,
|
|
1326
1361
|
StreamLifecycleEvent,
|
|
1327
1362
|
StreamOutputEvent,
|
|
1363
|
+
SubRunBudgetClampedEvent,
|
|
1364
|
+
SubRunCompletedEvent,
|
|
1365
|
+
SubRunConcurrencyClampedEvent,
|
|
1366
|
+
SubRunFailedEvent,
|
|
1367
|
+
SubRunParentAbortedEvent,
|
|
1368
|
+
SubRunQueuedEvent,
|
|
1369
|
+
SubRunStartedEvent,
|
|
1328
1370
|
ToolActivityEvent,
|
|
1329
1371
|
ToolCallEvent,
|
|
1330
1372
|
ToolResultEvent,
|
|
@@ -1372,7 +1414,7 @@ export interface TranscriptEntry {
|
|
|
1372
1414
|
/** Text produced by the agent. */
|
|
1373
1415
|
readonly output: string;
|
|
1374
1416
|
/** Optional structured role/participation decision parsed from model output. */
|
|
1375
|
-
readonly decision?: AgentDecision;
|
|
1417
|
+
readonly decision?: AgentDecision | readonly DelegateAgentDecision[];
|
|
1376
1418
|
/** Ordered runtime tool calls and results requested during this turn. */
|
|
1377
1419
|
readonly toolCalls?: readonly TranscriptToolCall[];
|
|
1378
1420
|
}
|
|
@@ -1535,6 +1577,17 @@ export interface Trace {
|
|
|
1535
1577
|
readonly providerCalls: readonly ReplayTraceProviderCall[];
|
|
1536
1578
|
/** Final output artifact for replay consumers. */
|
|
1537
1579
|
readonly finalOutput: ReplayTraceFinalOutput;
|
|
1580
|
+
/** Internal hand-off for fail-fast coordinator child failure handling. */
|
|
1581
|
+
readonly triggeringFailureForAbortMode?: {
|
|
1582
|
+
readonly childRunId: string;
|
|
1583
|
+
readonly intent: string;
|
|
1584
|
+
readonly error: {
|
|
1585
|
+
readonly code: string;
|
|
1586
|
+
readonly message: string;
|
|
1587
|
+
readonly detail?: { readonly reason?: string };
|
|
1588
|
+
};
|
|
1589
|
+
readonly partialCost: { readonly usd: number };
|
|
1590
|
+
};
|
|
1538
1591
|
/**
|
|
1539
1592
|
* Ordered coordination and lifecycle events.
|
|
1540
1593
|
*
|
|
@@ -1605,7 +1658,7 @@ export interface RunMetadata {
|
|
|
1605
1658
|
* Result returned by high-level single-call APIs.
|
|
1606
1659
|
*
|
|
1607
1660
|
* The returned shape is
|
|
1608
|
-
* `{ output, eventLog, transcript, usage, metadata, accounting, trace, cost, quality, evaluation }`.
|
|
1661
|
+
* `{ output, eventLog, transcript, usage, metadata, accounting, trace, cost, quality, evaluation, health }`.
|
|
1609
1662
|
* `output` is the final synthesized answer, `eventLog` is the complete ordered
|
|
1610
1663
|
* coordination log, `transcript` is the complete agent-turn transcript,
|
|
1611
1664
|
* `usage` reports token and dollar accounting, and `metadata` exposes stable
|
|
@@ -1614,6 +1667,7 @@ export interface RunMetadata {
|
|
|
1614
1667
|
* serializable replay artifact, `cost` is retained as a compatibility alias
|
|
1615
1668
|
* for `usage`, and `quality` and `evaluation` are present when a judge or
|
|
1616
1669
|
* benchmark supplies a normalized score and serializable evaluation payload.
|
|
1670
|
+
* `health` exposes machine-readable diagnostics once computed by the runtime.
|
|
1617
1671
|
*/
|
|
1618
1672
|
export interface RunResult {
|
|
1619
1673
|
/** Final synthesized answer for the supplied intent. */
|
|
@@ -1641,6 +1695,15 @@ export interface RunResult {
|
|
|
1641
1695
|
readonly quality?: NormalizedQualityScore;
|
|
1642
1696
|
/** Optional serializable evaluation data supplied by a caller-owned evaluator. */
|
|
1643
1697
|
readonly evaluation?: RunEvaluation;
|
|
1698
|
+
/**
|
|
1699
|
+
* Machine-readable health summary for the run, auto-computed from trace events.
|
|
1700
|
+
*
|
|
1701
|
+
* Always present. Re-computed identically by `replay()` from the same trace —
|
|
1702
|
+
* contains no information beyond what the trace events carry. Use
|
|
1703
|
+
* `computeHealth(trace, thresholds)` from `@dogpile/sdk/runtime/health` to
|
|
1704
|
+
* re-compute with custom thresholds on a stored trace.
|
|
1705
|
+
*/
|
|
1706
|
+
readonly health: RunHealthSummary;
|
|
1644
1707
|
}
|
|
1645
1708
|
|
|
1646
1709
|
/**
|
|
@@ -1649,6 +1712,69 @@ export interface RunResult {
|
|
|
1649
1712
|
*/
|
|
1650
1713
|
export type RunEvaluator = (result: Omit<RunResult, "quality" | "evaluation">) => RunEvaluation | Promise<RunEvaluation>;
|
|
1651
1714
|
|
|
1715
|
+
/**
|
|
1716
|
+
* Machine-readable code identifying a health anomaly detected in a completed run.
|
|
1717
|
+
*
|
|
1718
|
+
* - `"runaway-turns"`: an agent exceeded the configured per-agent turn threshold.
|
|
1719
|
+
* - `"budget-near-miss"`: budget utilization exceeded the configured near-miss threshold.
|
|
1720
|
+
* - `"empty-contribution"`: an agent produced an empty (blank/whitespace) output turn.
|
|
1721
|
+
* - `"provider-error-recovered"`: a provider call failed and was retried successfully.
|
|
1722
|
+
* Detection is deferred — computeHealth never emits this code in Phase 7 because no
|
|
1723
|
+
* trace signal exists without an event-shape change. The code is reserved for future use.
|
|
1724
|
+
*/
|
|
1725
|
+
export type AnomalyCode =
|
|
1726
|
+
| "runaway-turns"
|
|
1727
|
+
| "budget-near-miss"
|
|
1728
|
+
| "empty-contribution"
|
|
1729
|
+
| "provider-error-recovered";
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* A single health anomaly detected in a completed run trace.
|
|
1733
|
+
*
|
|
1734
|
+
* All fields are required except `agentId`, which is present for per-agent anomalies
|
|
1735
|
+
* (`"runaway-turns"`, `"empty-contribution"`, `"provider-error-recovered"`) and absent
|
|
1736
|
+
* for global anomalies (`"budget-near-miss"`).
|
|
1737
|
+
*/
|
|
1738
|
+
export interface HealthAnomaly {
|
|
1739
|
+
/** Machine-readable anomaly identifier. */
|
|
1740
|
+
readonly code: AnomalyCode;
|
|
1741
|
+
/** Severity level: `"error"` for runaway turns and empty contributions; `"warning"` for near-miss and recovered patterns. */
|
|
1742
|
+
readonly severity: "warning" | "error";
|
|
1743
|
+
/** Actual measured value that triggered the anomaly (turn count, utilization %, etc.). */
|
|
1744
|
+
readonly value: number;
|
|
1745
|
+
/** Threshold value that was exceeded (for comparison in UIs and alerting). */
|
|
1746
|
+
readonly threshold: number;
|
|
1747
|
+
/** Agent that triggered the anomaly, present for per-agent anomaly codes. */
|
|
1748
|
+
readonly agentId?: string;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* Machine-readable health summary for a completed run, auto-computed from trace events.
|
|
1753
|
+
*
|
|
1754
|
+
* Always present on {@link RunResult}. Re-computed identically by `replay()` from the
|
|
1755
|
+
* same trace — no information is stored beyond what the trace events contain.
|
|
1756
|
+
*
|
|
1757
|
+
* Use `computeHealth(trace, thresholds)` from `@dogpile/sdk/runtime/health` to re-compute
|
|
1758
|
+
* with custom thresholds.
|
|
1759
|
+
*/
|
|
1760
|
+
export interface RunHealthSummary {
|
|
1761
|
+
/** Detected health anomalies. Empty array when no anomalies are found. */
|
|
1762
|
+
readonly anomalies: readonly HealthAnomaly[];
|
|
1763
|
+
/** Derived stats computed from trace events. */
|
|
1764
|
+
readonly stats: {
|
|
1765
|
+
/** Total number of agent-turn events in the trace. */
|
|
1766
|
+
readonly totalTurns: number;
|
|
1767
|
+
/** Number of unique agents that produced at least one turn. */
|
|
1768
|
+
readonly agentCount: number;
|
|
1769
|
+
/**
|
|
1770
|
+
* Budget utilization as a percentage (0–100+).
|
|
1771
|
+
* `null` when no USD cap was configured for the run.
|
|
1772
|
+
* Computed as `(finalCost / maxUsd) * 100`.
|
|
1773
|
+
*/
|
|
1774
|
+
readonly budgetUtilizationPct: number | null;
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1652
1778
|
/**
|
|
1653
1779
|
* Mission supplied to a high-level Dogpile workflow call.
|
|
1654
1780
|
*
|
|
@@ -1760,8 +1886,74 @@ export interface DogpileOptions extends BudgetCostTierOptions {
|
|
|
1760
1886
|
readonly seed?: string | number;
|
|
1761
1887
|
/** Optional caller cancellation signal passed to provider-facing model requests. */
|
|
1762
1888
|
readonly signal?: AbortSignal;
|
|
1889
|
+
/**
|
|
1890
|
+
* Optional duck-typed OTEL-compatible tracer. When provided, the SDK emits
|
|
1891
|
+
* spans for run start/end, sub-run start/end, agent-turn start/end, and
|
|
1892
|
+
* model-call start/end with correct parent-child ancestry. When absent the
|
|
1893
|
+
* run completes with zero span overhead — no allocations, no branch cost.
|
|
1894
|
+
* `replay()` and `replayStream()` ignore this field entirely.
|
|
1895
|
+
* See {@link DogpileTracer} in `@dogpile/sdk/runtime/tracing`.
|
|
1896
|
+
*/
|
|
1897
|
+
readonly tracer?: DogpileTracer;
|
|
1898
|
+
/**
|
|
1899
|
+
* Optional callback object for run-completion metrics. When provided,
|
|
1900
|
+
* `onRunComplete` fires with a `RunMetricsSnapshot` at every terminal state
|
|
1901
|
+
* (completed, budget-stopped, or aborted). `onSubRunComplete` fires for each
|
|
1902
|
+
* coordinator-dispatched child run that completes. Hook errors are routed to
|
|
1903
|
+
* `logger.error` (or `console.error` when no logger is provided) and never
|
|
1904
|
+
* propagate into the run result. When absent, zero overhead — no allocations.
|
|
1905
|
+
* See `@dogpile/sdk/runtime/metrics` for the interface.
|
|
1906
|
+
*/
|
|
1907
|
+
readonly metricsHook?: MetricsHook;
|
|
1908
|
+
/**
|
|
1909
|
+
* Optional structured logger for SDK-internal diagnostics (hook errors and
|
|
1910
|
+
* future debug/info events). Implement against pino, winston, or any other
|
|
1911
|
+
* logger by satisfying the `Logger` interface from `@dogpile/sdk/runtime/logger`.
|
|
1912
|
+
* When absent, hook errors fall back to `console.error`.
|
|
1913
|
+
*/
|
|
1914
|
+
readonly logger?: Logger;
|
|
1915
|
+
/**
|
|
1916
|
+
* Maximum coordinator → sub-run recursion depth.
|
|
1917
|
+
*
|
|
1918
|
+
* Defaults to 4. Per-run values can only LOWER the engine ceiling; raising
|
|
1919
|
+
* is silently capped via
|
|
1920
|
+
* `effectiveMaxDepth = Math.min(engineMaxDepth, runMaxDepth ?? Infinity)`.
|
|
1921
|
+
* Depth overflow throws `DogpileError({ code: "invalid-configuration",
|
|
1922
|
+
* detail: { kind: "delegate-validation", reason: "depth-overflow" } })`.
|
|
1923
|
+
*/
|
|
1924
|
+
readonly maxDepth?: number;
|
|
1925
|
+
/**
|
|
1926
|
+
* Maximum delegated child runs that may execute in parallel.
|
|
1927
|
+
*
|
|
1928
|
+
* Defaults to 4. Per-run and per-decision values can only lower the engine
|
|
1929
|
+
* ceiling; the effective value is `min(engine, run ?? Infinity, decision ?? Infinity)`.
|
|
1930
|
+
*/
|
|
1931
|
+
readonly maxConcurrentChildren?: number;
|
|
1932
|
+
/**
|
|
1933
|
+
* Fallback timeout (milliseconds) applied to delegated sub-runs when neither
|
|
1934
|
+
* the parent's `budget.timeoutMs` nor the decision-level
|
|
1935
|
+
* `decision.budget.timeoutMs` specifies one (BUDGET-02 / D-14).
|
|
1936
|
+
*
|
|
1937
|
+
* Precedence (most specific wins):
|
|
1938
|
+
* `decision.budget.timeoutMs` > parent's remaining deadline (when parent has
|
|
1939
|
+
* `budget.timeoutMs`) > `defaultSubRunTimeoutMs` > undefined.
|
|
1940
|
+
*
|
|
1941
|
+
* Default: `undefined` (preserves the "no sub-run timeout" posture).
|
|
1942
|
+
*/
|
|
1943
|
+
readonly defaultSubRunTimeoutMs?: number;
|
|
1944
|
+
/**
|
|
1945
|
+
* Controls how coordinator runs react after a real delegated child failure.
|
|
1946
|
+
*
|
|
1947
|
+
* Defaults to `"continue"`, which re-issues the coordinator plan turn with
|
|
1948
|
+
* structured failure context. `"abort"` skips that follow-up plan turn and
|
|
1949
|
+
* records the triggering child failure for the unhandled-failure throw path.
|
|
1950
|
+
*/
|
|
1951
|
+
readonly onChildFailure?: OnChildFailureMode;
|
|
1763
1952
|
}
|
|
1764
1953
|
|
|
1954
|
+
/** Coordinator behavior after a real child failure in a delegated dispatch wave. */
|
|
1955
|
+
export type OnChildFailureMode = "continue" | "abort";
|
|
1956
|
+
|
|
1765
1957
|
/**
|
|
1766
1958
|
* Low-level engine configuration for reusable protocol execution.
|
|
1767
1959
|
*
|
|
@@ -1824,6 +2016,89 @@ export interface EngineOptions {
|
|
|
1824
2016
|
readonly seed?: string | number;
|
|
1825
2017
|
/** Optional caller cancellation signal passed to provider-facing model requests. */
|
|
1826
2018
|
readonly signal?: AbortSignal;
|
|
2019
|
+
/**
|
|
2020
|
+
* Optional duck-typed OTEL-compatible tracer. When provided, the SDK emits
|
|
2021
|
+
* spans for run start/end, sub-run start/end, agent-turn start/end, and
|
|
2022
|
+
* model-call start/end with correct parent-child ancestry. When absent the
|
|
2023
|
+
* run completes with zero span overhead — no allocations, no branch cost.
|
|
2024
|
+
* `replay()` and `replayStream()` ignore this field entirely.
|
|
2025
|
+
* See {@link DogpileTracer} in `@dogpile/sdk/runtime/tracing`.
|
|
2026
|
+
*/
|
|
2027
|
+
readonly tracer?: DogpileTracer;
|
|
2028
|
+
/**
|
|
2029
|
+
* Optional callback object for run-completion metrics. When provided,
|
|
2030
|
+
* `onRunComplete` fires with a `RunMetricsSnapshot` at every terminal state
|
|
2031
|
+
* (completed, budget-stopped, or aborted). `onSubRunComplete` fires for each
|
|
2032
|
+
* coordinator-dispatched child run that completes. Hook errors are routed to
|
|
2033
|
+
* `logger.error` (or `console.error` when no logger is provided) and never
|
|
2034
|
+
* propagate into the run result. When absent, zero overhead — no allocations.
|
|
2035
|
+
* See `@dogpile/sdk/runtime/metrics` for the interface.
|
|
2036
|
+
*/
|
|
2037
|
+
readonly metricsHook?: MetricsHook;
|
|
2038
|
+
/**
|
|
2039
|
+
* Optional structured logger for SDK-internal diagnostics (hook errors and
|
|
2040
|
+
* future debug/info events). Implement against pino, winston, or any other
|
|
2041
|
+
* logger by satisfying the `Logger` interface from `@dogpile/sdk/runtime/logger`.
|
|
2042
|
+
* When absent, hook errors fall back to `console.error`.
|
|
2043
|
+
*/
|
|
2044
|
+
readonly logger?: Logger;
|
|
2045
|
+
/**
|
|
2046
|
+
* Maximum coordinator → sub-run recursion depth ceiling.
|
|
2047
|
+
*
|
|
2048
|
+
* Defaults to 4. Per-run lowering happens at `engine.run` / `engine.stream`
|
|
2049
|
+
* call sites via {@link RunCallOptions.maxDepth}; per-run can only lower this
|
|
2050
|
+
* ceiling. Depth overflow throws `DogpileError({ code: "invalid-configuration",
|
|
2051
|
+
* detail: { kind: "delegate-validation", reason: "depth-overflow" } })`.
|
|
2052
|
+
*/
|
|
2053
|
+
readonly maxDepth?: number;
|
|
2054
|
+
/**
|
|
2055
|
+
* Maximum delegated child runs that may execute in parallel.
|
|
2056
|
+
*
|
|
2057
|
+
* Defaults to 4. Per-run lowering happens at `engine.run` / `engine.stream`
|
|
2058
|
+
* call sites via {@link RunCallOptions.maxConcurrentChildren}.
|
|
2059
|
+
*/
|
|
2060
|
+
readonly maxConcurrentChildren?: number;
|
|
2061
|
+
/**
|
|
2062
|
+
* Fallback timeout (milliseconds) applied to delegated sub-runs when neither
|
|
2063
|
+
* the parent's `budget.timeoutMs` nor the decision-level
|
|
2064
|
+
* `decision.budget.timeoutMs` specifies one (BUDGET-02 / D-14).
|
|
2065
|
+
*
|
|
2066
|
+
* Precedence (most specific wins):
|
|
2067
|
+
* `decision.budget.timeoutMs` > parent's remaining deadline (when parent has
|
|
2068
|
+
* `budget.timeoutMs`) > `defaultSubRunTimeoutMs` > undefined.
|
|
2069
|
+
*
|
|
2070
|
+
* Default: `undefined` (preserves the "no sub-run timeout" posture).
|
|
2071
|
+
*/
|
|
2072
|
+
readonly defaultSubRunTimeoutMs?: number;
|
|
2073
|
+
/**
|
|
2074
|
+
* Controls how coordinator runs react after a real delegated child failure.
|
|
2075
|
+
*
|
|
2076
|
+
* Defaults to `"continue"`. `"abort"` skips the follow-up coordinator plan
|
|
2077
|
+
* turn and records the triggering child failure for fail-fast callers.
|
|
2078
|
+
*/
|
|
2079
|
+
readonly onChildFailure?: OnChildFailureMode;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Per-call overrides accepted by {@link Engine.run} and {@link Engine.stream}.
|
|
2084
|
+
*
|
|
2085
|
+
* @remarks
|
|
2086
|
+
* Only fields that should be controllable per-mission live here. Today the
|
|
2087
|
+
* fields are controls that can only LOWER the engine's ceiling.
|
|
2088
|
+
*/
|
|
2089
|
+
export interface RunCallOptions {
|
|
2090
|
+
/**
|
|
2091
|
+
* Per-run maximum recursion depth. Cannot raise the engine's ceiling — the
|
|
2092
|
+
* effective value is `Math.min(engine.maxDepth ?? 4, runOptions.maxDepth ?? Infinity)`.
|
|
2093
|
+
*/
|
|
2094
|
+
readonly maxDepth?: number;
|
|
2095
|
+
/**
|
|
2096
|
+
* Per-run delegated child concurrency ceiling. Cannot raise the engine's
|
|
2097
|
+
* ceiling.
|
|
2098
|
+
*/
|
|
2099
|
+
readonly maxConcurrentChildren?: number;
|
|
2100
|
+
/** Per-run child-failure behavior. Overrides the engine default. */
|
|
2101
|
+
readonly onChildFailure?: OnChildFailureMode;
|
|
1827
2102
|
}
|
|
1828
2103
|
|
|
1829
2104
|
/**
|
|
@@ -1903,7 +2178,7 @@ export interface StreamSubscription {
|
|
|
1903
2178
|
*/
|
|
1904
2179
|
export interface Engine {
|
|
1905
2180
|
/** Execute a mission to completion and return the final result. */
|
|
1906
|
-
run(intent: string): Promise<RunResult>;
|
|
2181
|
+
run(intent: string, options?: RunCallOptions): Promise<RunResult>;
|
|
1907
2182
|
/** Stream a mission's events while preserving access to the final result. */
|
|
1908
|
-
stream(intent: string): StreamHandle;
|
|
2183
|
+
stream(intent: string, options?: RunCallOptions): StreamHandle;
|
|
1909
2184
|
}
|