@lloyal-labs/rig 1.7.0 → 2.0.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/README.md +72 -44
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/tools/delegate.d.ts +6 -2
- package/dist/tools/delegate.d.ts.map +1 -1
- package/dist/tools/delegate.js +3 -1
- package/dist/tools/delegate.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/plan.d.ts +24 -19
- package/dist/tools/plan.d.ts.map +1 -1
- package/dist/tools/plan.js +32 -20
- package/dist/tools/plan.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lloyal-labs/rig
|
|
2
2
|
|
|
3
|
-
Retrieval-Interleaved Generation for [lloyal
|
|
3
|
+
Retrieval-Interleaved Generation for the [lloyal HDK](https://github.com/lloyal-ai/hdk).
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm i @lloyal-labs/rig @lloyal-labs/lloyal-agents @lloyal-labs/lloyal.node
|
|
@@ -10,7 +10,7 @@ npm i @lloyal-labs/rig @lloyal-labs/lloyal-agents @lloyal-labs/lloyal.node
|
|
|
10
10
|
|
|
11
11
|
RAG retrieves first, then generates. A retrieval step runs upfront — query the vector DB, get top-k passages, inject them into the prompt, call the model once. The model sees static context. Retrieval and generation are separate phases.
|
|
12
12
|
|
|
13
|
-
RIG interleaves retrieval and generation inside the decode loop
|
|
13
|
+
RIG interleaves retrieval and generation **inside the decode loop**. Agents generate reasoning, decide to search, process results, reason further, fetch a page, form hypotheses from the content, search again with refined queries. Retrieval decisions emerge from ongoing generation — each search query is informed by everything the agent has already discovered.
|
|
14
14
|
|
|
15
15
|
The difference is observable in tool call inputs. A RAG system constructs search queries from the original user question. A RIG agent constructs queries from hypotheses formed during generation:
|
|
16
16
|
|
|
@@ -30,7 +30,7 @@ The last search — `"pool drain connection lifecycle interaction"` — is the s
|
|
|
30
30
|
|
|
31
31
|
This behavior is not prompted or engineered. It emerges from the concurrency semantics of `lloyal-agents`.
|
|
32
32
|
|
|
33
|
-
The
|
|
33
|
+
The five-phase tick loop creates a clean decision boundary between each tool call and the next generation step:
|
|
34
34
|
|
|
35
35
|
1. Agent generates tokens, hits stop token, tool call extracted
|
|
36
36
|
2. Tool executes to completion — agent is suspended
|
|
@@ -42,17 +42,15 @@ Step 5 is the critical moment. The model's next-token prediction operates on a c
|
|
|
42
42
|
|
|
43
43
|
An agent that greps with a narrow pattern and gets 0 matches will broaden the pattern on its next grep — not because it's prompted to retry, but because the 0-match result is in context and the model naturally adjusts. An agent that reads a section and discovers an unexpected connection will construct a search query targeting that specific connection — the read result is in context, and the model forms a hypothesis from it.
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Depth scales with `maxTurns`. At 2 turns, agents do single-shot retrieval. At 6 turns, agents do 3-4 rounds of iterative refinement. At 20 turns, agents go deep — following citation chains, cross-referencing claims, building evidence maps. The quality difference is in the later tool call inputs.
|
|
45
|
+
Depth scales with `maxTurns`. At 2 turns, agents do single-shot retrieval. At 6 turns, agents do 3–4 rounds of iterative refinement. At 20 turns, agents go deep — following citation chains, cross-referencing claims, building evidence maps. The quality difference is in the later tool call inputs.
|
|
48
46
|
|
|
49
47
|
## Sources
|
|
50
48
|
|
|
51
49
|
`@lloyal-labs/rig` provides two `Source` implementations (extending the base class from `lloyal-agents`):
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
**`CorpusSource`** — local files with grep, semantic search, read_file, and recursive delegation. Agents investigate a knowledge base by pattern matching, reading sections in context, and spawning sub-agents for deeper investigation.
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
**`WebSource`** — web search via [Tavily](https://tavily.com), page fetching with attention-based content extraction, and recursive delegation. `BufferingFetchPage` wraps fetch results — full content goes to the agent for reasoning, while a parallel buffer stores content for post-research reranking. Content extraction uses an ephemeral fork to attend over the fetched page and extract summary + links via grammar-constrained generation, then prunes the fork — zero net KV cost per extraction.
|
|
56
54
|
|
|
57
55
|
Sources are composable. A pipeline can use one source, both, or custom implementations:
|
|
58
56
|
|
|
@@ -61,20 +59,17 @@ import {
|
|
|
61
59
|
CorpusSource,
|
|
62
60
|
WebSource,
|
|
63
61
|
TavilyProvider,
|
|
64
|
-
loadResources,
|
|
65
|
-
chunkResources,
|
|
66
62
|
} from "@lloyal-labs/rig";
|
|
63
|
+
import { loadResources, chunkResources } from "@lloyal-labs/rig/node";
|
|
67
64
|
|
|
68
65
|
const sources = [];
|
|
69
66
|
|
|
70
|
-
// Local knowledge base
|
|
71
67
|
if (corpusDir) {
|
|
72
68
|
const resources = loadResources(corpusDir);
|
|
73
69
|
const chunks = chunkResources(resources);
|
|
74
70
|
sources.push(new CorpusSource(resources, chunks));
|
|
75
71
|
}
|
|
76
72
|
|
|
77
|
-
// Web search
|
|
78
73
|
if (process.env.TAVILY_API_KEY) {
|
|
79
74
|
sources.push(new WebSource(new TavilyProvider()));
|
|
80
75
|
}
|
|
@@ -82,9 +77,20 @@ if (process.env.TAVILY_API_KEY) {
|
|
|
82
77
|
|
|
83
78
|
When multiple sources are used, they run sequentially — each source gets the full KV budget. After source N completes, its inner branches are pruned and KV is freed for source N+1.
|
|
84
79
|
|
|
80
|
+
### Cross-encoder reranker — four scoring roles
|
|
81
|
+
|
|
82
|
+
The reranker (a small cross-encoder GGUF — Qwen3-Reranker-0.6B is the recommended default) drives an `EntailmentScorer` with four distinct methods:
|
|
83
|
+
|
|
84
|
+
- **`scoreEntailmentBatch`** — texts vs. the original query. Boundary entailment for retrieved content.
|
|
85
|
+
- **`scoreRelevanceBatch`** — dual-score `min(toolQueryScore, originalQueryScore)`. Used in exploit mode when KV pressure tightens focus.
|
|
86
|
+
- **`scoreSimilarityBatch`** — texts vs. an arbitrary reference. Powers echo detection at delegation boundaries (the agent's own task as reference).
|
|
87
|
+
- **`shouldProceed`** — floor gate. Default `_entailmentFloor = 0.25`.
|
|
88
|
+
|
|
89
|
+
One model, four roles. The reranker is RIG infrastructure, not a fetch optimization.
|
|
90
|
+
|
|
85
91
|
### Bridge
|
|
86
92
|
|
|
87
|
-
Between sources, a bridge
|
|
93
|
+
Between sources, a bridge structures discoveries from the completed source as durable context for the next source's investigation:
|
|
88
94
|
|
|
89
95
|
```
|
|
90
96
|
Corpus research → Bridge → Web research → Synthesize
|
|
@@ -93,19 +99,11 @@ Corpus research → Bridge → Web research → Synthesize
|
|
|
93
99
|
The bridge extracts three tiers of discovery:
|
|
94
100
|
|
|
95
101
|
1. **What was established** — specific data points, study details, statistics, quotes. Evidence preserved verbatim.
|
|
96
|
-
2. **Where evidence is incomplete** — acknowledged limitations, absent study designs, uncertain mechanisms.
|
|
102
|
+
2. **Where evidence is incomplete** — acknowledged limitations, absent study designs, uncertain mechanisms. Well-researched claims with identified evidence gaps.
|
|
97
103
|
3. **What was not covered** — topics mentioned but not substantiated, or entirely absent.
|
|
98
104
|
|
|
99
105
|
The distinction between (2) and (3) is critical. A topic with six sections of evidence but no experimental validation is not a gap — it is a well-researched claim with an identified evidence limitation. The bridge flags the limitation, not the topic. This prevents the next source from re-investigating what the previous source already covered, and directs it toward genuine gaps.
|
|
100
106
|
|
|
101
|
-
Bridge discoveries condition the next source's questions:
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
activeQuestions = questions.map(
|
|
105
|
-
(q) => `${q}\n\nPrior research discoveries:\n${discoveries}`,
|
|
106
|
-
);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
107
|
## Pipeline
|
|
110
108
|
|
|
111
109
|
A typical RIG pipeline:
|
|
@@ -114,11 +112,11 @@ A typical RIG pipeline:
|
|
|
114
112
|
Plan → Research → [Bridge →] Synthesize → Eval
|
|
115
113
|
```
|
|
116
114
|
|
|
117
|
-
**Plan.** Grammar-constrained decomposition of the user query into sub-questions with intent classification (`research` vs `clarify`). If the query is focused enough to investigate directly, produces an empty array (passthrough).
|
|
115
|
+
**Plan.** Grammar-constrained decomposition of the user query into sub-questions with intent classification (`research` vs `clarify`). If the query is focused enough to investigate directly, produces an empty array (passthrough). `PlanTool` uses `agent()` with a JSON schema grammar — the model outputs structured `{ questions: [{ text, intent }] }` in a single generation pass.
|
|
118
116
|
|
|
119
|
-
**Research.** Each source's
|
|
117
|
+
**Research.** Each source's tools are passed to an `agentPool` that investigates sub-questions in parallel (or in chain mode, sequentially with spine extension). Agents interleave retrieval and generation — searching, reading, forming hypotheses, searching again. Within each source, all agents run concurrently on shared GPU compute. Sources run sequentially, each getting the full KV budget.
|
|
120
118
|
|
|
121
|
-
Agents that get cut by context pressure (their tool results exceeded KV headroom) are recovered via scratchpad extraction —
|
|
119
|
+
Agents that get cut by context pressure (their tool results exceeded KV headroom) are recovered via scratchpad extraction — a grammar-constrained reporter prompt attends over the agent's accumulated KV and extracts findings. The agent paid the KV cost of reasoning; the extraction recovers the value.
|
|
122
120
|
|
|
123
121
|
**Bridge.** Runs between sources when multiple sources are configured. A single agent with report-only tools structures discoveries from the completed source. The bridge output conditions the next source's sub-questions, directing investigation toward gaps rather than re-covering established ground.
|
|
124
122
|
|
|
@@ -126,6 +124,8 @@ Agents that get cut by context pressure (their tool results exceeded KV headroom
|
|
|
126
124
|
|
|
127
125
|
**Eval.** Multi-branch semantic comparison via `diverge()`. Fork N branches from a shared frontier, generate independently with the same verify prompt, check convergence. Where branches agree, the model is confident. Where they diverge, the answer needs refinement.
|
|
128
126
|
|
|
127
|
+
Full architectural walkthrough: [RIG Pipeline reference](https://docs.lloyal.ai/reference/rig/pipeline).
|
|
128
|
+
|
|
129
129
|
## Tools
|
|
130
130
|
|
|
131
131
|
### Corpus tools
|
|
@@ -135,24 +135,44 @@ Agents that get cut by context pressure (their tool results exceeded KV headroom
|
|
|
135
135
|
| `SearchTool` | Semantic search over corpus chunks via reranker scoring |
|
|
136
136
|
| `GrepTool` | Exhaustive regex pattern matching across all files |
|
|
137
137
|
| `ReadFileTool` | Read file content at specified line ranges, tracks per-agent read state |
|
|
138
|
-
| `ResearchTool` | Spawn sub-agent pool for deeper investigation of sub-questions |
|
|
139
138
|
| `ReportTool` | Terminal tool — agents call this to submit findings |
|
|
140
139
|
|
|
141
140
|
### Web tools
|
|
142
141
|
|
|
143
|
-
| Tool
|
|
144
|
-
|
|
|
145
|
-
| `WebSearchTool`
|
|
146
|
-
| `FetchPageTool`
|
|
147
|
-
| `WebResearchTool` | Spawn sub-agent pool with web tools for recursive investigation |
|
|
142
|
+
| Tool | Description |
|
|
143
|
+
| --------------- | --------------------------------------------------------------- |
|
|
144
|
+
| `WebSearchTool` | Web search via configurable provider (`TavilyProvider` included) |
|
|
145
|
+
| `FetchPageTool` | Fetch URL, extract article text via Readability |
|
|
148
146
|
|
|
149
147
|
### Pipeline tools
|
|
150
148
|
|
|
151
|
-
| Tool
|
|
152
|
-
|
|
|
153
|
-
| `PlanTool`
|
|
154
|
-
| `
|
|
155
|
-
| `
|
|
149
|
+
| Tool | Description |
|
|
150
|
+
| ---------------------- | ---------------------------------------------------------------------------- |
|
|
151
|
+
| `PlanTool` | Grammar-constrained query decomposition with intent classification |
|
|
152
|
+
| `DelegateTool` | Generic recursive-delegation tool — agent calls it to spawn a sub-agent pool |
|
|
153
|
+
| `createTools(opts)` | Build corpus toolkit from resources, chunks, and reranker |
|
|
154
|
+
| `createReranker(path)` | (`/node` subpath) Semantic reranker for chunk scoring and passage selection |
|
|
155
|
+
|
|
156
|
+
### `DelegateTool`
|
|
157
|
+
|
|
158
|
+
`DelegateTool` is the canonical recursive-delegation primitive. It takes a tool name, a sub-task extractor, a system prompt, and pool options — when the agent calls it, the tool spawns an inner `agentPool` with `parent: context.branch` (warm path) so sub-agents inherit the calling agent's full KV state at zero marginal cost.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { DelegateTool, reportTool } from "@lloyal-labs/rig";
|
|
162
|
+
|
|
163
|
+
const delegate = new DelegateTool({
|
|
164
|
+
name: "web_research",
|
|
165
|
+
extractTasks: (a) => a.questions as string[],
|
|
166
|
+
systemPrompt: RESEARCH_PROMPT,
|
|
167
|
+
poolOpts: {
|
|
168
|
+
tools: [...sourceTools, reportTool],
|
|
169
|
+
terminalTool: "report",
|
|
170
|
+
scorer,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The agent sees `web_research` (or whatever `name` you give it) as a callable tool. Calling it spawns parallel sub-agents that recurse into the corpus or web. The deeper an investigation goes, the richer the attention state at depth — and the cost of inheritance is zero.
|
|
156
176
|
|
|
157
177
|
## Custom Sources
|
|
158
178
|
|
|
@@ -162,17 +182,19 @@ Extend `Source` from `lloyal-agents` to create custom sources:
|
|
|
162
182
|
import { Source } from "@lloyal-labs/lloyal-agents";
|
|
163
183
|
import type { Tool } from "@lloyal-labs/lloyal-agents";
|
|
164
184
|
|
|
165
|
-
class DatabaseSource extends Source<
|
|
185
|
+
class DatabaseSource extends Source<DatabaseContext, Row> {
|
|
166
186
|
readonly name = "database";
|
|
167
187
|
|
|
168
|
-
get
|
|
169
|
-
return this.
|
|
188
|
+
get tools(): Tool[] {
|
|
189
|
+
return this._tools;
|
|
170
190
|
}
|
|
171
191
|
|
|
172
|
-
*bind(ctx:
|
|
173
|
-
// Set up tools
|
|
174
|
-
|
|
175
|
-
|
|
192
|
+
*bind(ctx: DatabaseContext) {
|
|
193
|
+
// Set up tools, reranker, scorer state
|
|
194
|
+
this._tools = [
|
|
195
|
+
new QueryTool(/* ... */),
|
|
196
|
+
new SchemaInspectTool(/* ... */),
|
|
197
|
+
];
|
|
176
198
|
}
|
|
177
199
|
|
|
178
200
|
getChunks(): Row[] {
|
|
@@ -181,7 +203,13 @@ class DatabaseSource extends Source<SourceContext, Row> {
|
|
|
181
203
|
}
|
|
182
204
|
```
|
|
183
205
|
|
|
184
|
-
The `bind()` lifecycle receives a
|
|
206
|
+
The `bind()` lifecycle receives a context with reranker and scorer plumbing. Your tools call `agentPool` or `useAgent` internally for recursive patterns — same primitives the built-in sources use.
|
|
207
|
+
|
|
208
|
+
See [custom sources](https://docs.lloyal.ai/reference/rig/custom-sources) for the full contract.
|
|
209
|
+
|
|
210
|
+
## Documentation
|
|
211
|
+
|
|
212
|
+
Full positioning, source contract, reranker mechanics, and pipeline patterns at [docs.lloyal.ai](https://docs.lloyal.ai).
|
|
185
213
|
|
|
186
214
|
## License
|
|
187
215
|
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @category Rig
|
|
12
12
|
*/
|
|
13
13
|
export { createTools, reportTool, ReportTool, WebSearchTool, TavilyProvider, FetchPageTool, DelegateTool, PlanTool, taskToContent, } from './tools';
|
|
14
|
-
export type { DelegateToolOpts, PlanToolOpts, PlanResult,
|
|
14
|
+
export type { DelegateToolOpts, PlanToolOpts, PlanResult, PlanIntent, ResearchTask, SearchProvider, SearchResult, Reranker, ScoredChunk, ScoredResult, } from './tools';
|
|
15
15
|
export { WebSource } from './sources/web';
|
|
16
16
|
export type { WebSourceOpts } from './sources/web';
|
|
17
17
|
export { CorpusSource } from './sources/corpus';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,WAAW,EAAE,UAAU,EAAE,UAAU,EACnC,aAAa,EAAE,cAAc,EAAE,aAAa,EAC5C,YAAY,EACZ,QAAQ,EAAE,aAAa,GACxB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,WAAW,EAAE,UAAU,EAAE,UAAU,EACnC,aAAa,EAAE,cAAc,EAAE,aAAa,EAC5C,YAAY,EACZ,QAAQ,EAAE,aAAa,GACxB,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EAAE,UAAU,EAAE,YAAY,EACpC,cAAc,EAAE,YAAY,EAC5B,QAAQ,EAAE,WAAW,EAAE,YAAY,GACpC,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/tools/delegate.d.ts
CHANGED
|
@@ -15,8 +15,11 @@ export interface DelegateToolOpts {
|
|
|
15
15
|
argsSchema?: JsonSchema;
|
|
16
16
|
/** Extract task strings from parsed tool arguments. */
|
|
17
17
|
extractTasks?: (args: Record<string, unknown>) => string[];
|
|
18
|
-
/** Pool options propagated to the inner agentPool call.
|
|
19
|
-
|
|
18
|
+
/** Pool options propagated to the inner agentPool call. Orchestrator is set
|
|
19
|
+
* by DelegateTool (one agent per extracted task, parallel). */
|
|
20
|
+
poolOpts: Omit<CreateAgentPoolOpts, 'orchestrate'>;
|
|
21
|
+
/** System prompt applied to each delegated sub-agent. */
|
|
22
|
+
systemPrompt: string;
|
|
20
23
|
/** Factory for per-invocation policy. Called fresh each time the tool fires so time budgets start from delegation, not from pool setup. */
|
|
21
24
|
createPolicy?: () => AgentPolicy;
|
|
22
25
|
}
|
|
@@ -37,6 +40,7 @@ export declare class DelegateTool extends Tool<Record<string, unknown>> {
|
|
|
37
40
|
readonly description: string;
|
|
38
41
|
readonly parameters: JsonSchema;
|
|
39
42
|
private _poolOpts;
|
|
43
|
+
private _systemPrompt;
|
|
40
44
|
private _extractTasks;
|
|
41
45
|
private _createPolicy?;
|
|
42
46
|
constructor(opts: DelegateToolOpts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../src/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACL,IAAI,
|
|
1
|
+
{"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../src/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACL,IAAI,EAML,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEZ,MAAM,4BAA4B,CAAC;AAEpC;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,uDAAuD;IACvD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;IAC3D;oEACgE;IAChE,QAAQ,EAAE,IAAI,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;IACnD,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,2IAA2I;IAC3I,YAAY,CAAC,EAAE,MAAM,WAAW,CAAC;CAClC;AAcD;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEhC,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,aAAa,CAA8C;IACnE,OAAO,CAAC,aAAa,CAAC,CAAoB;gBAE9B,IAAI,EAAE,gBAAgB;IAWjC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC;CAuInF"}
|
package/dist/tools/delegate.js
CHANGED
|
@@ -31,6 +31,7 @@ class DelegateTool extends lloyal_agents_1.Tool {
|
|
|
31
31
|
description;
|
|
32
32
|
parameters;
|
|
33
33
|
_poolOpts;
|
|
34
|
+
_systemPrompt;
|
|
34
35
|
_extractTasks;
|
|
35
36
|
_createPolicy;
|
|
36
37
|
constructor(opts) {
|
|
@@ -40,6 +41,7 @@ class DelegateTool extends lloyal_agents_1.Tool {
|
|
|
40
41
|
this.parameters = opts.argsSchema ?? DEFAULT_ARGS_SCHEMA;
|
|
41
42
|
this._extractTasks = opts.extractTasks ?? ((args) => args.tasks);
|
|
42
43
|
this._poolOpts = opts.poolOpts;
|
|
44
|
+
this._systemPrompt = opts.systemPrompt;
|
|
43
45
|
this._createPolicy = opts.createPolicy;
|
|
44
46
|
}
|
|
45
47
|
*execute(args, context) {
|
|
@@ -153,7 +155,7 @@ class DelegateTool extends lloyal_agents_1.Tool {
|
|
|
153
155
|
const pool = yield* (0, lloyal_agents_1.agentPool)({
|
|
154
156
|
...opts,
|
|
155
157
|
...(this._createPolicy ? { policy: this._createPolicy() } : {}),
|
|
156
|
-
|
|
158
|
+
orchestrate: (0, lloyal_agents_1.parallel)(tasks.map(t => ({ systemPrompt: this._systemPrompt, content: t }))),
|
|
157
159
|
parent: context?.branch,
|
|
158
160
|
pruneOnReport: opts.pruneOnReport ?? true,
|
|
159
161
|
scorer: context?.scorer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../src/tools/delegate.ts"],"names":[],"mappings":";;;AACA,yCAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../src/tools/delegate.ts"],"names":[],"mappings":";;;AACA,yCAAiC;AACjC,8DAOoC;AAgCpC,MAAM,mBAAmB,GAAe;IACtC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,WAAW,EAAE,0CAA0C;SACxD;KACF;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAa,YAAa,SAAQ,oBAA6B;IACpD,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,UAAU,CAAa;IAExB,SAAS,CAA2C;IACpD,aAAa,CAAS;IACtB,aAAa,CAA8C;IAC3D,aAAa,CAAqB;IAE1C,YAAY,IAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,sEAAsE,CAAC;QAC9G,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,mBAAmB,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,KAAiB,CAAC,CAAC;QACtG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,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C,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC;YAChE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClC,CAAC;QACF,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5JD,oCA4JC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { DelegateTool } from './delegate';
|
|
|
9
9
|
export type { DelegateToolOpts } from './delegate';
|
|
10
10
|
export type { SearchProvider, SearchResult, Reranker, ScoredChunk, ScoredResult } from './types';
|
|
11
11
|
export { PlanTool, taskToContent } from './plan';
|
|
12
|
-
export type { PlanResult,
|
|
12
|
+
export type { PlanResult, PlanIntent, PlanToolOpts, ResearchTask } from './plan';
|
|
13
13
|
/**
|
|
14
14
|
* Shared singleton {@link ReportTool} instance.
|
|
15
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,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,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;CACpB,GAAG,OAAO,CAOV"}
|
package/dist/tools/plan.d.ts
CHANGED
|
@@ -23,13 +23,14 @@ export interface PlanToolOpts {
|
|
|
23
23
|
/**
|
|
24
24
|
* A structured research task produced by the planner.
|
|
25
25
|
*
|
|
26
|
+
* Intent is a plan-level decision (see {@link PlanIntent}), not a per-task
|
|
27
|
+
* attribute — a task is always a research assignment when emitted.
|
|
28
|
+
*
|
|
26
29
|
* @category Rig
|
|
27
30
|
*/
|
|
28
31
|
export interface ResearchTask {
|
|
29
32
|
/** What to find out — a specific, actionable research assignment. */
|
|
30
33
|
description: string;
|
|
31
|
-
/** Whether the task is answerable via research or needs user clarification. */
|
|
32
|
-
intent: 'research' | 'clarify';
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Convert a ResearchTask to agent content string.
|
|
@@ -38,39 +39,43 @@ export interface ResearchTask {
|
|
|
38
39
|
*/
|
|
39
40
|
export declare function taskToContent(task: ResearchTask): string;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* Plan-level disposition for the user's query.
|
|
43
|
+
*
|
|
44
|
+
* - **clarify** — query is genuinely ambiguous; planner emits `clarifyQuestions`,
|
|
45
|
+
* harness returns to REPL for user input.
|
|
46
|
+
* - **passthrough** — query is a follow-up answerable from session.trunk's prior
|
|
47
|
+
* Q&A turns; harness skips research pipeline, streams answer from trunk, commits turn.
|
|
48
|
+
* - **research** — query needs full decomposition; planner emits `tasks`, harness
|
|
49
|
+
* runs the chain → synth → verify pipeline.
|
|
42
50
|
*
|
|
43
|
-
* @deprecated Use {@link ResearchTask} instead.
|
|
44
51
|
* @category Rig
|
|
45
52
|
*/
|
|
46
|
-
export
|
|
47
|
-
/** The sub-question text. */
|
|
48
|
-
text: string;
|
|
49
|
-
/** Whether the question can be answered via research or needs user clarification. */
|
|
50
|
-
intent: 'research' | 'clarify';
|
|
51
|
-
}
|
|
53
|
+
export type PlanIntent = 'clarify' | 'passthrough' | 'research';
|
|
52
54
|
/**
|
|
53
55
|
* Output returned by {@link PlanTool} execution.
|
|
54
56
|
*
|
|
55
57
|
* @category Rig
|
|
56
58
|
*/
|
|
57
59
|
export interface PlanResult {
|
|
58
|
-
/**
|
|
60
|
+
/** Plan-level disposition: how should the harness route this query? */
|
|
61
|
+
intent: PlanIntent;
|
|
62
|
+
/** Research tasks (non-empty when intent === 'research'; empty otherwise). */
|
|
59
63
|
tasks: ResearchTask[];
|
|
60
|
-
/**
|
|
61
|
-
|
|
64
|
+
/** Clarification questions for the user (non-empty when intent === 'clarify'; empty otherwise). */
|
|
65
|
+
clarifyQuestions: string[];
|
|
62
66
|
/** Number of tokens generated during planning. */
|
|
63
67
|
tokenCount: number;
|
|
64
68
|
/** Wall-clock time for the planning pass in milliseconds. */
|
|
65
69
|
timeMs: number;
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
|
-
* Grammar-constrained query
|
|
72
|
+
* Grammar-constrained query planner.
|
|
69
73
|
*
|
|
70
|
-
* Analyzes
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
+
* Analyzes the user's query (with prior conversation in KV via warm session fork)
|
|
75
|
+
* and produces a {@link PlanResult} that commits to one disposition: clarify /
|
|
76
|
+
* passthrough / research. Uses a JSON grammar to guarantee structured output;
|
|
77
|
+
* the planner must choose one of the three intents and populate the matching
|
|
78
|
+
* fields (tasks for research, clarifyQuestions for clarify, neither for passthrough).
|
|
74
79
|
*
|
|
75
80
|
* @category Rig
|
|
76
81
|
*/
|
|
@@ -79,7 +84,7 @@ export declare class PlanTool extends Tool<{
|
|
|
79
84
|
context?: string;
|
|
80
85
|
}> {
|
|
81
86
|
readonly name = "plan";
|
|
82
|
-
readonly description = "Analyze a
|
|
87
|
+
readonly description = "Analyze a user query and decide how to handle it: ask for clarification, pass through for direct answer from conversation history, or decompose into research tasks.";
|
|
83
88
|
readonly parameters: JsonSchema;
|
|
84
89
|
private _prompt;
|
|
85
90
|
private _session;
|
package/dist/tools/plan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/tools/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAyB,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,0GAA0G;IAC1G,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/tools/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAyB,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,0GAA0G;IAC1G,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,6DAA6D;IA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14
|
/**
|
|
15
|
-
* Grammar-constrained query
|
|
15
|
+
* Grammar-constrained query planner.
|
|
16
16
|
*
|
|
17
|
-
* Analyzes
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* Analyzes the user's query (with prior conversation in KV via warm session fork)
|
|
18
|
+
* and produces a {@link PlanResult} that commits to one disposition: clarify /
|
|
19
|
+
* passthrough / research. Uses a JSON grammar to guarantee structured output;
|
|
20
|
+
* the planner must choose one of the three intents and populate the matching
|
|
21
|
+
* fields (tasks for research, clarifyQuestions for clarify, neither for passthrough).
|
|
21
22
|
*
|
|
22
23
|
* @category Rig
|
|
23
24
|
*/
|
|
24
25
|
class PlanTool extends lloyal_agents_1.Tool {
|
|
25
26
|
name = 'plan';
|
|
26
|
-
description = 'Analyze a
|
|
27
|
+
description = 'Analyze a user query and decide how to handle it: ask for clarification, pass through for direct answer from conversation history, or decompose into research tasks.';
|
|
27
28
|
parameters = {
|
|
28
29
|
type: 'object',
|
|
29
30
|
properties: {
|
|
@@ -48,20 +49,24 @@ class PlanTool extends lloyal_agents_1.Tool {
|
|
|
48
49
|
const schema = {
|
|
49
50
|
type: 'object',
|
|
50
51
|
properties: {
|
|
52
|
+
intent: { type: 'string', enum: ['clarify', 'passthrough', 'research'] },
|
|
51
53
|
tasks: {
|
|
52
54
|
type: 'array',
|
|
53
55
|
items: {
|
|
54
56
|
type: 'object',
|
|
55
57
|
properties: {
|
|
56
58
|
description: { type: 'string' },
|
|
57
|
-
intent: { type: 'string', enum: ['research', 'clarify'] },
|
|
58
59
|
},
|
|
59
|
-
required: ['description'
|
|
60
|
+
required: ['description'],
|
|
60
61
|
},
|
|
61
62
|
maxItems: this._maxQuestions,
|
|
62
63
|
},
|
|
64
|
+
clarifyQuestions: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: { type: 'string' },
|
|
67
|
+
},
|
|
63
68
|
},
|
|
64
|
-
required: ['
|
|
69
|
+
required: ['intent'],
|
|
65
70
|
};
|
|
66
71
|
const userContent = (0, lloyal_agents_1.renderTemplate)(this._prompt.user, {
|
|
67
72
|
query: args.query,
|
|
@@ -79,20 +84,27 @@ class PlanTool extends lloyal_agents_1.Tool {
|
|
|
79
84
|
const tokenCount = planAgent.tokenCount;
|
|
80
85
|
try {
|
|
81
86
|
const parsed = JSON.parse(planAgent.rawOutput);
|
|
82
|
-
const
|
|
83
|
-
|
|
87
|
+
const intent = parsed.intent === 'clarify' || parsed.intent === 'passthrough' || parsed.intent === 'research'
|
|
88
|
+
? parsed.intent
|
|
89
|
+
: 'research';
|
|
90
|
+
const tasks = (parsed.tasks ?? [])
|
|
84
91
|
.slice(0, this._maxQuestions)
|
|
85
|
-
.filter(t => typeof t.description === 'string'
|
|
86
|
-
.map(t => ({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}));
|
|
90
|
-
// Adapter: populate deprecated questions from tasks
|
|
91
|
-
const questions = tasks.map(t => ({ text: t.description, intent: t.intent }));
|
|
92
|
-
return { tasks, questions, tokenCount, timeMs };
|
|
92
|
+
.filter(t => typeof t.description === 'string')
|
|
93
|
+
.map(t => ({ description: t.description }));
|
|
94
|
+
const clarifyQuestions = (parsed.clarifyQuestions ?? []).filter(q => typeof q === 'string');
|
|
95
|
+
return { intent, tasks, clarifyQuestions, tokenCount, timeMs };
|
|
93
96
|
}
|
|
94
97
|
catch {
|
|
95
|
-
|
|
98
|
+
// Grammar should prevent this; fall through to passthrough on malformed output
|
|
99
|
+
// so the harness routes to a direct trunk-stream answer rather than running a
|
|
100
|
+
// research pipeline with no real plan.
|
|
101
|
+
return {
|
|
102
|
+
intent: 'passthrough',
|
|
103
|
+
tasks: [],
|
|
104
|
+
clarifyQuestions: [],
|
|
105
|
+
tokenCount,
|
|
106
|
+
timeMs,
|
|
107
|
+
};
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
}
|
package/dist/tools/plan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/tools/plan.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/tools/plan.ts"],"names":[],"mappings":";;;AAuCA,sCAEC;AAxCD,8DAAyE;AAiCzE;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAkB;IAC9C,OAAO,IAAI,CAAC,WAAW,CAAC;AAC1B,CAAC;AAkCD;;;;;;;;;;GAUG;AACH,MAAa,QAAS,SAAQ,oBAAyC;IAC5D,IAAI,GAAG,MAAM,CAAC;IACd,WAAW,GAAG,sKAAsK,CAAC;IACrL,UAAU,GAAe;QAChC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,+BAA+B,EAAE;YACvE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2CAA2C,EAAE;SACtF;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB,CAAC;IAEM,OAAO,CAAmC;IAC1C,QAAQ,CAAU;IAClB,aAAa,CAAS;IACtB,YAAY,CAAS;IAE7B,YAAY,IAAkB;QAC5B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC;IACzC,CAAC;IAED,CAAC,OAAO,CAAC,IAAyC;QAChD,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAE5B,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,SAAS,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,MAAM,CAAC,MAAM,KAAK,UAAU;gBAC5F,CAAC,CAAC,MAAM,CAAC,MAAM;gBACf,CAAC,CAAC,UAAU,CAAC;YAEjB,MAAM,KAAK,GAAmB,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;iBAC/C,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;iBAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC;iBAC9C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,WAAY,EAAE,CAAC,CAAC,CAAC;YAE/C,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;YAE5F,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAuB,CAAC;QACtF,CAAC;QAAC,MAAM,CAAC;YACP,+EAA+E;YAC/E,8EAA8E;YAC9E,uCAAuC;YACvC,OAAO;gBACL,MAAM,EAAE,aAAa;gBACrB,KAAK,EAAE,EAAE;gBACT,gBAAgB,EAAE,EAAE;gBACpB,UAAU;gBACV,MAAM;aACc,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AArGD,4BAqGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lloyal-labs/rig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Retrieval-Interleaved Generation for lloyal-agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/lloyal-ai/
|
|
22
|
+
"url": "git+https://github.com/lloyal-ai/hdk.git",
|
|
23
23
|
"directory": "packages/rig"
|
|
24
24
|
},
|
|
25
|
-
"homepage": "https://github.com/lloyal-ai/
|
|
25
|
+
"homepage": "https://github.com/lloyal-ai/hdk/tree/main/packages/rig#readme",
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/lloyal-ai/
|
|
27
|
+
"url": "https://github.com/lloyal-ai/hdk/issues"
|
|
28
28
|
},
|
|
29
29
|
"keywords": [
|
|
30
30
|
"llm",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"build": "tsc -b"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@lloyal-labs/lloyal-agents": "^
|
|
44
|
-
"@lloyal-labs/sdk": "^
|
|
43
|
+
"@lloyal-labs/lloyal-agents": "^2.0.0",
|
|
44
|
+
"@lloyal-labs/sdk": "^2.0.0",
|
|
45
45
|
"@mozilla/readability": "^0.6.0",
|
|
46
46
|
"effection": "^4.0.2",
|
|
47
47
|
"linkedom": "^0.18.12"
|