agentfootprint 1.7.1 → 1.9.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 (56) hide show
  1. package/CLAUDE.md +2 -2
  2. package/dist/concepts/Conditional.js +260 -0
  3. package/dist/concepts/Conditional.js.map +1 -0
  4. package/dist/concepts/index.js +4 -1
  5. package/dist/concepts/index.js.map +1 -1
  6. package/dist/esm/concepts/Conditional.js +255 -0
  7. package/dist/esm/concepts/Conditional.js.map +1 -0
  8. package/dist/esm/concepts/index.js +1 -0
  9. package/dist/esm/concepts/index.js.map +1 -1
  10. package/dist/esm/index.js +1 -1
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/patterns/index.js +18 -0
  13. package/dist/esm/patterns/index.js.map +1 -0
  14. package/dist/esm/patterns/mapReduce.js +60 -0
  15. package/dist/esm/patterns/mapReduce.js.map +1 -0
  16. package/dist/esm/patterns/planExecute.js +43 -0
  17. package/dist/esm/patterns/planExecute.js.map +1 -0
  18. package/dist/esm/patterns/reflexion.js +58 -0
  19. package/dist/esm/patterns/reflexion.js.map +1 -0
  20. package/dist/esm/patterns/treeOfThoughts.js +71 -0
  21. package/dist/esm/patterns/treeOfThoughts.js.map +1 -0
  22. package/dist/esm/patterns.barrel.js +8 -0
  23. package/dist/esm/patterns.barrel.js.map +1 -0
  24. package/dist/index.js +4 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/patterns/index.js +25 -0
  27. package/dist/patterns/index.js.map +1 -0
  28. package/dist/patterns/mapReduce.js +64 -0
  29. package/dist/patterns/mapReduce.js.map +1 -0
  30. package/dist/patterns/planExecute.js +47 -0
  31. package/dist/patterns/planExecute.js.map +1 -0
  32. package/dist/patterns/reflexion.js +62 -0
  33. package/dist/patterns/reflexion.js.map +1 -0
  34. package/dist/patterns/treeOfThoughts.js +75 -0
  35. package/dist/patterns/treeOfThoughts.js.map +1 -0
  36. package/dist/patterns.barrel.js +24 -0
  37. package/dist/patterns.barrel.js.map +1 -0
  38. package/dist/types/concepts/Conditional.d.ts +120 -0
  39. package/dist/types/concepts/Conditional.d.ts.map +1 -0
  40. package/dist/types/concepts/index.d.ts +2 -0
  41. package/dist/types/concepts/index.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +2 -2
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/patterns/index.d.ts +22 -0
  45. package/dist/types/patterns/index.d.ts.map +1 -0
  46. package/dist/types/patterns/mapReduce.d.ts +65 -0
  47. package/dist/types/patterns/mapReduce.d.ts.map +1 -0
  48. package/dist/types/patterns/planExecute.d.ts +49 -0
  49. package/dist/types/patterns/planExecute.d.ts.map +1 -0
  50. package/dist/types/patterns/reflexion.d.ts +65 -0
  51. package/dist/types/patterns/reflexion.d.ts.map +1 -0
  52. package/dist/types/patterns/treeOfThoughts.d.ts +65 -0
  53. package/dist/types/patterns/treeOfThoughts.d.ts.map +1 -0
  54. package/dist/types/patterns.barrel.d.ts +8 -0
  55. package/dist/types/patterns.barrel.d.ts.map +1 -0
  56. package/package.json +9 -1
@@ -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"}
package/dist/index.js CHANGED
@@ -13,7 +13,8 @@
13
13
  * agentfootprint/stream → Real-time lifecycle events
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.CostRecorder = exports.TurnRecorder = 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.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;
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;
17
18
  // ── Concepts (Builders + Runners) ───────────────────────────
18
19
  var concepts_1 = require("./concepts");
19
20
  Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return concepts_1.Agent; } });
@@ -28,6 +29,8 @@ Object.defineProperty(exports, "Swarm", { enumerable: true, get: function () { r
28
29
  Object.defineProperty(exports, "SwarmRunner", { enumerable: true, get: function () { return concepts_1.SwarmRunner; } });
29
30
  Object.defineProperty(exports, "Parallel", { enumerable: true, get: function () { return concepts_1.Parallel; } });
30
31
  Object.defineProperty(exports, "ParallelRunner", { enumerable: true, get: function () { return concepts_1.ParallelRunner; } });
32
+ Object.defineProperty(exports, "Conditional", { enumerable: true, get: function () { return concepts_1.Conditional; } });
33
+ Object.defineProperty(exports, "ConditionalRunner", { enumerable: true, get: function () { return concepts_1.ConditionalRunner; } });
31
34
  // ── Tools ───────────────────────────────────────────────────
32
35
  var tools_1 = require("./tools");
33
36
  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,uCAaoB;AAZlB,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,mGAAA,OAAO,OAAA;AACP,yGAAA,aAAa,OAAA;AACb,+FAAA,GAAG,OAAA;AACH,qGAAA,SAAS,OAAA;AACT,qGAAA,SAAS,OAAA;AACT,2GAAA,eAAe,OAAA;AACf,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,oGAAA,QAAQ,OAAA;AACR,0GAAA,cAAc,OAAA;AAIhB,+DAA+D;AAC/D,iCAA6D;AAApD,mGAAA,UAAU,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE3C,iEAAiE;AACjE,uCAA6F;AAApF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxE,mCAA8D;AAArD,mGAAA,SAAS,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,iGAAA,OAAO,OAAA;AAC3C,uCAA6E;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"}
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,OAAO,OAAA;AACP,yGAAA,aAAa,OAAA;AACb,+FAAA,GAAG,OAAA;AACH,qGAAA,SAAS,OAAA;AACT,qGAAA,SAAS,OAAA;AACT,2GAAA,eAAe,OAAA;AACf,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,oGAAA,QAAQ,OAAA;AACR,0GAAA,cAAc,OAAA;AACd,uGAAA,WAAW,OAAA;AACX,6GAAA,iBAAiB,OAAA;AASnB,+DAA+D;AAC/D,iCAA6D;AAApD,mGAAA,UAAU,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE3C,iEAAiE;AACjE,uCAA6F;AAApF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxE,mCAA8D;AAArD,mGAAA,SAAS,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,iGAAA,OAAO,OAAA;AAC3C,uCAA6E;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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planExecute.js","sourceRoot":"","sources":["../../src/patterns/planExecute.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;AAEH,qDAAwE;AAcxE;;;;GAIG;AACH,SAAgB,WAAW,CAAC,OAA2B;IACrD,OAAO,qBAAS,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;AALD,kCAKC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * reflexion — Solve → Critique → Improve (single-pass).
4
+ *
5
+ * Three runners chained sequentially: a solver produces a draft, a critic
6
+ * reviews it, an improver integrates the critique. Shinn et al. 2023's
7
+ * Reflexion pattern has a quality-gated loop; this is the simplest form —
8
+ * one reflection pass. For multi-iteration Reflexion, wrap this pattern
9
+ * inside `Conditional` to rerun while a quality predicate fails.
10
+ *
11
+ * Why: a single self-review pass catches a surprising number of errors in
12
+ * reasoning / code / plans. Exposing the three runners individually lets
13
+ * users pick cheap models for critic/improver while keeping a strong solver.
14
+ *
15
+ * Under the hood:
16
+ * FlowChart[ solver, critic, improver ]
17
+ *
18
+ * Each runner receives the previous runner's output as its input message.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { Agent, anthropic } from 'agentfootprint';
23
+ * import { reflexion } from 'agentfootprint/patterns';
24
+ *
25
+ * const provider = anthropic('claude-sonnet-4');
26
+ *
27
+ * const reviewer = reflexion({
28
+ * solver: Agent.create({ provider }).system('Draft an answer.').build(),
29
+ * critic: Agent.create({ provider }).system('List weaknesses in the draft.').build(),
30
+ * improver: Agent.create({ provider })
31
+ * .system('Apply the critique to improve the draft.')
32
+ * .build(),
33
+ * });
34
+ *
35
+ * const result = await reviewer.run('Explain monads in plain English.');
36
+ * ```
37
+ *
38
+ * For multi-iteration Reflexion (loop until quality gate passes), compose
39
+ * with `Conditional`:
40
+ * ```ts
41
+ * import { Conditional } from 'agentfootprint';
42
+ * const iterative = Conditional.create()
43
+ * .when((s) => qualityOf(s) < 0.8, reviewer)
44
+ * .otherwise(doneRunner)
45
+ * .build();
46
+ * ```
47
+ */
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.reflexion = void 0;
50
+ const FlowChart_1 = require("../concepts/FlowChart");
51
+ /**
52
+ * Build a Solve → Critique → Improve pipeline. Returns a `FlowChartRunner`.
53
+ */
54
+ function reflexion(options) {
55
+ return FlowChart_1.FlowChart.create()
56
+ .agent('solve', options.solveName ?? 'Solve', options.solver)
57
+ .agent('critique', options.critiqueName ?? 'Critique', options.critic)
58
+ .agent('improve', options.improveName ?? 'Improve', options.improver)
59
+ .build();
60
+ }
61
+ exports.reflexion = reflexion;
62
+ //# sourceMappingURL=reflexion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflexion.js","sourceRoot":"","sources":["../../src/patterns/reflexion.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;;;AAEH,qDAAwE;AAgBxE;;GAEG;AACH,SAAgB,SAAS,CAAC,OAAyB;IACjD,OAAO,qBAAS,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;AAND,8BAMC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * treeOfThoughts — N parallel thinkers → one judge picks best.
4
+ *
5
+ * Fan out N parallel thinkers (each a runner, typically same prompt + higher
6
+ * temperature variance), format their outputs as context, then hand to a
7
+ * judge runner that picks or synthesizes the best answer.
8
+ *
9
+ * Why: for problems where one-shot answers are often wrong, generating
10
+ * multiple independent attempts and judging them catches errors that a
11
+ * single chain-of-thought would miss. Tree-of-Thoughts (Yao et al. 2023)
12
+ * formalized this pattern.
13
+ *
14
+ * Under the hood:
15
+ * FlowChart[ Parallel({ t0, t1, ..., tN-1, merge: labelled-concat }),
16
+ * judge ]
17
+ *
18
+ * The merge step concatenates each thinker's output under its id so the
19
+ * judge sees them as labeled candidates. The judge receives that
20
+ * concatenation as its input string.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { Agent, LLMCall, anthropic } from 'agentfootprint';
25
+ * import { treeOfThoughts } from 'agentfootprint/patterns';
26
+ *
27
+ * const provider = anthropic('claude-sonnet-4');
28
+ *
29
+ * const tot = treeOfThoughts({
30
+ * provider,
31
+ * branches: 3,
32
+ * thinker: (i) =>
33
+ * LLMCall.create({ provider }).system(`Thinker ${i + 1}: propose a different solution.`).build(),
34
+ * judge: Agent.create({ provider })
35
+ * .system('Pick the single best answer and explain why.')
36
+ * .build(),
37
+ * });
38
+ *
39
+ * const result = await tot.run('What is the fastest sort for nearly-sorted data?');
40
+ * ```
41
+ */
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.treeOfThoughts = void 0;
44
+ const FlowChart_1 = require("../concepts/FlowChart");
45
+ const Parallel_1 = require("../concepts/Parallel");
46
+ /**
47
+ * Build a Tree-of-Thoughts pipeline. Returns a `FlowChartRunner`.
48
+ *
49
+ * Throws if `branches < 2` — use a single runner directly when you don't need
50
+ * multiple candidates. Throws if `branches > 10` (Parallel's cap).
51
+ */
52
+ function treeOfThoughts(options) {
53
+ if (options.branches < 2) {
54
+ throw new Error(`treeOfThoughts requires at least 2 branches (got ${options.branches}). Use a single runner for 1-candidate flows.`);
55
+ }
56
+ const parallel = Parallel_1.Parallel.create({
57
+ provider: options.provider,
58
+ name: `${options.name ?? 'treeOfThoughts'}:thinkers`,
59
+ });
60
+ for (let i = 0; i < options.branches; i++) {
61
+ parallel.agent(`thinker-${i}`, options.thinker(i), `Thinker ${i + 1}`);
62
+ }
63
+ // Merge: label each thought so the judge can reference them by id.
64
+ // Kept as a pure function so the merge itself uses no LLM call — the judge
65
+ // is the only decision-maker and should be budgeted as such.
66
+ parallel.merge((results) => Object.entries(results)
67
+ .map(([id, r]) => `=== ${id} ===\n${r.content}`)
68
+ .join('\n\n'));
69
+ return FlowChart_1.FlowChart.create()
70
+ .agent('thinkers', 'Think', parallel.build())
71
+ .agent('judge', 'Judge', options.judge)
72
+ .build();
73
+ }
74
+ exports.treeOfThoughts = treeOfThoughts;
75
+ //# sourceMappingURL=treeOfThoughts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeOfThoughts.js","sourceRoot":"","sources":["../../src/patterns/treeOfThoughts.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAEH,qDAAwE;AACxE,mDAAmE;AAmBnE;;;;;GAKG;AACH,SAAgB,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,mBAAQ,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,qBAAS,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;AA3BD,wCA2BC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * agentfootprint/patterns — canonical composition patterns.
4
+ *
5
+ * See `src/patterns/index.ts` for the patterns themselves. This file is the
6
+ * subpath barrel used by package.json `exports['./patterns']`.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./patterns/index"), exports);
24
+ //# 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,mDAAiC"}