@lloyal-labs/rig 1.2.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/index.d.ts +10 -7
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +10 -7
  4. package/dist/index.js.map +1 -1
  5. package/dist/node.d.ts +3 -2
  6. package/dist/node.d.ts.map +1 -1
  7. package/dist/node.js +4 -6
  8. package/dist/node.js.map +1 -1
  9. package/dist/sources/corpus.d.ts +37 -23
  10. package/dist/sources/corpus.d.ts.map +1 -1
  11. package/dist/sources/corpus.js +16 -48
  12. package/dist/sources/corpus.js.map +1 -1
  13. package/dist/sources/index.d.ts +3 -1
  14. package/dist/sources/index.d.ts.map +1 -1
  15. package/dist/sources/index.js +1 -1
  16. package/dist/sources/index.js.map +1 -1
  17. package/dist/sources/types.d.ts +6 -18
  18. package/dist/sources/types.d.ts.map +1 -1
  19. package/dist/sources/web.d.ts +40 -16
  20. package/dist/sources/web.d.ts.map +1 -1
  21. package/dist/sources/web.js +19 -60
  22. package/dist/sources/web.js.map +1 -1
  23. package/dist/tools/fetch-page.d.ts +8 -1
  24. package/dist/tools/fetch-page.d.ts.map +1 -1
  25. package/dist/tools/fetch-page.js +22 -6
  26. package/dist/tools/fetch-page.js.map +1 -1
  27. package/dist/tools/grep.d.ts +6 -1
  28. package/dist/tools/grep.d.ts.map +1 -1
  29. package/dist/tools/grep.js +9 -4
  30. package/dist/tools/grep.js.map +1 -1
  31. package/dist/tools/index.d.ts +2 -8
  32. package/dist/tools/index.d.ts.map +1 -1
  33. package/dist/tools/index.js +4 -9
  34. package/dist/tools/index.js.map +1 -1
  35. package/dist/tools/plan.d.ts +3 -0
  36. package/dist/tools/plan.d.ts.map +1 -1
  37. package/dist/tools/plan.js +3 -1
  38. package/dist/tools/plan.js.map +1 -1
  39. package/dist/tools/read-file.d.ts +4 -1
  40. package/dist/tools/read-file.d.ts.map +1 -1
  41. package/dist/tools/read-file.js +4 -2
  42. package/dist/tools/read-file.js.map +1 -1
  43. package/dist/tools/report.d.ts +7 -1
  44. package/dist/tools/report.d.ts.map +1 -1
  45. package/dist/tools/report.js +18 -6
  46. package/dist/tools/report.js.map +1 -1
  47. package/package.json +5 -5
  48. package/dist/sources/corpus-research.md +0 -14
  49. package/dist/sources/extract.md +0 -5
  50. package/dist/sources/search-extract.md +0 -6
  51. package/dist/sources/web-research.md +0 -12
  52. package/dist/tools/research.d.ts +0 -57
  53. package/dist/tools/research.d.ts.map +0 -1
  54. package/dist/tools/research.js +0 -117
  55. package/dist/tools/research.js.map +0 -1
  56. package/dist/tools/web-research.d.ts +0 -60
  57. package/dist/tools/web-research.d.ts.map +0 -1
  58. package/dist/tools/web-research.js +0 -136
  59. package/dist/tools/web-research.js.map +0 -1
@@ -14,12 +14,24 @@ const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
14
14
  */
15
15
  class ReportTool extends lloyal_agents_1.Tool {
16
16
  name = 'report';
17
- description = 'Submit your final research findings. Call this when you have gathered enough information to answer the question.';
18
- parameters = {
19
- type: 'object',
20
- properties: { findings: { type: 'string', description: 'Your research findings and answer' } },
21
- required: ['findings'],
22
- };
17
+ description;
18
+ parameters;
19
+ constructor(opts) {
20
+ super();
21
+ this.description = opts?.description ??
22
+ 'Submit your final research findings with specific evidence, direct quotes, data points, and source URLs from the pages you read. State what you found AND what you checked but could not find. Do not summarize — preserve detail.';
23
+ this.parameters = {
24
+ type: 'object',
25
+ properties: {
26
+ findings: {
27
+ type: 'string',
28
+ description: opts?.findingsDescription ??
29
+ 'Detailed findings with direct quotes, data points, and source URLs. Include what was found and what was not found.',
30
+ },
31
+ },
32
+ required: ['findings'],
33
+ };
34
+ }
23
35
  *execute() { return {}; }
24
36
  }
25
37
  exports.ReportTool = ReportTool;
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/tools/report.ts"],"names":[],"mappings":";;;AACA,8DAAkD;AAGlD;;;;;;;;;GASG;AACH,MAAa,UAAW,SAAQ,oBAA0B;IAC/C,IAAI,GAAG,QAAQ,CAAC;IAChB,WAAW,GAAG,kHAAkH,CAAC;IACjI,UAAU,GAAe;QAChC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mCAAmC,EAAE,EAAE;QAC9F,QAAQ,EAAE,CAAC,UAAU,CAAC;KACvB,CAAC;IAEF,CAAC,OAAO,KAAyB,OAAO,EAAE,CAAC,CAAC,CAAC;CAC9C;AAVD,gCAUC"}
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/tools/report.ts"],"names":[],"mappings":";;;AACA,8DAAkD;AAGlD;;;;;;;;;GASG;AACH,MAAa,UAAW,SAAQ,oBAA0B;IAC/C,IAAI,GAAG,QAAQ,CAAC;IAChB,WAAW,CAAS;IACpB,UAAU,CAAa;IAEhC,YAAY,IAKX;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,IAAI,EAAE,WAAW;YAClC,oOAAoO,CAAC;QACvO,IAAI,CAAC,UAAU,GAAG;YAChB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,IAAI,EAAE,mBAAmB;wBACpC,oHAAoH;iBACvH;aACF;YACD,QAAQ,EAAE,CAAC,UAAU,CAAC;SACvB,CAAC;IACJ,CAAC;IAED,CAAC,OAAO,KAAyB,OAAO,EAAE,CAAC,CAAC,CAAC;CAC9C;AA5BD,gCA4BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lloyal-labs/rig",
3
- "version": "1.2.3",
3
+ "version": "1.4.0",
4
4
  "description": "Retrieval-Interleaved Generation for lloyal-agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,14 +37,14 @@
37
37
  "license": "Apache-2.0",
38
38
  "type": "commonjs",
39
39
  "scripts": {
40
- "build": "tsc -b && mkdir -p dist/sources && cp src/sources/*.md dist/sources/"
40
+ "build": "tsc -b"
41
41
  },
42
42
  "dependencies": {
43
- "@lloyal-labs/sdk": "*",
44
43
  "@lloyal-labs/lloyal-agents": "*",
44
+ "@lloyal-labs/sdk": "*",
45
+ "@mozilla/readability": "^0.6.0",
45
46
  "effection": "^4.0.2",
46
- "linkedom": "^0.18.12",
47
- "@mozilla/readability": "^0.6.0"
47
+ "linkedom": "^0.18.12"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@lloyal-labs/lloyal.node": "^2.0.2"
@@ -1,14 +0,0 @@
1
- You are a research assistant analyzing a knowledge base. Your tools:
2
- - **grep**: regex pattern matching — use for precise, exhaustive retrieval
3
- - **search**: semantic relevance ranking — use to discover related content
4
- - **read_file**: read specific line ranges — use to verify and get context
5
- - **research**: spawn parallel sub-agents that each run their own grep/search/read_file cycle — call with `{"questions": ["q1", "q2", ...]}`
6
- - **report**: submit your final findings with evidence
7
-
8
- Process — follow every step in order:
9
- 1. Grep with short, simple patterns first. Use single keywords or two-word phrases — never combine multiple clauses with `.*`. Run multiple greps if needed.
10
- 2. Use search to discover content that grep may miss (different phrasing, synonyms).
11
- 3. Read every matching line with read_file to verify in context. Do not rely on grep/search summaries alone.
12
- 4. Grep again with a different pattern targeting what you have NOT yet found. This is a completeness check, not confirmation of existing results.
13
- 5. Call research with sub-questions only if your findings point to specific topics you haven't fully investigated.
14
- 6. Report with line numbers and direct quotes as evidence. State what you found and what you checked.
@@ -1,5 +0,0 @@
1
- You extract key information from web page content. Produce a concise summary and list any URLs/links found in the text that are worth following. Output JSON only.
2
- ---
3
- Page: {{title}} ({{url}})
4
-
5
- {{content}}
@@ -1,6 +0,0 @@
1
- You select the most relevant search results for a research query. Pick URLs most likely to contain substantive information and summarize the key findings. Output JSON only.
2
- ---
3
- Query: {{query}}
4
-
5
- Search results:
6
- {{results}}
@@ -1,12 +0,0 @@
1
- You are a research assistant investigating questions using the web. Your tools:
2
- - **web_search**: search the web — returns results with titles, snippets, and URLs
3
- - **fetch_page**: fetch a URL and extract its article content — use to read promising search results or follow links
4
- - **web_research**: spawn parallel sub-agents that each run their own web_search/fetch_page cycle — call with `{"questions": ["q1", "q2", ...]}`
5
- - **report**: submit your final findings with evidence and source URLs
6
-
7
- Process — follow every step in order:
8
- 1. Search the web with focused queries targeting specific aspects of the question.
9
- 2. Read the most promising results with fetch_page. Follow links within pages when they lead to more authoritative content.
10
- 3. Search again with refined queries based on what you learned. Target gaps in your findings.
11
- 4. Call web_research with sub-questions if you judge there are areas that need deeper investigation.
12
- 5. Report with source URLs and direct quotes as evidence. State what you found and what you checked.
@@ -1,57 +0,0 @@
1
- import type { Operation } from 'effection';
2
- import { Tool } from '@lloyal-labs/lloyal-agents';
3
- import type { JsonSchema, Toolkit, PressureThresholds } from '@lloyal-labs/lloyal-agents';
4
- /**
5
- * Configuration for {@link ResearchTool}
6
- *
7
- * @category Rig
8
- */
9
- export interface ResearchToolOpts {
10
- /** System prompt for each spawned research agent */
11
- systemPrompt: string;
12
- /** Prompt pair used to extract findings from hard-cut agents */
13
- reporterPrompt: {
14
- system: string;
15
- user: string;
16
- };
17
- /** Maximum tool-use turns per research agent (default: 20) */
18
- maxTurns?: number;
19
- /** Enable trace logging for sub-agent pools */
20
- trace?: boolean;
21
- /** Context pressure thresholds for sub-agent pools */
22
- pressure?: PressureThresholds;
23
- }
24
- /**
25
- * Spawn parallel research agents for sub-questions (corpus source)
26
- *
27
- * Creates a {@link withSharedRoot | shared root} and runs a
28
- * {@link useAgentPool | pool} of research agents, one per question.
29
- * Each agent has access to the full toolkit (search, read_file,
30
- * grep, report). Agents that hit the turn limit without reporting
31
- * are forced through a reporter pass that extracts partial findings.
32
- *
33
- * Call {@link ResearchTool.setToolkit | setToolkit()} before first
34
- * execution to wire the toolkit into the sub-agent pool.
35
- *
36
- * @category Rig
37
- */
38
- export declare class ResearchTool extends Tool<{
39
- questions: string[];
40
- }> {
41
- readonly name = "research";
42
- readonly description = "Spawn parallel research agents to investigate sub-questions. Each question gets its own agent.";
43
- readonly parameters: JsonSchema;
44
- private _systemPrompt;
45
- private _reporterPrompt;
46
- private _maxTurns;
47
- private _trace;
48
- private _pressure?;
49
- private _toolkit;
50
- constructor(opts: ResearchToolOpts);
51
- /** Inject the toolkit that sub-agents will use. Must be called before execute. */
52
- setToolkit(toolkit: Toolkit): void;
53
- execute(args: {
54
- questions: string[];
55
- }): Operation<unknown>;
56
- }
57
- //# sourceMappingURL=research.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../src/tools/research.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAA8D,MAAM,4BAA4B,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAE1F;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,cAAc,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,IAAI,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;IAC7D,QAAQ,CAAC,IAAI,cAAc;IAC3B,QAAQ,CAAC,WAAW,oGAAoG;IACxH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAU7B;IAEF,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAC,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAwB;gBAE5B,IAAI,EAAE,gBAAgB;IASlC,kFAAkF;IAClF,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIjC,OAAO,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CAAC,OAAO,CAAC;CAoE5D"}
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResearchTool = void 0;
4
- const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
5
- /**
6
- * Spawn parallel research agents for sub-questions (corpus source)
7
- *
8
- * Creates a {@link withSharedRoot | shared root} and runs a
9
- * {@link useAgentPool | pool} of research agents, one per question.
10
- * Each agent has access to the full toolkit (search, read_file,
11
- * grep, report). Agents that hit the turn limit without reporting
12
- * are forced through a reporter pass that extracts partial findings.
13
- *
14
- * Call {@link ResearchTool.setToolkit | setToolkit()} before first
15
- * execution to wire the toolkit into the sub-agent pool.
16
- *
17
- * @category Rig
18
- */
19
- class ResearchTool extends lloyal_agents_1.Tool {
20
- name = 'research';
21
- description = 'Spawn parallel research agents to investigate sub-questions. Each question gets its own agent.';
22
- parameters = {
23
- type: 'object',
24
- properties: {
25
- questions: {
26
- type: 'array',
27
- items: { type: 'string' },
28
- description: 'Sub-questions to research in parallel',
29
- },
30
- },
31
- required: ['questions'],
32
- };
33
- _systemPrompt;
34
- _reporterPrompt;
35
- _maxTurns;
36
- _trace;
37
- _pressure;
38
- _toolkit = null;
39
- constructor(opts) {
40
- super();
41
- this._systemPrompt = opts.systemPrompt;
42
- this._reporterPrompt = opts.reporterPrompt;
43
- this._maxTurns = opts.maxTurns ?? 20;
44
- this._trace = opts.trace ?? false;
45
- this._pressure = opts.pressure;
46
- }
47
- /** Inject the toolkit that sub-agents will use. Must be called before execute. */
48
- setToolkit(toolkit) {
49
- this._toolkit = toolkit;
50
- }
51
- *execute(args) {
52
- const questions = args?.questions;
53
- if (!Array.isArray(questions) || questions.length === 0) {
54
- return { error: 'questions must be a non-empty array of strings', example: '{"questions": ["q1", "q2"]}' };
55
- }
56
- if (!this._toolkit)
57
- throw new Error('ResearchTool: setToolkit() must be called before execute');
58
- const tw = yield* lloyal_agents_1.Trace.expect();
59
- const scope = (0, lloyal_agents_1.traceScope)(tw, null, 'researchTool', { questionCount: questions.length });
60
- const toolkit = this._toolkit;
61
- const systemPrompt = this._systemPrompt;
62
- const reporterPrompt = this._reporterPrompt;
63
- const maxTurns = this._maxTurns;
64
- const trace = this._trace;
65
- const pressure = this._pressure;
66
- return yield* (0, lloyal_agents_1.withSharedRoot)({ systemPrompt, tools: toolkit.toolsJson }, function* (root) {
67
- const pool = yield* (0, lloyal_agents_1.useAgentPool)({
68
- tasks: questions.map(q => ({
69
- systemPrompt,
70
- content: q,
71
- tools: toolkit.toolsJson,
72
- parent: root,
73
- })),
74
- tools: toolkit.toolMap,
75
- terminalTool: 'report',
76
- maxTurns,
77
- trace,
78
- pressure,
79
- });
80
- // Force hard-cut agents to report — same pattern as prior harness reportPass
81
- const hardCut = pool.agents.filter(a => !a.findings && !a.branch.disposed);
82
- if (hardCut.length > 0) {
83
- for (const a of pool.agents) {
84
- if (a.findings && !a.branch.disposed)
85
- a.branch.pruneSync();
86
- }
87
- const reportTool = toolkit.toolMap.get('report');
88
- const reporters = yield* (0, lloyal_agents_1.runAgents)({
89
- tasks: hardCut.map(a => ({
90
- systemPrompt: reporterPrompt.system,
91
- content: reporterPrompt.user,
92
- tools: JSON.stringify([reportTool.schema]),
93
- parent: a.branch,
94
- })),
95
- tools: new Map([['report', reportTool]]),
96
- terminalTool: 'report',
97
- trace,
98
- pressure: { softLimit: 200, hardLimit: 64 },
99
- });
100
- hardCut.forEach((a, i) => {
101
- if (reporters.agents[i]?.findings)
102
- a.findings = reporters.agents[i].findings;
103
- });
104
- }
105
- const result = {
106
- findings: pool.agents.map(a => a.findings).filter(Boolean),
107
- agentCount: pool.agents.length,
108
- totalTokens: pool.totalTokens,
109
- totalToolCalls: pool.totalToolCalls,
110
- };
111
- scope.close();
112
- return result;
113
- });
114
- }
115
- }
116
- exports.ResearchTool = ResearchTool;
117
- //# sourceMappingURL=research.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"research.js","sourceRoot":"","sources":["../../src/tools/research.ts"],"names":[],"mappings":";;;AACA,8DAA8G;AAqB9G;;;;;;;;;;;;;GAaG;AACH,MAAa,YAAa,SAAQ,oBAA6B;IACpD,IAAI,GAAG,UAAU,CAAC;IAClB,WAAW,GAAG,gGAAgG,CAAC;IAC/G,UAAU,GAAe;QAChC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACzB,WAAW,EAAE,uCAAuC;aACrD;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,CAAC;KACxB,CAAC;IAEM,aAAa,CAAS;IACtB,eAAe,CAAmC;IAClD,SAAS,CAAS;IAClB,MAAM,CAAU;IAChB,SAAS,CAAsB;IAC/B,QAAQ,GAAmB,IAAI,CAAC;IAExC,YAAY,IAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;QAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;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KAAK;oBACL,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;iBAC5C,CAAC,CAAC;gBACH,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACvB,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ;wBAAE,CAAC,CAAC,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAC/E,CAAC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,MAAM,GAAG;gBACb,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC1D,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,cAAc,EAAE,IAAI,CAAC,cAAc;aACpC,CAAC;YACF,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,OAAO,MAAM,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAxGD,oCAwGC"}
@@ -1,60 +0,0 @@
1
- import type { Operation } from "effection";
2
- import { Tool } from "@lloyal-labs/lloyal-agents";
3
- import type { JsonSchema, Toolkit, PressureThresholds } from "@lloyal-labs/lloyal-agents";
4
- /**
5
- * Configuration for {@link WebResearchTool}.
6
- *
7
- * @category Rig
8
- */
9
- export interface WebResearchToolOpts {
10
- /** Override the tool name exposed to the model. @defaultValue "research" */
11
- name?: string;
12
- /** Override the tool description exposed to the model. */
13
- description?: string;
14
- /** System prompt given to each spawned web-research sub-agent. */
15
- systemPrompt: string;
16
- /** Prompts used for grammar-constrained scratchpad extraction on hard-cut agents. */
17
- reporterPrompt: {
18
- system: string;
19
- user: string;
20
- };
21
- /** Maximum tool-use turns per sub-agent before hard cut. @defaultValue 20 */
22
- maxTurns?: number;
23
- /** Enable trace output for sub-agent execution. @defaultValue false */
24
- trace?: boolean;
25
- /** Context pressure thresholds for the sub-agent pool. */
26
- pressure?: PressureThresholds;
27
- }
28
- /**
29
- * Spawn parallel web-research sub-agents for a set of questions.
30
- *
31
- * Similar to {@link ResearchTool} but designed for web-source pipelines.
32
- * Each question gets its own agent in a shared-root pool with access
33
- * to web_search, fetch_page, and report tools. Hard-cut agents that
34
- * exhaust their turns without reporting get a grammar-constrained
35
- * scratchpad extraction via {@link generate} to recover partial findings.
36
- *
37
- * Must call {@link setToolkit} before the tool is executed.
38
- *
39
- * @category Rig
40
- */
41
- export declare class WebResearchTool extends Tool<{
42
- questions: string[];
43
- }> {
44
- readonly name: string;
45
- readonly description: string;
46
- readonly parameters: JsonSchema;
47
- private _systemPrompt;
48
- private _reporterPrompt;
49
- private _maxTurns;
50
- private _trace;
51
- private _pressure?;
52
- private _toolkit;
53
- constructor(opts: WebResearchToolOpts);
54
- /** Inject the toolkit that sub-agents will use. Must be called before execute. */
55
- setToolkit(toolkit: Toolkit): void;
56
- execute(args: {
57
- questions: string[];
58
- }): Operation<unknown>;
59
- }
60
- //# sourceMappingURL=web-research.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-research.d.ts","sourceRoot":"","sources":["../../src/tools/web-research.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,IAAI,EAOL,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,UAAU,EACV,OAAO,EACP,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAEpC;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,YAAY,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,cAAc,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,SAAQ,IAAI,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAU7B;IAEF,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAC,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAwB;gBAE5B,IAAI,EAAE,mBAAmB;IAarC,kFAAkF;IAClF,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIjC,OAAO,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CAAC,OAAO,CAAC;CA2F5D"}
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebResearchTool = void 0;
4
- const effection_1 = require("effection");
5
- const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
6
- /**
7
- * Spawn parallel web-research sub-agents for a set of questions.
8
- *
9
- * Similar to {@link ResearchTool} but designed for web-source pipelines.
10
- * Each question gets its own agent in a shared-root pool with access
11
- * to web_search, fetch_page, and report tools. Hard-cut agents that
12
- * exhaust their turns without reporting get a grammar-constrained
13
- * scratchpad extraction via {@link generate} to recover partial findings.
14
- *
15
- * Must call {@link setToolkit} before the tool is executed.
16
- *
17
- * @category Rig
18
- */
19
- class WebResearchTool extends lloyal_agents_1.Tool {
20
- name;
21
- description;
22
- parameters = {
23
- type: "object",
24
- properties: {
25
- questions: {
26
- type: "array",
27
- items: { type: "string" },
28
- description: "Sub-questions to research in parallel",
29
- },
30
- },
31
- required: ["questions"],
32
- };
33
- _systemPrompt;
34
- _reporterPrompt;
35
- _maxTurns;
36
- _trace;
37
- _pressure;
38
- _toolkit = null;
39
- constructor(opts) {
40
- super();
41
- this.name = opts.name ?? "research";
42
- this.description =
43
- opts.description ??
44
- "Spawn parallel research agents to investigate sub-questions. Each question gets its own agent.";
45
- this._systemPrompt = opts.systemPrompt;
46
- this._reporterPrompt = opts.reporterPrompt;
47
- this._maxTurns = opts.maxTurns ?? 20;
48
- this._trace = opts.trace ?? false;
49
- this._pressure = opts.pressure;
50
- }
51
- /** Inject the toolkit that sub-agents will use. Must be called before execute. */
52
- setToolkit(toolkit) {
53
- this._toolkit = toolkit;
54
- }
55
- *execute(args) {
56
- const questions = args?.questions;
57
- if (!Array.isArray(questions) || questions.length === 0) {
58
- return {
59
- error: "questions must be a non-empty array of strings",
60
- example: '{"questions": ["q1", "q2"]}',
61
- };
62
- }
63
- if (!this._toolkit)
64
- throw new Error("WebResearchTool: setToolkit() must be called before execute");
65
- const tw = yield* lloyal_agents_1.Trace.expect();
66
- const scope = (0, lloyal_agents_1.traceScope)(tw, null, 'webResearchTool', { questionCount: questions.length });
67
- const toolkit = this._toolkit;
68
- const systemPrompt = this._systemPrompt;
69
- const reporterPrompt = this._reporterPrompt;
70
- const maxTurns = this._maxTurns;
71
- const trace = this._trace;
72
- const pressure = this._pressure;
73
- return yield* (0, lloyal_agents_1.withSharedRoot)({ systemPrompt, tools: toolkit.toolsJson }, function* (root) {
74
- const pool = yield* (0, lloyal_agents_1.useAgentPool)({
75
- tasks: questions.map((q) => ({
76
- systemPrompt,
77
- content: q,
78
- tools: toolkit.toolsJson,
79
- parent: root,
80
- })),
81
- tools: toolkit.toolMap,
82
- terminalTool: "report",
83
- maxTurns,
84
- trace,
85
- pressure,
86
- });
87
- // Scratchpad extraction for hard-cut agents — works under pressure
88
- const hardCut = pool.agents.filter((a) => !a.findings && !a.branch.disposed);
89
- if (hardCut.length > 0) {
90
- for (const a of pool.agents) {
91
- if (a.findings && !a.branch.disposed)
92
- a.branch.pruneSync();
93
- }
94
- const ctx = yield* lloyal_agents_1.Ctx.expect();
95
- const schema = {
96
- type: "object",
97
- properties: { findings: { type: "string" } },
98
- required: ["findings"],
99
- };
100
- const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(schema)));
101
- const msgs = [
102
- { role: "system", content: reporterPrompt.system },
103
- { role: "user", content: reporterPrompt.user },
104
- ];
105
- const { prompt } = ctx.formatChatSync(JSON.stringify(msgs), { enableThinking: false });
106
- for (const a of hardCut) {
107
- try {
108
- const result = yield* (0, lloyal_agents_1.generate)({
109
- prompt,
110
- grammar,
111
- parse: (o) => JSON.parse(o),
112
- parent: a.branch,
113
- });
114
- if (result.parsed?.findings)
115
- a.findings = result.parsed.findings;
116
- }
117
- catch {
118
- /* extraction failure non-fatal */
119
- }
120
- if (!a.branch.disposed)
121
- a.branch.pruneSync();
122
- }
123
- }
124
- const result = {
125
- findings: pool.agents.map((a) => a.findings).filter(Boolean),
126
- agentCount: pool.agents.length,
127
- totalTokens: pool.totalTokens,
128
- totalToolCalls: pool.totalToolCalls,
129
- };
130
- scope.close();
131
- return result;
132
- });
133
- }
134
- }
135
- exports.WebResearchTool = WebResearchTool;
136
- //# sourceMappingURL=web-research.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-research.js","sourceRoot":"","sources":["../../src/tools/web-research.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC,8DAQoC;AA6BpC;;;;;;;;;;;;GAYG;AACH,MAAa,eAAgB,SAAQ,oBAA6B;IACvD,IAAI,CAAS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