@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.
@@ -1,3 +1,57 @@
1
+ /**
2
+ * The long-horizon entry point: a job, not a conversation.
3
+ *
4
+ * `createAgent` is a bounded tool loop — you talk to it. This is the
5
+ * other shape: you hand it a corpus and a question, and it authors a
6
+ * program over an environment, fans model calls out across the pieces,
7
+ * and may let any of those calls be **another agent over its own slice**
8
+ * — depth-capped, budget-shared, and traced at every level.
9
+ *
10
+ * Four things about recursion are load-bearing, and each one exists
11
+ * because the RLM paper reports the failure it prevents:
12
+ *
13
+ * - **Depth defaults to 1 and caps at 3.** The paper runs depths 0–3
14
+ * and finds most of its gain at depth 1, with depth 3 helping only on
15
+ * information-dense tasks. Depth multiplies cost on every task where
16
+ * it does not help, so the default is the depth that usually pays and
17
+ * the cap is asserted rather than documented — a program asking for
18
+ * more is clamped, and the clamp is recorded in the trajectory rather
19
+ * than applied silently.
20
+ * - **Budgets are shared by the whole tree, not per call.** Depth times
21
+ * fan-out is multiplicative: depth 3 fanning 20 ways at each level is
22
+ * 8000 leaf calls. A per-call budget cannot bound that. One account is
23
+ * threaded through every depth, charged by every model call, and when
24
+ * it runs out the tree stops with a named reason and **leaves its
25
+ * partial work in slots** — which is why Phase A came first: a
26
+ * budget-stopped run is resumable because its work is durable.
27
+ * - **A child cannot reach a sibling.** Each child gets an environment
28
+ * scoped to a prefix of its own. Isolation is what makes one failing
29
+ * branch containable instead of a corruption of the shared corpus.
30
+ * - **A child's failure is a value.** A child whose program will not
31
+ * compile returns `{ error, depth, slot }` to its parent, recorded and
32
+ * addressable. The paper reports syntax errors propagating silently
33
+ * through recursion; here the parent's map completes with a recorded
34
+ * failure in the child's own result slot, exactly as a failed leaf
35
+ * sub-call does.
36
+ *
37
+ * **What is not here, stated rather than implied:** guardrails for
38
+ * recursive LM systems are under-explored, and this package does not
39
+ * pretend otherwise. Three bounds exist and they are the only three —
40
+ * the depth cap, the shared budget and the abort signal. There is no
41
+ * general proof of a child's factual correctness or loop detection beyond
42
+ * depth. Recursive envelopes are compile/runtime checked; hosts may also
43
+ * opt into checked root reuse and per-call route limits.
44
+ */
45
+ /** The deepest a tree may go, whatever it asks for. */
46
+ export declare const MAX_DEPTH = 3;
47
+ /** The conservative default; local depth measurements have not justified raising it. */
48
+ export declare const DEFAULT_DEPTH = 1;
49
+ /**
50
+ * The dimensions a tree is bounded by. The same three the agent loop
51
+ * uses, in the same order, because a caller who has budgeted one should
52
+ * not have to learn a second vocabulary for the other.
53
+ */
54
+ export declare const BUDGET_DIMENSIONS: readonly ["turns", "tokens", "ms"];
1
55
  /**
2
56
  * One account, charged by every model call at every depth.
3
57
  *
@@ -6,9 +60,8 @@
6
60
  * branch spend the full budget independently, which is precisely the
7
61
  * runaway the cap exists to prevent.
8
62
  *
9
- * @param {{ turns?: number, tokens?: number, ms?: number,
10
- * spent?: { turns?: number, tokens?: number, ms?: number } }} [budget]
11
- * @param {() => number} [clock]
63
+ * @param [budget]
64
+ * @param [clock]
12
65
  * **Turns are reserved, tokens are settled**, and the split is what makes
13
66
  * a concurrent fan-out bounded. A budget checked before a call and
14
67
  * charged after it can be beaten by concurrency: four sub-calls launched
@@ -19,11 +72,8 @@
19
72
  * at most `maxConcurrentSubcalls - 1` calls' worth. That is stated here
20
73
  * rather than hidden, because a caller sizing a budget needs it.
21
74
  *
22
- * @returns {{ reserve: () => void, settle: (usage: any, text?: string) => void,
23
- * stop: () => string | null, spent: () => { turns: number, tokens: number, ms: number },
24
- * remaining: () => Record<string, number | null> }}
25
75
  */
26
- export function createBudgetAccount(budget?: {
76
+ export declare function createBudgetAccount(budget?: {
27
77
  turns?: number;
28
78
  tokens?: number;
29
79
  ms?: number;
@@ -51,10 +101,8 @@ export function createBudgetAccount(budget?: {
51
101
  * calls it made and the slots it wrote, at every depth. Kept as plain
52
102
  * data so a host can persist it, render it, or diff two runs.
53
103
  *
54
- * @returns {{ add: (entry: any) => any, entries: () => any[],
55
- * summary: () => { steps: number, calls: number, slots: number, depths: number[] } }}
56
104
  */
57
- export function createTrajectory(): {
105
+ export declare function createTrajectory(): {
58
106
  add: (entry: any) => any;
59
107
  entries: () => any[];
60
108
  summary: () => {
@@ -70,13 +118,15 @@ export function createTrajectory(): {
70
118
  * Returns the depth AND whether it was clamped, because a run that
71
119
  * quietly did less than it was asked to is indistinguishable from one
72
120
  * that failed to find anything — the caller has to be able to tell.
73
- * @param {number | undefined} requested
74
- * @returns {{ depth: number, clamped: boolean }}
75
121
  */
76
- export function resolveDepth(requested: number | undefined): {
122
+ export declare function resolveDepth(requested: number | undefined): {
77
123
  depth: number;
78
124
  clamped: boolean;
79
125
  };
126
+ /** The slot prefix a child at `depth` working on `index` owns. Derived,
127
+ * like every other address in this package, so nothing has to store a
128
+ * mapping from a child to its workspace. */
129
+ export declare const childScope: (depth: any, index: any) => string;
80
130
  /**
81
131
  * The long-horizon entry point: hand it a question and an environment,
82
132
  * get back an answer and the trajectory that produced it.
@@ -86,23 +136,12 @@ export function resolveDepth(requested: number | undefined): {
86
136
  * CONVERSATION, this is for a JOB — something with a corpus, a question
87
137
  * over all of it, and no user waiting to answer a follow-up.
88
138
  *
89
- * @param {{ client: any, environment: any, compileQuery?: any,
90
- * analyzeQuery?: any, annotateTypes?: any, reuse?: any,
91
- * selectModel?: any, limits?: any, onRoute?: any,
92
- * createStructuredOutput: (options: any) => { generate: Function },
93
- * createProgramAuthor: (options: any) => { author: Function },
94
- * createProgramRunner: (options: any) => { run: Function },
95
- * createEnvironment: (options: any) => any,
96
- * querySchema?: any, budget?: any, depth?: number,
97
- * maxConcurrentSubcalls?: number, maxSubcalls?: number,
98
- * subcallChars?: number, maxAnswerChars?: number, clock?: () => number }} options
99
139
  * The three factories and `createEnvironment` are injected for the
100
140
  * same reason everything heavy in this package is: it keeps this
101
- * module free of a cycle with `program.js` and lets a probe wrap any
141
+ * module free of a cycle with `program.ts` and lets a probe wrap any
102
142
  * of them to count what a run actually did.
103
- * @returns {{ run: (question: string, hooks?: { signal?: AbortSignal }) => Promise<any> }}
104
143
  */
105
- export function createLongHorizonAgent(options: {
144
+ export declare function createLongHorizonAgent(options: {
106
145
  client: any;
107
146
  environment: any;
108
147
  compileQuery?: any;
@@ -135,14 +174,3 @@ export function createLongHorizonAgent(options: {
135
174
  signal?: AbortSignal;
136
175
  }) => Promise<any>;
137
176
  };
138
- /** The deepest a tree may go, whatever it asks for. */
139
- export const MAX_DEPTH: 3;
140
- /** The conservative default; local depth measurements have not justified raising it. */
141
- export const DEFAULT_DEPTH: 1;
142
- /**
143
- * The dimensions a tree is bounded by. The same three the agent loop
144
- * uses, in the same order, because a caller who has budgeted one should
145
- * not have to learn a second vocabulary for the other.
146
- */
147
- export const BUDGET_DIMENSIONS: readonly ["turns", "tokens", "ms"];
148
- export function childScope(depth: any, index: any): string;