agentfootprint 1.8.0 → 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.
- package/dist/esm/patterns/index.js +18 -0
- package/dist/esm/patterns/index.js.map +1 -0
- package/dist/esm/patterns/mapReduce.js +60 -0
- package/dist/esm/patterns/mapReduce.js.map +1 -0
- package/dist/esm/patterns/planExecute.js +43 -0
- package/dist/esm/patterns/planExecute.js.map +1 -0
- package/dist/esm/patterns/reflexion.js +58 -0
- package/dist/esm/patterns/reflexion.js.map +1 -0
- package/dist/esm/patterns/treeOfThoughts.js +71 -0
- package/dist/esm/patterns/treeOfThoughts.js.map +1 -0
- package/dist/esm/patterns.barrel.js +8 -0
- package/dist/esm/patterns.barrel.js.map +1 -0
- package/dist/patterns/index.js +25 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/mapReduce.js +64 -0
- package/dist/patterns/mapReduce.js.map +1 -0
- package/dist/patterns/planExecute.js +47 -0
- package/dist/patterns/planExecute.js.map +1 -0
- package/dist/patterns/reflexion.js +62 -0
- package/dist/patterns/reflexion.js.map +1 -0
- package/dist/patterns/treeOfThoughts.js +75 -0
- package/dist/patterns/treeOfThoughts.js.map +1 -0
- package/dist/patterns.barrel.js +24 -0
- package/dist/patterns.barrel.js.map +1 -0
- package/dist/types/patterns/index.d.ts +22 -0
- package/dist/types/patterns/index.d.ts.map +1 -0
- package/dist/types/patterns/mapReduce.d.ts +65 -0
- package/dist/types/patterns/mapReduce.d.ts.map +1 -0
- package/dist/types/patterns/planExecute.d.ts +49 -0
- package/dist/types/patterns/planExecute.d.ts.map +1 -0
- package/dist/types/patterns/reflexion.d.ts +65 -0
- package/dist/types/patterns/reflexion.d.ts.map +1 -0
- package/dist/types/patterns/treeOfThoughts.d.ts +65 -0
- package/dist/types/patterns/treeOfThoughts.d.ts.map +1 -0
- package/dist/types/patterns.barrel.d.ts +8 -0
- package/dist/types/patterns.barrel.d.ts.map +1 -0
- package/package.json +9 -1
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 type { PlanExecuteOptions } from './planExecute';
|
|
16
|
+
export { mapReduce } from './mapReduce';
|
|
17
|
+
export type { MapReduceOptions, MapReduceMapper, MapReduceReduceConfig } from './mapReduce';
|
|
18
|
+
export { treeOfThoughts } from './treeOfThoughts';
|
|
19
|
+
export type { TreeOfThoughtsOptions } from './treeOfThoughts';
|
|
20
|
+
export { reflexion } from './reflexion';
|
|
21
|
+
export type { ReflexionOptions } from './reflexion';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/patterns/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE5F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { type ParallelRunner, type BranchResult } from '../concepts/Parallel';
|
|
37
|
+
import type { RunnerLike, LLMProvider } from '../types';
|
|
38
|
+
export interface MapReduceMapper {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly description: string;
|
|
41
|
+
readonly runner: RunnerLike;
|
|
42
|
+
}
|
|
43
|
+
export type MapReduceReduceConfig = {
|
|
44
|
+
readonly mode: 'llm';
|
|
45
|
+
readonly prompt: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly mode: 'fn';
|
|
48
|
+
readonly fn: (results: Record<string, BranchResult>) => string;
|
|
49
|
+
};
|
|
50
|
+
export interface MapReduceOptions {
|
|
51
|
+
/** Provider used for the reduce step (only needed when `reduce.mode === 'llm'`). */
|
|
52
|
+
readonly provider: LLMProvider;
|
|
53
|
+
/** Pre-bound mappers — each runner already has its slice of work baked in. */
|
|
54
|
+
readonly mappers: readonly MapReduceMapper[];
|
|
55
|
+
/** Reduce strategy — LLM-synthesized or custom function. */
|
|
56
|
+
readonly reduce: MapReduceReduceConfig;
|
|
57
|
+
/** Name in narrative (default `'mapReduce'`). */
|
|
58
|
+
readonly name?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build a map-reduce pipeline. Returns a `ParallelRunner` — plug it into
|
|
62
|
+
* `FlowChart`, `Conditional`, or `Agent.route()` like any other runner.
|
|
63
|
+
*/
|
|
64
|
+
export declare function mapReduce(options: MapReduceOptions): ParallelRunner;
|
|
65
|
+
//# sourceMappingURL=mapReduce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapReduce.d.ts","sourceRoot":"","sources":["../../../src/patterns/mapReduce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAY,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AAED,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,MAAM,CAAA;CAAE,CAAC;AAE5F,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,iDAAiD;IACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAmBnE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { type FlowChartRunner } from '../concepts/FlowChart';
|
|
32
|
+
import type { RunnerLike } from '../types';
|
|
33
|
+
export interface PlanExecuteOptions {
|
|
34
|
+
/** Runner that produces a plan from the user's request. */
|
|
35
|
+
readonly planner: RunnerLike;
|
|
36
|
+
/** Runner that executes the plan produced by `planner`. */
|
|
37
|
+
readonly executor: RunnerLike;
|
|
38
|
+
/** Stage name for the planner step in narrative (default `'Plan'`). */
|
|
39
|
+
readonly planName?: string;
|
|
40
|
+
/** Stage name for the executor step in narrative (default `'Execute'`). */
|
|
41
|
+
readonly executeName?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build a planner → executor pipeline. Returns a `FlowChartRunner` — plug it
|
|
45
|
+
* into `Parallel`, `FlowChart`, `Conditional`, or `Agent.route()` like any
|
|
46
|
+
* other runner.
|
|
47
|
+
*/
|
|
48
|
+
export declare function planExecute(options: PlanExecuteOptions): FlowChartRunner;
|
|
49
|
+
//# sourceMappingURL=planExecute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planExecute.d.ts","sourceRoot":"","sources":["../../../src/patterns/planExecute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAKxE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { type FlowChartRunner } from '../concepts/FlowChart';
|
|
48
|
+
import type { RunnerLike } from '../types';
|
|
49
|
+
export interface ReflexionOptions {
|
|
50
|
+
/** Produces the first draft. */
|
|
51
|
+
readonly solver: RunnerLike;
|
|
52
|
+
/** Reviews the draft, outputs critique. */
|
|
53
|
+
readonly critic: RunnerLike;
|
|
54
|
+
/** Integrates the critique to produce the final answer. */
|
|
55
|
+
readonly improver: RunnerLike;
|
|
56
|
+
/** Stage names for narrative (defaults: `'Solve'`, `'Critique'`, `'Improve'`). */
|
|
57
|
+
readonly solveName?: string;
|
|
58
|
+
readonly critiqueName?: string;
|
|
59
|
+
readonly improveName?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build a Solve → Critique → Improve pipeline. Returns a `FlowChartRunner`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function reflexion(options: ReflexionOptions): FlowChartRunner;
|
|
65
|
+
//# sourceMappingURL=reflexion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflexion.d.ts","sourceRoot":"","sources":["../../../src/patterns/reflexion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAMpE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { type FlowChartRunner } from '../concepts/FlowChart';
|
|
42
|
+
import type { RunnerLike, LLMProvider } from '../types';
|
|
43
|
+
export interface TreeOfThoughtsOptions {
|
|
44
|
+
/** Provider for the Parallel merge step. */
|
|
45
|
+
readonly provider: LLMProvider;
|
|
46
|
+
/** Number of parallel thinkers (2–10). */
|
|
47
|
+
readonly branches: number;
|
|
48
|
+
/**
|
|
49
|
+
* Factory producing one thinker per index. Called once per branch at
|
|
50
|
+
* build time; each should return a built Runner.
|
|
51
|
+
*/
|
|
52
|
+
readonly thinker: (index: number) => RunnerLike;
|
|
53
|
+
/** Judge runner — receives all thinker outputs labeled by id, returns the best answer. */
|
|
54
|
+
readonly judge: RunnerLike;
|
|
55
|
+
/** Narrative name (default `'treeOfThoughts'`). */
|
|
56
|
+
readonly name?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Build a Tree-of-Thoughts pipeline. Returns a `FlowChartRunner`.
|
|
60
|
+
*
|
|
61
|
+
* Throws if `branches < 2` — use a single runner directly when you don't need
|
|
62
|
+
* multiple candidates. Throws if `branches > 10` (Parallel's cap).
|
|
63
|
+
*/
|
|
64
|
+
export declare function treeOfThoughts(options: TreeOfThoughtsOptions): FlowChartRunner;
|
|
65
|
+
//# sourceMappingURL=treeOfThoughts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"treeOfThoughts.d.ts","sourceRoot":"","sources":["../../../src/patterns/treeOfThoughts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC;IAChD,0FAA0F;IAC1F,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,eAAe,CA2B9E"}
|
|
@@ -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.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.barrel.d.ts","sourceRoot":"","sources":["../../src/patterns.barrel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentfootprint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "The explainable agent framework — build AI agents you can explain, audit, and trust. Built on footprintjs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sanjay Krishna Anbalagan",
|
|
@@ -117,6 +117,11 @@
|
|
|
117
117
|
"types": "./dist/types/stream.barrel.d.ts",
|
|
118
118
|
"import": "./dist/esm/stream.barrel.js",
|
|
119
119
|
"require": "./dist/stream.barrel.js"
|
|
120
|
+
},
|
|
121
|
+
"./patterns": {
|
|
122
|
+
"types": "./dist/types/patterns.barrel.d.ts",
|
|
123
|
+
"import": "./dist/esm/patterns.barrel.js",
|
|
124
|
+
"require": "./dist/patterns.barrel.js"
|
|
120
125
|
}
|
|
121
126
|
},
|
|
122
127
|
"typesVersions": {
|
|
@@ -141,6 +146,9 @@
|
|
|
141
146
|
],
|
|
142
147
|
"stream": [
|
|
143
148
|
"dist/types/stream.barrel.d.ts"
|
|
149
|
+
],
|
|
150
|
+
"patterns": [
|
|
151
|
+
"dist/types/patterns.barrel.d.ts"
|
|
144
152
|
]
|
|
145
153
|
}
|
|
146
154
|
},
|