@tangleai/agents 0.21.1 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +7 -6
- package/package.json +6 -6
- package/src/agent.d.ts +31 -33
- package/src/agent.js +522 -669
- package/src/index.d.ts +12 -11
- package/src/index.js +7 -12
- package/src/program-result.d.ts +7 -29
- package/src/program-result.js +16 -40
- package/src/program-session.d.ts +7 -13
- package/src/program-session.js +130 -108
- package/src/program-shape.d.ts +17 -17
- package/src/program-shape.js +47 -40
- package/src/program.d.ts +140 -108
- package/src/program.js +637 -712
- package/src/recursive.d.ts +65 -37
- package/src/recursive.js +223 -263
- package/src/refine.d.ts +49 -15
- package/src/refine.js +396 -445
- package/src/schemas/program.d.ts +25 -25
- package/src/schemas/program.js +88 -104
- package/src/toolbox.d.ts +27 -26
- package/src/toolbox.js +90 -124
package/src/refine.d.ts
CHANGED
|
@@ -1,21 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refinement: how an agent's durable state improves without anyone
|
|
3
|
+
* rewriting it.
|
|
4
|
+
*
|
|
5
|
+
* After a run, the model is asked what it learned. The answer is not
|
|
6
|
+
* prose and it is not a new system prompt — it is an RFC 6902 JSON Patch
|
|
7
|
+
* over the ledger's supplemental state, generated through
|
|
8
|
+
* `createStructuredOutput` and put through four stages before any of it
|
|
9
|
+
* lands:
|
|
10
|
+
*
|
|
11
|
+
* 1. **shape** — the patch validates against the constrained schema
|
|
12
|
+
* (`schemas/patch.ts`): three verbs, a path pattern that matches
|
|
13
|
+
* only the supplemental subtree, a cap on the number of operations.
|
|
14
|
+
* 2. **semantics** — the patch is applied to a COPY of the state
|
|
15
|
+
* through the injected patch engine. An operation that cannot apply
|
|
16
|
+
* is a compile-style error with a pointer into the patch document,
|
|
17
|
+
* which is exactly the error class this package's field notes say
|
|
18
|
+
* small models repair well.
|
|
19
|
+
* 3. **legality** — every record the patched document would store is
|
|
20
|
+
* validated against the LEDGER's own schemas. A memory without
|
|
21
|
+
* evidence dies here, before anything is written, so the model can
|
|
22
|
+
* be told why and try again.
|
|
23
|
+
* 4. **commit** — a snapshot is taken, then the writes go through the
|
|
24
|
+
* ledger's own API. Any rejection rolls the whole thing back: there
|
|
25
|
+
* is no half-applied refinement.
|
|
26
|
+
*
|
|
27
|
+
* Why a patch rather than a rewrite: a rewrite is unreviewable and
|
|
28
|
+
* unbounded, and a model asked to restate its memories will drift them.
|
|
29
|
+
* A patch is small, auditable, and undone by the snapshot from the
|
|
30
|
+
* ledger. Two things follow from that and are worth saying out loud:
|
|
31
|
+
*
|
|
32
|
+
* - **The base system prompt is not a patch target.** Not "should not
|
|
33
|
+
* be" — it is not IN the document a patch is applied to, and no path
|
|
34
|
+
* that could reach it matches the schema's pattern. There is no
|
|
35
|
+
* operation a model can write that edits its own instructions.
|
|
36
|
+
* - **Every stored memory carries evidence**, because the ledger
|
|
37
|
+
* rejects one that does not. That is the mechanism by which
|
|
38
|
+
* "evidence-backed updates" is enforced rather than hoped for.
|
|
39
|
+
*
|
|
40
|
+
* The patch engine is INJECTED (`applyPatch`), like every other heavy
|
|
41
|
+
* thing this package touches: `@jarenjs/json` ships an RFC 6902 engine
|
|
42
|
+
* and this package must not import it. With the seam empty, refinement
|
|
43
|
+
* declines with a stated reason and the rest of the ledger is unaffected
|
|
44
|
+
* — the same degrade-to-nothing posture as the retrieval seam.
|
|
45
|
+
*/
|
|
1
46
|
/**
|
|
2
47
|
* The run, as the few hundred characters worth putting in front of the
|
|
3
48
|
* model. Tool steps are preferred over wire messages: the steps ARE the
|
|
4
49
|
* evidence a memory would cite, and a transcript's assistant turns are
|
|
5
50
|
* mostly the model reading its own prose back.
|
|
6
|
-
* @param
|
|
7
|
-
* @param {number} max
|
|
8
|
-
* @returns {string}
|
|
51
|
+
* @param trajectory - a `send` result, its `steps`, or wire messages
|
|
9
52
|
*/
|
|
10
|
-
export function describeTrajectory(trajectory: any, max?: number): string;
|
|
53
|
+
export declare function describeTrajectory(trajectory: any, max?: number): string;
|
|
11
54
|
/**
|
|
12
55
|
* Create a refiner over a ledger.
|
|
13
56
|
*
|
|
14
|
-
* @param {{ client: any, ledger: any,
|
|
15
|
-
* applyPatch?: ((document: any, patch: any[]) => any) | null,
|
|
16
|
-
* maxOps?: number, maxRepairs?: number, validator?: any,
|
|
17
|
-
* now?: () => string, trajectoryChars?: number,
|
|
18
|
-
* instructions?: string, deduplicate?: 'exact-evidence' }} options
|
|
19
57
|
* - `applyPatch` is the RFC 6902 seam: `(document, patch) => document`,
|
|
20
58
|
* normally `(doc, patch) => applyJSONPatch(doc, patch)` from
|
|
21
59
|
* `@jarenjs/json`. Absent, `refine`/`commit` decline with a stated
|
|
@@ -32,12 +70,8 @@ export function describeTrajectory(trajectory: any, max?: number): string;
|
|
|
32
70
|
* text and evidence and the same tags. Existing records are never merged
|
|
33
71
|
* or removed by this option; case, whitespace and independent citations
|
|
34
72
|
* remain distinct. The result reports every skipped proposal in `deduplicated`.
|
|
35
|
-
* @returns {{ state: () => Promise<any>,
|
|
36
|
-
* commit: (patch: any[]) => Promise<any>,
|
|
37
|
-
* refine: (trajectory: any, hooks?: { signal?: AbortSignal }) => Promise<any>,
|
|
38
|
-
* patchSchema: any }}
|
|
39
73
|
*/
|
|
40
|
-
export function createRefiner(options: {
|
|
74
|
+
export declare function createRefiner(options: {
|
|
41
75
|
client: any;
|
|
42
76
|
ledger: any;
|
|
43
77
|
applyPatch?: ((document: any, patch: any[]) => any) | null;
|
|
@@ -47,7 +81,7 @@ export function createRefiner(options: {
|
|
|
47
81
|
now?: () => string;
|
|
48
82
|
trajectoryChars?: number;
|
|
49
83
|
instructions?: string;
|
|
50
|
-
deduplicate?:
|
|
84
|
+
deduplicate?: 'exact-evidence';
|
|
51
85
|
}): {
|
|
52
86
|
state: () => Promise<any>;
|
|
53
87
|
commit: (patch: any[]) => Promise<any>;
|