agentfootprint 1.8.0 → 1.10.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.
Files changed (49) hide show
  1. package/dist/esm/exportTrace.js +72 -0
  2. package/dist/esm/exportTrace.js.map +1 -0
  3. package/dist/esm/index.js +2 -0
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/patterns/index.js +18 -0
  6. package/dist/esm/patterns/index.js.map +1 -0
  7. package/dist/esm/patterns/mapReduce.js +60 -0
  8. package/dist/esm/patterns/mapReduce.js.map +1 -0
  9. package/dist/esm/patterns/planExecute.js +43 -0
  10. package/dist/esm/patterns/planExecute.js.map +1 -0
  11. package/dist/esm/patterns/reflexion.js +58 -0
  12. package/dist/esm/patterns/reflexion.js.map +1 -0
  13. package/dist/esm/patterns/treeOfThoughts.js +71 -0
  14. package/dist/esm/patterns/treeOfThoughts.js.map +1 -0
  15. package/dist/esm/patterns.barrel.js +8 -0
  16. package/dist/esm/patterns.barrel.js.map +1 -0
  17. package/dist/exportTrace.js +76 -0
  18. package/dist/exportTrace.js.map +1 -0
  19. package/dist/index.js +5 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/patterns/index.js +25 -0
  22. package/dist/patterns/index.js.map +1 -0
  23. package/dist/patterns/mapReduce.js +64 -0
  24. package/dist/patterns/mapReduce.js.map +1 -0
  25. package/dist/patterns/planExecute.js +47 -0
  26. package/dist/patterns/planExecute.js.map +1 -0
  27. package/dist/patterns/reflexion.js +62 -0
  28. package/dist/patterns/reflexion.js.map +1 -0
  29. package/dist/patterns/treeOfThoughts.js +75 -0
  30. package/dist/patterns/treeOfThoughts.js.map +1 -0
  31. package/dist/patterns.barrel.js +24 -0
  32. package/dist/patterns.barrel.js.map +1 -0
  33. package/dist/types/exportTrace.d.ts +85 -0
  34. package/dist/types/exportTrace.d.ts.map +1 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/patterns/index.d.ts +22 -0
  38. package/dist/types/patterns/index.d.ts.map +1 -0
  39. package/dist/types/patterns/mapReduce.d.ts +65 -0
  40. package/dist/types/patterns/mapReduce.d.ts.map +1 -0
  41. package/dist/types/patterns/planExecute.d.ts +49 -0
  42. package/dist/types/patterns/planExecute.d.ts.map +1 -0
  43. package/dist/types/patterns/reflexion.d.ts +65 -0
  44. package/dist/types/patterns/reflexion.d.ts.map +1 -0
  45. package/dist/types/patterns/treeOfThoughts.d.ts +65 -0
  46. package/dist/types/patterns/treeOfThoughts.d.ts.map +1 -0
  47. package/dist/types/patterns.barrel.d.ts +8 -0
  48. package/dist/types/patterns.barrel.d.ts.map +1 -0
  49. package/package.json +11 -3
@@ -0,0 +1,72 @@
1
+ /**
2
+ * exportTrace — capture an agent run's full state into a portable JSON
3
+ * blob for sharing externally (paste into a viewer, ship to support, log
4
+ * for debugging, store in a database).
5
+ *
6
+ * Defaults to **redacted** output: snapshots come from
7
+ * `getSnapshot({ redact: true })` (footprintjs 4.14+), so values for keys
8
+ * listed in `RedactionPolicy.keys` / matching `patterns` arrive as
9
+ * `'REDACTED'` instead of raw. The commit log is already redacted at
10
+ * write-time. Combined with `emitPatterns` (also redacted at origin), the
11
+ * exported trace is safe to share when the caller has configured a policy.
12
+ *
13
+ * **Without a redaction policy, this helper still emits a trace — but
14
+ * `sharedState` will contain raw values.** Configure `setRedactionPolicy`
15
+ * before calling this for any externally shared trace.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { Agent, exportTrace, anthropic } from 'agentfootprint';
20
+ *
21
+ * const agent = Agent.create({ provider: anthropic('claude-sonnet-4') })
22
+ * .system('You are a customer support agent.')
23
+ * .build();
24
+ *
25
+ * await agent.run('My credit card 4242-4242-4242-4242 was declined');
26
+ *
27
+ * // Configure policy on the underlying executor for full safety
28
+ * // (concept-level recorder API for this is a follow-up).
29
+ * const trace = exportTrace(agent);
30
+ * console.log(JSON.stringify(trace, null, 2));
31
+ * // → paste into the playground viewer, send to support, etc.
32
+ * ```
33
+ */
34
+ /**
35
+ * Capture a full execution trace from any runner exposing the standard
36
+ * introspection surface (`getSnapshot`, `getNarrative*`, `getSpec`).
37
+ * All of those methods are optional — missing methods skip the field.
38
+ *
39
+ * Always returns a JSON-stringify-safe object.
40
+ */
41
+ export function exportTrace(runner, options) {
42
+ const redact = options?.redact !== false; // default true
43
+ const r = runner;
44
+ // `getSnapshot` may be the older 0-arg form — still safe to call with
45
+ // an arg (JS ignores extras), but keep our intent explicit so older
46
+ // overloads with strict signatures don't trip the type checker.
47
+ let snapshot;
48
+ try {
49
+ snapshot = r.getSnapshot?.({ redact });
50
+ }
51
+ catch {
52
+ // Fall back to the 0-arg form if the runner's signature rejects the
53
+ // options object (older custom runners). Result will be raw — caller
54
+ // is responsible for the safety implication when this happens.
55
+ try {
56
+ snapshot = r.getSnapshot?.();
57
+ }
58
+ catch {
59
+ snapshot = undefined;
60
+ }
61
+ }
62
+ return {
63
+ schemaVersion: 1,
64
+ exportedAt: new Date().toISOString(),
65
+ redacted: redact,
66
+ snapshot,
67
+ narrativeEntries: r.getNarrativeEntries?.(),
68
+ narrative: r.getNarrative?.(),
69
+ spec: r.getSpec?.(),
70
+ };
71
+ }
72
+ //# sourceMappingURL=exportTrace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exportTrace.js","sourceRoot":"","sources":["../../src/exportTrace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AA4DH;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,OAA4B;IAC1E,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,CAAC,eAAe;IACzD,MAAM,CAAC,GAAG,MAA0B,CAAC;IAErC,sEAAsE;IACtE,oEAAoE;IACpE,gEAAgE;IAChE,IAAI,QAAiB,CAAC;IACtB,IAAI,CAAC;QACH,QAAQ,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,qEAAqE;QACrE,+DAA+D;QAC/D,IAAI,CAAC;YACH,QAAQ,GAAI,CAAC,CAAC,WAA2C,EAAE,EAAE,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,QAAQ,GAAG,SAAS,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,QAAQ,EAAE,MAAM;QAChB,QAAQ;QACR,gBAAgB,EAAE,CAAC,CAAC,mBAAmB,EAAE,EAAE;QAC3C,SAAS,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE;QAC7B,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC"}
package/dist/esm/index.js CHANGED
@@ -13,6 +13,8 @@
13
13
  */
14
14
  // ── Concepts (Builders + Runners) ───────────────────────────
15
15
  export { Agent, AgentRunner, LLMCall, LLMCallRunner, RAG, RAGRunner, FlowChart, FlowChartRunner, Swarm, SwarmRunner, Parallel, ParallelRunner, Conditional, ConditionalRunner, } from './concepts';
16
+ // ── Trace export (paste-into-viewer / share-with-support workflow) ─
17
+ export { exportTrace } from './exportTrace';
16
18
  // ── Tools ───────────────────────────────────────────────────
17
19
  export { defineTool, askHuman, ToolRegistry } from './tools';
18
20
  // ── Providers (core — you can't build an agent without these) ─
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+DAA+D;AAC/D,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,aAAa,EACb,GAAG,EACH,SAAS,EACT,SAAS,EACT,eAAe,EACf,KAAK,EACL,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB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+1,18 @@
1
+ /**
2
+ * agentfootprint/patterns — canonical agent composition patterns.
3
+ *
4
+ * Each pattern is a thin factory over the existing concepts (`FlowChart`,
5
+ * `Parallel`, `Conditional`, `Agent`, `LLMCall`, `RAG`, `Swarm`). No new
6
+ * primitives. The source of each file shows the composition — read it to
7
+ * learn how to build your own.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { treeOfThoughts, reflexion, planExecute, mapReduce } from 'agentfootprint/patterns';
12
+ * ```
13
+ */
14
+ export { planExecute } from './planExecute';
15
+ export { mapReduce } from './mapReduce';
16
+ export { treeOfThoughts } from './treeOfThoughts';
17
+ export { reflexion } from './reflexion';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/patterns/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * mapReduce — fan-out map over N pre-bound mappers, then reduce.
3
+ *
4
+ * Each mapper is a runner with its own input already bound (prepare them with
5
+ * the slice they should process). `Parallel.mergeWithLLM` or a custom reduce
6
+ * function combines the results. Under the hood: a single `Parallel` with N
7
+ * branches and one merge strategy.
8
+ *
9
+ * Why: map-reduce is a common shape — summarize N documents, compare N
10
+ * candidates, evaluate a prompt against N rubrics. Keeping it as a named
11
+ * pattern teaches the shape; each mapper / reducer is still a regular runner.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { LLMCall, anthropic } from 'agentfootprint';
16
+ * import { mapReduce } from 'agentfootprint/patterns';
17
+ *
18
+ * const documents = [doc1, doc2, doc3];
19
+ * const provider = anthropic('claude-sonnet-4');
20
+ *
21
+ * const pipeline = mapReduce({
22
+ * provider,
23
+ * mappers: documents.map((doc, i) => ({
24
+ * id: `doc-${i}`,
25
+ * description: `Summarize doc ${i}`,
26
+ * runner: LLMCall.create({ provider })
27
+ * .system(`Summarize this document:\n\n${doc}`)
28
+ * .build(),
29
+ * })),
30
+ * reduce: { mode: 'llm', prompt: 'Combine the summaries into a single report.' },
31
+ * });
32
+ *
33
+ * const result = await pipeline.run('Produce the report');
34
+ * ```
35
+ */
36
+ import { Parallel } from '../concepts/Parallel';
37
+ /**
38
+ * Build a map-reduce pipeline. Returns a `ParallelRunner` — plug it into
39
+ * `FlowChart`, `Conditional`, or `Agent.route()` like any other runner.
40
+ */
41
+ export function mapReduce(options) {
42
+ if (options.mappers.length < 2) {
43
+ throw new Error('mapReduce requires at least 2 mappers. Use a single runner directly if you only have one.');
44
+ }
45
+ const builder = Parallel.create({
46
+ provider: options.provider,
47
+ name: options.name ?? 'mapReduce',
48
+ });
49
+ for (const m of options.mappers) {
50
+ builder.agent(m.id, m.runner, m.description);
51
+ }
52
+ if (options.reduce.mode === 'llm') {
53
+ builder.mergeWithLLM(options.reduce.prompt);
54
+ }
55
+ else {
56
+ builder.merge(options.reduce.fn);
57
+ }
58
+ return builder.build();
59
+ }
60
+ //# sourceMappingURL=mapReduce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapReduce.js","sourceRoot":"","sources":["../../../src/patterns/mapReduce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,QAAQ,EAA0C,MAAM,sBAAsB,CAAC;AAwBxF;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,WAAW;KAClC,CAAC,CAAC;IACH,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAClC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * planExecute — Planner → Executor composition.
3
+ *
4
+ * Two runners chained sequentially: the planner takes the user request and
5
+ * produces a plan; the executor takes that plan (as the planner's output) and
6
+ * carries it out. Pure composition over `FlowChart` — no new primitives,
7
+ * readable as a teaching example.
8
+ *
9
+ * Why: separating planning from execution is often cheaper (small model
10
+ * plans, capable model executes) and safer (plan visible in narrative before
11
+ * any tool fires).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Agent, anthropic } from 'agentfootprint';
16
+ * import { planExecute } from 'agentfootprint/patterns';
17
+ *
18
+ * const planner = Agent.create({ provider: anthropic('claude-haiku-4-5') })
19
+ * .system('Produce a numbered plan. Do not execute.')
20
+ * .build();
21
+ *
22
+ * const executor = Agent.create({ provider: anthropic('claude-sonnet-4') })
23
+ * .system('Execute the given plan step by step.')
24
+ * .tools([...])
25
+ * .build();
26
+ *
27
+ * const runner = planExecute({ planner, executor });
28
+ * const result = await runner.run('Research competitors and draft a brief.');
29
+ * ```
30
+ */
31
+ import { FlowChart } from '../concepts/FlowChart';
32
+ /**
33
+ * Build a planner → executor pipeline. Returns a `FlowChartRunner` — plug it
34
+ * into `Parallel`, `FlowChart`, `Conditional`, or `Agent.route()` like any
35
+ * other runner.
36
+ */
37
+ export function planExecute(options) {
38
+ return FlowChart.create()
39
+ .agent('plan', options.planName ?? 'Plan', options.planner)
40
+ .agent('execute', options.executeName ?? 'Execute', options.executor)
41
+ .build();
42
+ }
43
+ //# sourceMappingURL=planExecute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planExecute.js","sourceRoot":"","sources":["../../../src/patterns/planExecute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAcxE;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,OAAO,SAAS,CAAC,MAAM,EAAE;SACtB,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC;SAC1D,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;SACpE,KAAK,EAAE,CAAC;AACb,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * reflexion — Solve → Critique → Improve (single-pass).
3
+ *
4
+ * Three runners chained sequentially: a solver produces a draft, a critic
5
+ * reviews it, an improver integrates the critique. Shinn et al. 2023's
6
+ * Reflexion pattern has a quality-gated loop; this is the simplest form —
7
+ * one reflection pass. For multi-iteration Reflexion, wrap this pattern
8
+ * inside `Conditional` to rerun while a quality predicate fails.
9
+ *
10
+ * Why: a single self-review pass catches a surprising number of errors in
11
+ * reasoning / code / plans. Exposing the three runners individually lets
12
+ * users pick cheap models for critic/improver while keeping a strong solver.
13
+ *
14
+ * Under the hood:
15
+ * FlowChart[ solver, critic, improver ]
16
+ *
17
+ * Each runner receives the previous runner's output as its input message.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { Agent, anthropic } from 'agentfootprint';
22
+ * import { reflexion } from 'agentfootprint/patterns';
23
+ *
24
+ * const provider = anthropic('claude-sonnet-4');
25
+ *
26
+ * const reviewer = reflexion({
27
+ * solver: Agent.create({ provider }).system('Draft an answer.').build(),
28
+ * critic: Agent.create({ provider }).system('List weaknesses in the draft.').build(),
29
+ * improver: Agent.create({ provider })
30
+ * .system('Apply the critique to improve the draft.')
31
+ * .build(),
32
+ * });
33
+ *
34
+ * const result = await reviewer.run('Explain monads in plain English.');
35
+ * ```
36
+ *
37
+ * For multi-iteration Reflexion (loop until quality gate passes), compose
38
+ * with `Conditional`:
39
+ * ```ts
40
+ * import { Conditional } from 'agentfootprint';
41
+ * const iterative = Conditional.create()
42
+ * .when((s) => qualityOf(s) < 0.8, reviewer)
43
+ * .otherwise(doneRunner)
44
+ * .build();
45
+ * ```
46
+ */
47
+ import { FlowChart } from '../concepts/FlowChart';
48
+ /**
49
+ * Build a Solve → Critique → Improve pipeline. Returns a `FlowChartRunner`.
50
+ */
51
+ export function reflexion(options) {
52
+ return FlowChart.create()
53
+ .agent('solve', options.solveName ?? 'Solve', options.solver)
54
+ .agent('critique', options.critiqueName ?? 'Critique', options.critic)
55
+ .agent('improve', options.improveName ?? 'Improve', options.improver)
56
+ .build();
57
+ }
58
+ //# sourceMappingURL=reflexion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflexion.js","sourceRoot":"","sources":["../../../src/patterns/reflexion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAgBxE;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,OAAO,SAAS,CAAC,MAAM,EAAE;SACtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC;SAC5D,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,IAAI,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC;SACrE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;SACpE,KAAK,EAAE,CAAC;AACb,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * treeOfThoughts — N parallel thinkers → one judge picks best.
3
+ *
4
+ * Fan out N parallel thinkers (each a runner, typically same prompt + higher
5
+ * temperature variance), format their outputs as context, then hand to a
6
+ * judge runner that picks or synthesizes the best answer.
7
+ *
8
+ * Why: for problems where one-shot answers are often wrong, generating
9
+ * multiple independent attempts and judging them catches errors that a
10
+ * single chain-of-thought would miss. Tree-of-Thoughts (Yao et al. 2023)
11
+ * formalized this pattern.
12
+ *
13
+ * Under the hood:
14
+ * FlowChart[ Parallel({ t0, t1, ..., tN-1, merge: labelled-concat }),
15
+ * judge ]
16
+ *
17
+ * The merge step concatenates each thinker's output under its id so the
18
+ * judge sees them as labeled candidates. The judge receives that
19
+ * concatenation as its input string.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { Agent, LLMCall, anthropic } from 'agentfootprint';
24
+ * import { treeOfThoughts } from 'agentfootprint/patterns';
25
+ *
26
+ * const provider = anthropic('claude-sonnet-4');
27
+ *
28
+ * const tot = treeOfThoughts({
29
+ * provider,
30
+ * branches: 3,
31
+ * thinker: (i) =>
32
+ * LLMCall.create({ provider }).system(`Thinker ${i + 1}: propose a different solution.`).build(),
33
+ * judge: Agent.create({ provider })
34
+ * .system('Pick the single best answer and explain why.')
35
+ * .build(),
36
+ * });
37
+ *
38
+ * const result = await tot.run('What is the fastest sort for nearly-sorted data?');
39
+ * ```
40
+ */
41
+ import { FlowChart } from '../concepts/FlowChart';
42
+ import { Parallel } from '../concepts/Parallel';
43
+ /**
44
+ * Build a Tree-of-Thoughts pipeline. Returns a `FlowChartRunner`.
45
+ *
46
+ * Throws if `branches < 2` — use a single runner directly when you don't need
47
+ * multiple candidates. Throws if `branches > 10` (Parallel's cap).
48
+ */
49
+ export function treeOfThoughts(options) {
50
+ if (options.branches < 2) {
51
+ throw new Error(`treeOfThoughts requires at least 2 branches (got ${options.branches}). Use a single runner for 1-candidate flows.`);
52
+ }
53
+ const parallel = Parallel.create({
54
+ provider: options.provider,
55
+ name: `${options.name ?? 'treeOfThoughts'}:thinkers`,
56
+ });
57
+ for (let i = 0; i < options.branches; i++) {
58
+ parallel.agent(`thinker-${i}`, options.thinker(i), `Thinker ${i + 1}`);
59
+ }
60
+ // Merge: label each thought so the judge can reference them by id.
61
+ // Kept as a pure function so the merge itself uses no LLM call — the judge
62
+ // is the only decision-maker and should be budgeted as such.
63
+ parallel.merge((results) => Object.entries(results)
64
+ .map(([id, r]) => `=== ${id} ===\n${r.content}`)
65
+ .join('\n\n'));
66
+ return FlowChart.create()
67
+ .agent('thinkers', 'Think', parallel.build())
68
+ .agent('judge', 'Judge', options.judge)
69
+ .build();
70
+ }
71
+ //# sourceMappingURL=treeOfThoughts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeOfThoughts.js","sourceRoot":"","sources":["../../../src/patterns/treeOfThoughts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAqB,MAAM,sBAAsB,CAAC;AAmBnE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,IAAI,OAAO,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,oDAAoD,OAAO,CAAC,QAAQ,+CAA+C,CACpH,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC/B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,WAAW;KACrD,CAAC,CAAC;IACH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,mEAAmE;IACnE,2EAA2E;IAC3E,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAqC,EAAE,EAAE,CACvD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/C,IAAI,CAAC,MAAM,CAAC,CAChB,CAAC;IAEF,OAAO,SAAS,CAAC,MAAM,EAAE;SACtB,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;SAC5C,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;SACtC,KAAK,EAAE,CAAC;AACb,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * agentfootprint/patterns — canonical composition patterns.
3
+ *
4
+ * See `src/patterns/index.ts` for the patterns themselves. This file is the
5
+ * subpath barrel used by package.json `exports['./patterns']`.
6
+ */
7
+ export * from './patterns/index';
8
+ //# sourceMappingURL=patterns.barrel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.barrel.js","sourceRoot":"","sources":["../../src/patterns.barrel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * exportTrace — capture an agent run's full state into a portable JSON
4
+ * blob for sharing externally (paste into a viewer, ship to support, log
5
+ * for debugging, store in a database).
6
+ *
7
+ * Defaults to **redacted** output: snapshots come from
8
+ * `getSnapshot({ redact: true })` (footprintjs 4.14+), so values for keys
9
+ * listed in `RedactionPolicy.keys` / matching `patterns` arrive as
10
+ * `'REDACTED'` instead of raw. The commit log is already redacted at
11
+ * write-time. Combined with `emitPatterns` (also redacted at origin), the
12
+ * exported trace is safe to share when the caller has configured a policy.
13
+ *
14
+ * **Without a redaction policy, this helper still emits a trace — but
15
+ * `sharedState` will contain raw values.** Configure `setRedactionPolicy`
16
+ * before calling this for any externally shared trace.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { Agent, exportTrace, anthropic } from 'agentfootprint';
21
+ *
22
+ * const agent = Agent.create({ provider: anthropic('claude-sonnet-4') })
23
+ * .system('You are a customer support agent.')
24
+ * .build();
25
+ *
26
+ * await agent.run('My credit card 4242-4242-4242-4242 was declined');
27
+ *
28
+ * // Configure policy on the underlying executor for full safety
29
+ * // (concept-level recorder API for this is a follow-up).
30
+ * const trace = exportTrace(agent);
31
+ * console.log(JSON.stringify(trace, null, 2));
32
+ * // → paste into the playground viewer, send to support, etc.
33
+ * ```
34
+ */
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.exportTrace = void 0;
37
+ /**
38
+ * Capture a full execution trace from any runner exposing the standard
39
+ * introspection surface (`getSnapshot`, `getNarrative*`, `getSpec`).
40
+ * All of those methods are optional — missing methods skip the field.
41
+ *
42
+ * Always returns a JSON-stringify-safe object.
43
+ */
44
+ function exportTrace(runner, options) {
45
+ const redact = options?.redact !== false; // default true
46
+ const r = runner;
47
+ // `getSnapshot` may be the older 0-arg form — still safe to call with
48
+ // an arg (JS ignores extras), but keep our intent explicit so older
49
+ // overloads with strict signatures don't trip the type checker.
50
+ let snapshot;
51
+ try {
52
+ snapshot = r.getSnapshot?.({ redact });
53
+ }
54
+ catch {
55
+ // Fall back to the 0-arg form if the runner's signature rejects the
56
+ // options object (older custom runners). Result will be raw — caller
57
+ // is responsible for the safety implication when this happens.
58
+ try {
59
+ snapshot = r.getSnapshot?.();
60
+ }
61
+ catch {
62
+ snapshot = undefined;
63
+ }
64
+ }
65
+ return {
66
+ schemaVersion: 1,
67
+ exportedAt: new Date().toISOString(),
68
+ redacted: redact,
69
+ snapshot,
70
+ narrativeEntries: r.getNarrativeEntries?.(),
71
+ narrative: r.getNarrative?.(),
72
+ spec: r.getSpec?.(),
73
+ };
74
+ }
75
+ exports.exportTrace = exportTrace;
76
+ //# sourceMappingURL=exportTrace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exportTrace.js","sourceRoot":"","sources":["../src/exportTrace.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;AA4DH;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,MAAkB,EAAE,OAA4B;IAC1E,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,CAAC,eAAe;IACzD,MAAM,CAAC,GAAG,MAA0B,CAAC;IAErC,sEAAsE;IACtE,oEAAoE;IACpE,gEAAgE;IAChE,IAAI,QAAiB,CAAC;IACtB,IAAI,CAAC;QACH,QAAQ,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,qEAAqE;QACrE,+DAA+D;QAC/D,IAAI,CAAC;YACH,QAAQ,GAAI,CAAC,CAAC,WAA2C,EAAE,EAAE,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,QAAQ,GAAG,SAAS,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,QAAQ,EAAE,MAAM;QAChB,QAAQ;QACR,gBAAgB,EAAE,CAAC,CAAC,mBAAmB,EAAE,EAAE;QAC3C,SAAS,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE;QAC7B,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC;AA9BD,kCA8BC"}
package/dist/index.js CHANGED
@@ -13,8 +13,8 @@
13
13
  * agentfootprint/stream → Real-time lifecycle events
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ToolUsageRecorder = exports.TokenRecorder = exports.quickBind = exports.AgentPattern = exports.defineInstruction = exports.agentLoop = exports.LLMError = exports.urlImage = exports.base64Image = exports.imageBlock = exports.textBlock = exports.toolResultMessage = exports.assistantMessage = exports.userMessage = exports.systemMessage = exports.postgresStore = exports.dynamoStore = exports.redisStore = exports.InMemoryStore = exports.BrowserOpenAIAdapter = exports.BrowserAnthropicAdapter = exports.BedrockAdapter = exports.OpenAIAdapter = exports.AnthropicAdapter = exports.bedrock = exports.ollama = exports.openai = exports.anthropic = exports.createProvider = exports.MockRetriever = exports.mockRetriever = exports.MockAdapter = exports.mock = exports.ToolRegistry = exports.askHuman = exports.defineTool = exports.ConditionalRunner = exports.Conditional = exports.ParallelRunner = exports.Parallel = exports.SwarmRunner = exports.Swarm = exports.FlowChartRunner = exports.FlowChart = exports.RAGRunner = exports.RAG = exports.LLMCallRunner = exports.LLMCall = exports.AgentRunner = exports.Agent = void 0;
17
- exports.CostRecorder = exports.TurnRecorder = void 0;
16
+ exports.TokenRecorder = exports.quickBind = exports.AgentPattern = exports.defineInstruction = exports.agentLoop = exports.LLMError = exports.urlImage = exports.base64Image = exports.imageBlock = exports.textBlock = exports.toolResultMessage = exports.assistantMessage = exports.userMessage = exports.systemMessage = exports.postgresStore = exports.dynamoStore = exports.redisStore = exports.InMemoryStore = exports.BrowserOpenAIAdapter = exports.BrowserAnthropicAdapter = exports.BedrockAdapter = exports.OpenAIAdapter = exports.AnthropicAdapter = exports.bedrock = exports.ollama = exports.openai = exports.anthropic = exports.createProvider = exports.MockRetriever = exports.mockRetriever = exports.MockAdapter = exports.mock = exports.ToolRegistry = exports.askHuman = exports.defineTool = exports.exportTrace = exports.ConditionalRunner = exports.Conditional = exports.ParallelRunner = exports.Parallel = exports.SwarmRunner = exports.Swarm = exports.FlowChartRunner = exports.FlowChart = exports.RAGRunner = exports.RAG = exports.LLMCallRunner = exports.LLMCall = exports.AgentRunner = exports.Agent = void 0;
17
+ exports.CostRecorder = exports.TurnRecorder = exports.ToolUsageRecorder = void 0;
18
18
  // ── Concepts (Builders + Runners) ───────────────────────────
19
19
  var concepts_1 = require("./concepts");
20
20
  Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return concepts_1.Agent; } });
@@ -31,6 +31,9 @@ Object.defineProperty(exports, "Parallel", { enumerable: true, get: function ()
31
31
  Object.defineProperty(exports, "ParallelRunner", { enumerable: true, get: function () { return concepts_1.ParallelRunner; } });
32
32
  Object.defineProperty(exports, "Conditional", { enumerable: true, get: function () { return concepts_1.Conditional; } });
33
33
  Object.defineProperty(exports, "ConditionalRunner", { enumerable: true, get: function () { return concepts_1.ConditionalRunner; } });
34
+ // ── Trace export (paste-into-viewer / share-with-support workflow) ─
35
+ var exportTrace_1 = require("./exportTrace");
36
+ Object.defineProperty(exports, "exportTrace", { enumerable: true, get: function () { return exportTrace_1.exportTrace; } });
34
37
  // ── Tools ───────────────────────────────────────────────────
35
38
  var tools_1 = require("./tools");
36
39
  Object.defineProperty(exports, "defineTool", { enumerable: true, get: function () { return tools_1.defineTool; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;AAEH,+DAA+D;AAC/D,uCAeoB;AAdlB,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,mGAAA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A6E;AAApE,4GAAA,gBAAgB,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxD,uCAA2E;AAAlE,mHAAA,uBAAuB,OAAA;AAAE,gHAAA,oBAAoB,OAAA;AACtD,uDAA2D;AAAlD,yGAAA,aAAa,OAAA;AACtB,mDAAkF;AAAzE,oGAAA,UAAU,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,uGAAA,aAAa,OAAA;AAuB/C,+DAA+D;AAC/D,iCASiB;AARf,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,yGAAA,gBAAgB,OAAA;AAChB,0GAAA,iBAAiB,OAAA;AACjB,kGAAA,SAAS,OAAA;AACT,mGAAA,UAAU,OAAA;AACV,oGAAA,WAAW,OAAA;AACX,iGAAA,QAAQ,OAAA;AAGV,+DAA+D;AAC/D,iCAAmC;AAA1B,iGAAA,QAAQ,OAAA;AA0BjB,8DAA8D;AAC9D,uCAAuC;AAA9B,qGAAA,SAAS,OAAA;AAGlB,uEAAuE;AACvE,6DAAmF;AAA1E,wHAAA,iBAAiB,OAAA;AAAE,mHAAA,YAAY,OAAA;AAAE,gHAAA,SAAS,OAAA;AAGnD,+DAA+D;AAC/D,mDAAgG;AAAvF,+GAAA,aAAa,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAAE,8GAAA,YAAY,OAAA;AAAE,8GAAA,YAAY,OAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * agentfootprint/patterns — canonical agent composition patterns.
4
+ *
5
+ * Each pattern is a thin factory over the existing concepts (`FlowChart`,
6
+ * `Parallel`, `Conditional`, `Agent`, `LLMCall`, `RAG`, `Swarm`). No new
7
+ * primitives. The source of each file shows the composition — read it to
8
+ * learn how to build your own.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { treeOfThoughts, reflexion, planExecute, mapReduce } from 'agentfootprint/patterns';
13
+ * ```
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.reflexion = exports.treeOfThoughts = exports.mapReduce = exports.planExecute = void 0;
17
+ var planExecute_1 = require("./planExecute");
18
+ Object.defineProperty(exports, "planExecute", { enumerable: true, get: function () { return planExecute_1.planExecute; } });
19
+ var mapReduce_1 = require("./mapReduce");
20
+ Object.defineProperty(exports, "mapReduce", { enumerable: true, get: function () { return mapReduce_1.mapReduce; } });
21
+ var treeOfThoughts_1 = require("./treeOfThoughts");
22
+ Object.defineProperty(exports, "treeOfThoughts", { enumerable: true, get: function () { return treeOfThoughts_1.treeOfThoughts; } });
23
+ var reflexion_1 = require("./reflexion");
24
+ Object.defineProperty(exports, "reflexion", { enumerable: true, get: function () { return reflexion_1.reflexion; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/patterns/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAGpB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAGlB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAGvB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * mapReduce — fan-out map over N pre-bound mappers, then reduce.
4
+ *
5
+ * Each mapper is a runner with its own input already bound (prepare them with
6
+ * the slice they should process). `Parallel.mergeWithLLM` or a custom reduce
7
+ * function combines the results. Under the hood: a single `Parallel` with N
8
+ * branches and one merge strategy.
9
+ *
10
+ * Why: map-reduce is a common shape — summarize N documents, compare N
11
+ * candidates, evaluate a prompt against N rubrics. Keeping it as a named
12
+ * pattern teaches the shape; each mapper / reducer is still a regular runner.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { LLMCall, anthropic } from 'agentfootprint';
17
+ * import { mapReduce } from 'agentfootprint/patterns';
18
+ *
19
+ * const documents = [doc1, doc2, doc3];
20
+ * const provider = anthropic('claude-sonnet-4');
21
+ *
22
+ * const pipeline = mapReduce({
23
+ * provider,
24
+ * mappers: documents.map((doc, i) => ({
25
+ * id: `doc-${i}`,
26
+ * description: `Summarize doc ${i}`,
27
+ * runner: LLMCall.create({ provider })
28
+ * .system(`Summarize this document:\n\n${doc}`)
29
+ * .build(),
30
+ * })),
31
+ * reduce: { mode: 'llm', prompt: 'Combine the summaries into a single report.' },
32
+ * });
33
+ *
34
+ * const result = await pipeline.run('Produce the report');
35
+ * ```
36
+ */
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.mapReduce = void 0;
39
+ const Parallel_1 = require("../concepts/Parallel");
40
+ /**
41
+ * Build a map-reduce pipeline. Returns a `ParallelRunner` — plug it into
42
+ * `FlowChart`, `Conditional`, or `Agent.route()` like any other runner.
43
+ */
44
+ function mapReduce(options) {
45
+ if (options.mappers.length < 2) {
46
+ throw new Error('mapReduce requires at least 2 mappers. Use a single runner directly if you only have one.');
47
+ }
48
+ const builder = Parallel_1.Parallel.create({
49
+ provider: options.provider,
50
+ name: options.name ?? 'mapReduce',
51
+ });
52
+ for (const m of options.mappers) {
53
+ builder.agent(m.id, m.runner, m.description);
54
+ }
55
+ if (options.reduce.mode === 'llm') {
56
+ builder.mergeWithLLM(options.reduce.prompt);
57
+ }
58
+ else {
59
+ builder.merge(options.reduce.fn);
60
+ }
61
+ return builder.build();
62
+ }
63
+ exports.mapReduce = mapReduce;
64
+ //# sourceMappingURL=mapReduce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapReduce.js","sourceRoot":"","sources":["../../src/patterns/mapReduce.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,mDAAwF;AAwBxF;;;GAGG;AACH,SAAgB,SAAS,CAAC,OAAyB;IACjD,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,mBAAQ,CAAC,MAAM,CAAC;QAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,WAAW;KAClC,CAAC,CAAC;IACH,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAClC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAnBD,8BAmBC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * planExecute — Planner → Executor composition.
4
+ *
5
+ * Two runners chained sequentially: the planner takes the user request and
6
+ * produces a plan; the executor takes that plan (as the planner's output) and
7
+ * carries it out. Pure composition over `FlowChart` — no new primitives,
8
+ * readable as a teaching example.
9
+ *
10
+ * Why: separating planning from execution is often cheaper (small model
11
+ * plans, capable model executes) and safer (plan visible in narrative before
12
+ * any tool fires).
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { Agent, anthropic } from 'agentfootprint';
17
+ * import { planExecute } from 'agentfootprint/patterns';
18
+ *
19
+ * const planner = Agent.create({ provider: anthropic('claude-haiku-4-5') })
20
+ * .system('Produce a numbered plan. Do not execute.')
21
+ * .build();
22
+ *
23
+ * const executor = Agent.create({ provider: anthropic('claude-sonnet-4') })
24
+ * .system('Execute the given plan step by step.')
25
+ * .tools([...])
26
+ * .build();
27
+ *
28
+ * const runner = planExecute({ planner, executor });
29
+ * const result = await runner.run('Research competitors and draft a brief.');
30
+ * ```
31
+ */
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.planExecute = void 0;
34
+ const FlowChart_1 = require("../concepts/FlowChart");
35
+ /**
36
+ * Build a planner → executor pipeline. Returns a `FlowChartRunner` — plug it
37
+ * into `Parallel`, `FlowChart`, `Conditional`, or `Agent.route()` like any
38
+ * other runner.
39
+ */
40
+ function planExecute(options) {
41
+ return FlowChart_1.FlowChart.create()
42
+ .agent('plan', options.planName ?? 'Plan', options.planner)
43
+ .agent('execute', options.executeName ?? 'Execute', options.executor)
44
+ .build();
45
+ }
46
+ exports.planExecute = planExecute;
47
+ //# sourceMappingURL=planExecute.js.map