@statelyai/agent 2.0.0-alpha.31 → 2.0.0-alpha.33

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/ai-sdk.cjs +3 -3
  3. package/dist/ai-sdk.d.cts +1 -1
  4. package/dist/ai-sdk.d.mts +1 -1
  5. package/dist/ai-sdk.mjs +3 -3
  6. package/dist/{decision-Iys2hzg3.cjs → decision-BPdEaxPf.cjs} +1 -1
  7. package/dist/{decision-DqO018Tp.mjs → decision-CV7WiV5C.mjs} +1 -1
  8. package/dist/{event-log-Bdww2l1D.cjs → event-log-CKWeC7H-.cjs} +22 -3
  9. package/dist/{event-log-DE430ZCa.mjs → event-log-DAqsalT1.mjs} +22 -3
  10. package/dist/{event-log-store-CCWdTPEP.mjs → event-log-store-BGehvVTb.mjs} +2 -2
  11. package/dist/{event-log-store-DTf_OzB-.d.cts → event-log-store-C2NjVlWU.d.mts} +13 -5
  12. package/dist/{event-log-store-BWMLi6oh.cjs → event-log-store-DKyE7JKr.cjs} +2 -2
  13. package/dist/{event-log-store-RziIobdW.d.mts → event-log-store-s73r1Hxf.d.cts} +13 -5
  14. package/dist/index.cjs +5 -5
  15. package/dist/index.d.cts +9 -8
  16. package/dist/index.d.mts +9 -8
  17. package/dist/index.mjs +5 -5
  18. package/dist/log.cjs +40 -5
  19. package/dist/log.d.cts +1 -1
  20. package/dist/log.d.mts +1 -1
  21. package/dist/log.mjs +40 -5
  22. package/dist/machines.cjs +1 -1
  23. package/dist/machines.mjs +1 -1
  24. package/dist/{model-source-DQ7KgJaT.cjs → model-source-BQ97_l1-.cjs} +1 -1
  25. package/dist/{model-source-CXsSZPq0.mjs → model-source-BilDEyqk.mjs} +1 -1
  26. package/dist/openai.cjs +2 -2
  27. package/dist/openai.d.cts +1 -1
  28. package/dist/openai.d.mts +1 -1
  29. package/dist/openai.mjs +2 -2
  30. package/dist/otel.d.cts +1 -1
  31. package/dist/otel.d.mts +1 -1
  32. package/dist/{run-agent-DWZ1uyBJ.mjs → run-agent-2UnSUhDb.mjs} +7 -5
  33. package/dist/{run-agent-D4MwS5GY.d.mts → run-agent-Atu-wEk7.d.mts} +3 -3
  34. package/dist/{run-agent-B5opVUxx.d.cts → run-agent-B5QhabdY.d.cts} +3 -3
  35. package/dist/{run-agent-tmk58M0x.cjs → run-agent-Cg0xd3K-.cjs} +7 -5
  36. package/dist/{setup-agent-yFFVXf5s.d.cts → setup-agent-BiF1N3td.d.cts} +2 -2
  37. package/dist/{setup-agent-BaffhCcM.mjs → setup-agent-CmhB-U5P.mjs} +2 -2
  38. package/dist/{setup-agent-D0L8Anl_.cjs → setup-agent-CwUJyqKB.cjs} +2 -2
  39. package/dist/{setup-agent-CPyg2ic7.d.mts → setup-agent-J9f_Wu5T.d.mts} +2 -2
  40. package/dist/tanstack-ai.cjs +3 -3
  41. package/dist/tanstack-ai.d.cts +1 -1
  42. package/dist/tanstack-ai.d.mts +1 -1
  43. package/dist/tanstack-ai.mjs +3 -3
  44. package/dist/testing.cjs +495 -5
  45. package/dist/testing.d.cts +389 -5
  46. package/dist/testing.d.mts +389 -5
  47. package/dist/testing.mjs +491 -6
  48. package/dist/{text-logic-j9hShB7d.d.cts → text-logic-CYP502VT.d.cts} +5 -3
  49. package/dist/{text-logic-BwdrDpO9.d.mts → text-logic-DuK9HIFM.d.mts} +5 -3
  50. package/dist/{usage-BYqv7VBw.d.cts → usage-D7JKAxLc.d.mts} +1 -1
  51. package/dist/{usage-Bl4nK8D-.d.mts → usage-DVw-646x.d.cts} +1 -1
  52. package/dist/validate.cjs +3 -3
  53. package/dist/validate.d.cts +2 -2
  54. package/dist/validate.d.mts +2 -2
  55. package/dist/validate.mjs +3 -3
  56. package/dist/{verify-tkymWz6X.d.mts → verify-BVz4cURF.d.mts} +1 -1
  57. package/dist/{verify-CS_xxvVU.cjs → verify-CS_WLRXn.cjs} +19 -3
  58. package/dist/{verify-BH5e0XLK.mjs → verify-DgB8P-Wx.mjs} +14 -4
  59. package/dist/{verify-CPKDPMwY.d.cts → verify-Dk3Vwnha.d.cts} +1 -1
  60. package/package.json +1 -1
  61. package/skills/add-evals/SKILL.md +8 -2
  62. package/skills/improve-machine/SKILL.md +1 -1
@@ -1,5 +1,5 @@
1
- const require_event_log = require("./event-log-Bdww2l1D.cjs");
2
- const require_decision = require("./decision-Iys2hzg3.cjs");
1
+ const require_event_log = require("./event-log-CKWeC7H-.cjs");
2
+ const require_decision = require("./decision-BPdEaxPf.cjs");
3
3
  let xstate = require("xstate");
4
4
  //#region src/steps.ts
5
5
  /**
@@ -1223,10 +1223,20 @@ async function canReach(machine, target, options = {}) {
1223
1223
  };
1224
1224
  return {
1225
1225
  reachable: false,
1226
- complete: !report.hitPathCap && report.unexpandedEvents.length === 0 && report.terminals.every((terminal) => terminal.status === "done" || terminal.status === "idle" || terminal.status === "error"),
1226
+ complete: isExplorationComplete(report),
1227
1227
  ...resolvedTarget ? { target: resolvedTarget } : {}
1228
1228
  };
1229
1229
  }
1230
+ /**
1231
+ * Whether an `explorePaths` report covers every path: no cap cut it short,
1232
+ * every payload was expanded, and every branch ended on its own. `done`,
1233
+ * `idle`, and `error` end a branch the machine itself ended; any other
1234
+ * terminal stopped a branch the search did not explore.
1235
+ * @internal
1236
+ */
1237
+ function isExplorationComplete(report) {
1238
+ return !report.hitPathCap && report.unexpandedEvents.length === 0 && report.terminals.every((terminal) => terminal.status === "done" || terminal.status === "idle" || terminal.status === "error");
1239
+ }
1230
1240
  //#endregion
1231
1241
  Object.defineProperty(exports, "AgentLintError", {
1232
1242
  enumerable: true,
@@ -1258,6 +1268,12 @@ Object.defineProperty(exports, "explorePaths", {
1258
1268
  return explorePaths;
1259
1269
  }
1260
1270
  });
1271
+ Object.defineProperty(exports, "isExplorationComplete", {
1272
+ enumerable: true,
1273
+ get: function() {
1274
+ return isExplorationComplete;
1275
+ }
1276
+ });
1261
1277
  Object.defineProperty(exports, "lintAgentMachine", {
1262
1278
  enumerable: true,
1263
1279
  get: function() {
@@ -1,5 +1,5 @@
1
- import { P as isTextLogic, U as getRegisteredAgentExecutionOptions, V as executorBoundLogics, X as getJsonSchemaSync, lt as isRecord, ut as AgentError } from "./event-log-DE430ZCa.mjs";
2
- import { d as getAcceptedEvents, f as getHumanEventTypes, l as resolveDecision, n as acceptedDecisionOptions, p as isEventPattern, s as isDecisionLogic, t as AgentDecisionExhaustedError } from "./decision-DqO018Tp.mjs";
1
+ import { P as isTextLogic, U as getRegisteredAgentExecutionOptions, V as executorBoundLogics, X as getJsonSchemaSync, lt as isRecord, ut as AgentError } from "./event-log-DAqsalT1.mjs";
2
+ import { d as getAcceptedEvents, f as getHumanEventTypes, l as resolveDecision, n as acceptedDecisionOptions, p as isEventPattern, s as isDecisionLogic, t as AgentDecisionExhaustedError } from "./decision-CV7WiV5C.mjs";
3
3
  import { getNextTransitions, initialTransition, machineToJSON, transition } from "xstate";
4
4
  //#region src/steps.ts
5
5
  /**
@@ -1223,9 +1223,19 @@ async function canReach(machine, target, options = {}) {
1223
1223
  };
1224
1224
  return {
1225
1225
  reachable: false,
1226
- complete: !report.hitPathCap && report.unexpandedEvents.length === 0 && report.terminals.every((terminal) => terminal.status === "done" || terminal.status === "idle" || terminal.status === "error"),
1226
+ complete: isExplorationComplete(report),
1227
1227
  ...resolvedTarget ? { target: resolvedTarget } : {}
1228
1228
  };
1229
1229
  }
1230
+ /**
1231
+ * Whether an `explorePaths` report covers every path: no cap cut it short,
1232
+ * every payload was expanded, and every branch ended on its own. `done`,
1233
+ * `idle`, and `error` end a branch the machine itself ended; any other
1234
+ * terminal stopped a branch the search did not explore.
1235
+ * @internal
1236
+ */
1237
+ function isExplorationComplete(report) {
1238
+ return !report.hitPathCap && report.unexpandedEvents.length === 0 && report.terminals.every((terminal) => terminal.status === "done" || terminal.status === "idle" || terminal.status === "error");
1239
+ }
1230
1240
  //#endregion
1231
- export { explorePaths as a, canReach as i, AgentUnknownStateError as n, lintAgentMachine as o, assertAgentMachine as r, simulateAgent as s, AgentLintError as t };
1241
+ export { explorePaths as a, simulateAgent as c, canReach as i, AgentUnknownStateError as n, isExplorationComplete as o, assertAgentMachine as r, lintAgentMachine as s, AgentLintError as t };
@@ -1,5 +1,5 @@
1
1
  import { u as ChosenEvent } from "./types-Dp5_Ru4R.cjs";
2
- import { Q as AgentError } from "./text-logic-j9hShB7d.cjs";
2
+ import { Q as AgentError } from "./text-logic-CYP502VT.cjs";
3
3
  import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
4
4
  //#region src/verify.d.ts
5
5
  /** Severity of an {@link AgentLintDiagnostic}. `error` findings fail CI/the CLI; `warning`s are advisory. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.31",
3
+ "version": "2.0.0-alpha.33",
4
4
  "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
5
5
  "keywords": [
6
6
  "agent",
@@ -125,10 +125,16 @@ export function objective(runs: Array<{ scenario: Scenario; outcome: string; ref
125
125
 
126
126
  Read the terminal state from the event logs `add-traces` recorded (`replay(machine, entries).snapshot`, `replay` from `@statelyai/agent/log`). Effects and violations live in the world, not the log: save them next to the thread id when the run ends, so the objective can be recomputed without running anything. Use `matchesTrajectory` only for an ordering a person requires (approval before payment), never to pin the whole path; build its input from the `machine.transition` trace events' `snapshot.value`.
127
127
 
128
- **Stats.** `foldTraces(traces, { failed })` (from `@statelyai/agent/testing`) returns `{ state, visits, failures, withheld }` per state. A failed run counts against **every** state it visited, so states after a bad decision rank as high as the decision itself. Use the table to see which states failing runs pass through, then look at the decision states among them, their `withheld` counts, and their decision attempts. `failed` sees only the trace: to judge a run against its label, keep a map from trace to scenario.
128
+ **Reliability.** A live model is measured over repeated runs. `repeatRuns({ scenarios, k, run, passed })` (from `@statelyai/agent/testing`) runs each scenario `k` times and reports `passes`, `passAll` (pass^k), `distinctPaths`, and `divergedAt`, the state where its runs went different ways. Report `report.passHat(k)` next to `report.passHat(1)`. For runs recorded elsewhere, `summarizeRepeats` takes them per scenario.
129
+
130
+ **Judged evals.** Where a model grades text because no ground truth exists, measure the judge first: `judgeAgreement(rows, { positive })` over confirmed labels, grouped by the state or request it judges. Report the true positive and true negative rates, and gate on the judge only after the user accepts them. Use `report.correct(p)` to turn the judge's rate on unlabeled runs into an estimate.
131
+
132
+ **Stats.** `foldTraces(traces, { failed, blame })` (from `@statelyai/agent/testing`) returns `{ state, visits, failures, withheld, ignored, blamed }` per state. A failed run counts in `failures` against **every** state it visited, so states after a bad decision rank as high as the decision itself. `blame` counts each failed run once, against the state it started failing in: `blame: (trace) => firstDivergence(trace, reference)?.state`, where the reference is a passing run of the same scenario or the trajectory a person expects. Sort by `blamed`, then look at the decision states among the top rows, their `withheld` counts, and their decision attempts. `failed` sees only the trace: to judge a run against its label, keep a map from trace to scenario.
129
133
 
130
134
  ## 5. Coverage
131
135
 
136
+ Run `traceCoverage(machine, traces, { reachable })` (from `@statelyai/agent/testing`) over the traces of every scenario, with `reachable` set to an `explorePaths` report. List its `unvisitedStates` and `unvisitedHandlers`: each one is a part of the machine no scenario exercises. Draft a scenario for each, as below. Handlers in `unobservable` (`always` transitions) do not show in traces; say so, and do not draft scenarios for them.
137
+
132
138
  If every decider scores the same on the confirmed scenarios, the scenarios cannot tell a better decider from a worse one. Draft scenarios on the boundaries the evals found (an amount just under and over a threshold, a partial request), label them as drafts, and ask the user to confirm them and add them to the scenario set. They become part of the train or held-out split only once confirmed.
133
139
 
134
140
  ## 6. Baseline
@@ -139,6 +145,6 @@ Run every eval once on the current machine and record the numbers: which pass, t
139
145
 
140
146
  1. The state mapping from step 2.
141
147
  2. The evals by level, each named by state.
142
- 3. The baseline numbers, train and held-out separately.
148
+ 3. The baseline numbers, train and held-out separately, with pass^k for live-model evals and the coverage ratios.
143
149
  4. Every failing eval and the state it points at.
144
150
  5. Next step: `improve-machine`, with the objective from step 4 as its scorer.
@@ -197,7 +197,7 @@ const failed = verified.gates.find((gate) => !gate.ok);
197
197
  Run the candidate on the training scenarios, then on the held-out scenarios. Write every replay to the store under new thread ids that name the split and version, in the scheme `add-traces` set up (`train:v3:<scenario>:r1`, `held-out:v3:<scenario>:r1`), so the next round can list them by prefix. With no persistent store, write each thread's `result.events` to a file.
198
198
 
199
199
  - Run the current policy and the candidate on the same scenarios, the same world state, and the same model refs.
200
- - Model calls are nondeterministic. Run each scenario k times (k ≥ 3 when calls are not cached) and compare means.
200
+ - Model calls are nondeterministic. Run each scenario k times (k ≥ 3 when calls are not cached) with `repeatRuns` (from `@statelyai/agent/testing`), and compare `passHat(k)` as well as the mean. A candidate that raises the mean but lowers pass^k made the agent less reliable.
201
201
  - Compute the objective, invariant violations, and cost per split, for both versions.
202
202
 
203
203
  ## 7. Recommend or discard