@geotechcli/core 0.2.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/agents/brain.d.ts +39 -0
- package/dist/agents/brain.d.ts.map +1 -0
- package/dist/agents/brain.js +339 -0
- package/dist/agents/brain.js.map +1 -0
- package/dist/agents/bridge-tools.d.ts +2 -0
- package/dist/agents/bridge-tools.d.ts.map +1 -0
- package/dist/agents/bridge-tools.js +170 -0
- package/dist/agents/bridge-tools.js.map +1 -0
- package/dist/agents/data-tools.d.ts +2 -0
- package/dist/agents/data-tools.d.ts.map +1 -0
- package/dist/agents/data-tools.js +309 -0
- package/dist/agents/data-tools.js.map +1 -0
- package/dist/agents/filesystem-tools.d.ts +2 -0
- package/dist/agents/filesystem-tools.d.ts.map +1 -0
- package/dist/agents/filesystem-tools.js +267 -0
- package/dist/agents/filesystem-tools.js.map +1 -0
- package/dist/agents/guardrails.d.ts +17 -0
- package/dist/agents/guardrails.d.ts.map +1 -0
- package/dist/agents/guardrails.js +260 -0
- package/dist/agents/guardrails.js.map +1 -0
- package/dist/agents/orchestrator.d.ts +9 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +136 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/safety.d.ts +9 -0
- package/dist/agents/safety.d.ts.map +1 -0
- package/dist/agents/safety.js +40 -0
- package/dist/agents/safety.js.map +1 -0
- package/dist/agents/sandbox.d.ts +34 -0
- package/dist/agents/sandbox.d.ts.map +1 -0
- package/dist/agents/sandbox.js +235 -0
- package/dist/agents/sandbox.js.map +1 -0
- package/dist/agents/swarm.d.ts +25 -0
- package/dist/agents/swarm.d.ts.map +1 -0
- package/dist/agents/swarm.js +434 -0
- package/dist/agents/swarm.js.map +1 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +451 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/bridge/index.d.ts +52 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +195 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/config/index.d.ts +106 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +217 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +4 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/redis.d.ts +14 -0
- package/dist/db/redis.d.ts.map +1 -0
- package/dist/db/redis.js +204 -0
- package/dist/db/redis.js.map +1 -0
- package/dist/db/supabase.d.ts +57 -0
- package/dist/db/supabase.d.ts.map +1 -0
- package/dist/db/supabase.js +156 -0
- package/dist/db/supabase.js.map +1 -0
- package/dist/db/users.d.ts +50 -0
- package/dist/db/users.d.ts.map +1 -0
- package/dist/db/users.js +132 -0
- package/dist/db/users.js.map +1 -0
- package/dist/export/index.d.ts +51 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +126 -0
- package/dist/export/index.js.map +1 -0
- package/dist/geo/bearing-capacity.d.ts +60 -0
- package/dist/geo/bearing-capacity.d.ts.map +1 -0
- package/dist/geo/bearing-capacity.js +195 -0
- package/dist/geo/bearing-capacity.js.map +1 -0
- package/dist/geo/classification.d.ts +107 -0
- package/dist/geo/classification.d.ts.map +1 -0
- package/dist/geo/classification.js +261 -0
- package/dist/geo/classification.js.map +1 -0
- package/dist/geo/index.d.ts +9 -0
- package/dist/geo/index.d.ts.map +1 -0
- package/dist/geo/index.js +9 -0
- package/dist/geo/index.js.map +1 -0
- package/dist/geo/lateral-earth-pressure.d.ts +75 -0
- package/dist/geo/lateral-earth-pressure.d.ts.map +1 -0
- package/dist/geo/lateral-earth-pressure.js +219 -0
- package/dist/geo/lateral-earth-pressure.js.map +1 -0
- package/dist/geo/liquefaction.d.ts +65 -0
- package/dist/geo/liquefaction.d.ts.map +1 -0
- package/dist/geo/liquefaction.js +163 -0
- package/dist/geo/liquefaction.js.map +1 -0
- package/dist/geo/pile-capacity.d.ts +91 -0
- package/dist/geo/pile-capacity.d.ts.map +1 -0
- package/dist/geo/pile-capacity.js +233 -0
- package/dist/geo/pile-capacity.js.map +1 -0
- package/dist/geo/settlement.d.ts +119 -0
- package/dist/geo/settlement.d.ts.map +1 -0
- package/dist/geo/settlement.js +184 -0
- package/dist/geo/settlement.js.map +1 -0
- package/dist/geo/slope-stability.d.ts +82 -0
- package/dist/geo/slope-stability.d.ts.map +1 -0
- package/dist/geo/slope-stability.js +214 -0
- package/dist/geo/slope-stability.js.map +1 -0
- package/dist/geo/tunnel/index.d.ts +2 -0
- package/dist/geo/tunnel/index.d.ts.map +1 -0
- package/dist/geo/tunnel/index.js +2 -0
- package/dist/geo/tunnel/index.js.map +1 -0
- package/dist/geo/tunnel/tbm.d.ts +135 -0
- package/dist/geo/tunnel/tbm.d.ts.map +1 -0
- package/dist/geo/tunnel/tbm.js +268 -0
- package/dist/geo/tunnel/tbm.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/ags.d.ts +42 -0
- package/dist/ingest/ags.d.ts.map +1 -0
- package/dist/ingest/ags.js +133 -0
- package/dist/ingest/ags.js.map +1 -0
- package/dist/ingest/cpt.d.ts +47 -0
- package/dist/ingest/cpt.d.ts.map +1 -0
- package/dist/ingest/cpt.js +112 -0
- package/dist/ingest/cpt.js.map +1 -0
- package/dist/ingest/index.d.ts +3 -0
- package/dist/ingest/index.d.ts.map +1 -0
- package/dist/ingest/index.js +3 -0
- package/dist/ingest/index.js.map +1 -0
- package/dist/llm/index.d.ts +5 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +4 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/middleware/metering.d.ts +55 -0
- package/dist/llm/middleware/metering.d.ts.map +1 -0
- package/dist/llm/middleware/metering.js +191 -0
- package/dist/llm/middleware/metering.js.map +1 -0
- package/dist/llm/middleware/persistent-usage.d.ts +7 -0
- package/dist/llm/middleware/persistent-usage.d.ts.map +1 -0
- package/dist/llm/middleware/persistent-usage.js +108 -0
- package/dist/llm/middleware/persistent-usage.js.map +1 -0
- package/dist/llm/middleware/retry.d.ts +7 -0
- package/dist/llm/middleware/retry.d.ts.map +1 -0
- package/dist/llm/middleware/retry.js +29 -0
- package/dist/llm/middleware/retry.js.map +1 -0
- package/dist/llm/providers/anthropic.d.ts +10 -0
- package/dist/llm/providers/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/anthropic.js +107 -0
- package/dist/llm/providers/anthropic.js.map +1 -0
- package/dist/llm/providers/hosted-beta.d.ts +10 -0
- package/dist/llm/providers/hosted-beta.d.ts.map +1 -0
- package/dist/llm/providers/hosted-beta.js +106 -0
- package/dist/llm/providers/hosted-beta.js.map +1 -0
- package/dist/llm/providers/huggingface.d.ts +37 -0
- package/dist/llm/providers/huggingface.d.ts.map +1 -0
- package/dist/llm/providers/huggingface.js +133 -0
- package/dist/llm/providers/huggingface.js.map +1 -0
- package/dist/llm/providers/openai-compatible.d.ts +27 -0
- package/dist/llm/providers/openai-compatible.d.ts.map +1 -0
- package/dist/llm/providers/openai-compatible.js +99 -0
- package/dist/llm/providers/openai-compatible.js.map +1 -0
- package/dist/llm/providers/zhipu.d.ts +10 -0
- package/dist/llm/providers/zhipu.d.ts.map +1 -0
- package/dist/llm/providers/zhipu.js +81 -0
- package/dist/llm/providers/zhipu.js.map +1 -0
- package/dist/llm/router.d.ts +35 -0
- package/dist/llm/router.d.ts.map +1 -0
- package/dist/llm/router.js +109 -0
- package/dist/llm/router.js.map +1 -0
- package/dist/llm/types.d.ts +63 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +38 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/meta/index.d.ts +12 -0
- package/dist/meta/index.d.ts.map +1 -0
- package/dist/meta/index.js +8 -0
- package/dist/meta/index.js.map +1 -0
- package/dist/meta/metadata.json +46 -0
- package/dist/report/index.d.ts +20 -0
- package/dist/report/index.d.ts.map +1 -0
- package/dist/report/index.js +58 -0
- package/dist/report/index.js.map +1 -0
- package/dist/standards/index.d.ts +23 -0
- package/dist/standards/index.d.ts.map +1 -0
- package/dist/standards/index.js +89 -0
- package/dist/standards/index.js.map +1 -0
- package/dist/storage/index.d.ts +114 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +465 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/vision/index.d.ts +80 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +298 -0
- package/dist/vision/index.js.map +1 -0
- package/dist/vision/parse.d.ts +20 -0
- package/dist/vision/parse.d.ts.map +1 -0
- package/dist/vision/parse.js +75 -0
- package/dist/vision/parse.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { generateText, generateChat } from '../llm/router.js';
|
|
2
|
+
import { toolRegistry } from './tools.js';
|
|
3
|
+
import { validateToolArgs, formatViolations } from './guardrails.js';
|
|
4
|
+
import { extractToolSafetyIssue, serializeContextForPrompt } from './safety.js';
|
|
5
|
+
// Ensure all tools are registered
|
|
6
|
+
import './filesystem-tools.js';
|
|
7
|
+
import './bridge-tools.js';
|
|
8
|
+
import './data-tools.js';
|
|
9
|
+
const INTERPRETATION_TOOLS = [
|
|
10
|
+
'read_file',
|
|
11
|
+
'list_directory',
|
|
12
|
+
'parse_csv',
|
|
13
|
+
'scan_project',
|
|
14
|
+
'parse_ags',
|
|
15
|
+
'parse_cpt',
|
|
16
|
+
'classify_uscs',
|
|
17
|
+
'classify_rmr89',
|
|
18
|
+
'classify_q_system',
|
|
19
|
+
'query_standards',
|
|
20
|
+
'project_save_dataset',
|
|
21
|
+
'project_save_parameter',
|
|
22
|
+
'project_add_assumption',
|
|
23
|
+
];
|
|
24
|
+
const SIMULATION_TOOLS = [
|
|
25
|
+
'calculate_bearing_capacity',
|
|
26
|
+
'calculate_liquefaction',
|
|
27
|
+
'predict_tbm_performance',
|
|
28
|
+
'select_tbm_type',
|
|
29
|
+
'predict_cutter_wear',
|
|
30
|
+
'calculate_tunnel_settlement',
|
|
31
|
+
'calculate_consolidation',
|
|
32
|
+
'calculate_schmertmann_settlement',
|
|
33
|
+
'calculate_pile_capacity',
|
|
34
|
+
'calculate_slope_stability',
|
|
35
|
+
'calculate_lateral_earth_pressure',
|
|
36
|
+
'plaxis_execute',
|
|
37
|
+
'plaxis_get_results',
|
|
38
|
+
'flac3d_execute',
|
|
39
|
+
'rocscience_execute',
|
|
40
|
+
'write_file',
|
|
41
|
+
'project_save_result',
|
|
42
|
+
'project_save_parameter',
|
|
43
|
+
'project_add_artifact',
|
|
44
|
+
];
|
|
45
|
+
const REVIEWER_TOOLS = [
|
|
46
|
+
'query_standards',
|
|
47
|
+
'project_load',
|
|
48
|
+
'project_add_assumption',
|
|
49
|
+
'project_add_artifact',
|
|
50
|
+
];
|
|
51
|
+
function getToolDescriptionsFor(toolNames) {
|
|
52
|
+
return toolRegistry
|
|
53
|
+
.list()
|
|
54
|
+
.filter((tool) => toolNames.includes(tool.name))
|
|
55
|
+
.map((tool) => {
|
|
56
|
+
const params = Object.entries(tool.parameters.properties ?? {})
|
|
57
|
+
.map(([key, value]) => ` - ${key}: ${value.description ?? value.type}`)
|
|
58
|
+
.join('\n');
|
|
59
|
+
return ` ${tool.name}: ${tool.description}\n${params}`;
|
|
60
|
+
})
|
|
61
|
+
.join('\n\n');
|
|
62
|
+
}
|
|
63
|
+
function interpretationPrompt() {
|
|
64
|
+
return `You are the INTERPRETATION AGENT in geotechCLI's multi-agent system.
|
|
65
|
+
|
|
66
|
+
YOUR ROLE: Clean, parse, classify, and structure raw geotechnical data.
|
|
67
|
+
|
|
68
|
+
YOU HANDLE:
|
|
69
|
+
- Reading borehole logs, AGS files, CPT data from disk
|
|
70
|
+
- Classifying soils (USCS, AASHTO) and rocks (RMR, Q-system)
|
|
71
|
+
- Parsing CSV sensor data and site investigation reports
|
|
72
|
+
- Scanning project directories to inventory available data
|
|
73
|
+
- Looking up relevant standards for classification methods
|
|
74
|
+
- Saving structured datasets, derived parameters, and assumptions into project memory when a project context is available
|
|
75
|
+
|
|
76
|
+
YOUR TOOLS:
|
|
77
|
+
${getToolDescriptionsFor(INTERPRETATION_TOOLS)}
|
|
78
|
+
|
|
79
|
+
RULES:
|
|
80
|
+
- Call tools to do real work; never estimate or guess data values.
|
|
81
|
+
- If a tool result indicates canAutoProceed=false or low-confidence parsing, stop automatic handoff from that output until you retry or clearly mark the limitation.
|
|
82
|
+
- When you derive reusable structured data or assumptions for a project, persist them with project memory tools.
|
|
83
|
+
- After processing all data, output a structured summary in this format:
|
|
84
|
+
|
|
85
|
+
\`\`\`handoff
|
|
86
|
+
{"to": "simulation", "data": {<structured data for the simulation agent>}, "summary": "<what you found>"}
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
To call a tool:
|
|
90
|
+
\`\`\`tool
|
|
91
|
+
{"tool": "<name>", "args": {<params>}}
|
|
92
|
+
\`\`\``;
|
|
93
|
+
}
|
|
94
|
+
function simulationPrompt() {
|
|
95
|
+
return `You are the SIMULATION AGENT in geotechCLI's multi-agent system.
|
|
96
|
+
|
|
97
|
+
YOUR ROLE: Execute engineering calculations and numerical simulations.
|
|
98
|
+
|
|
99
|
+
YOU RECEIVE: Structured data from the Interpretation Agent (soil profiles, classification results, parameters).
|
|
100
|
+
|
|
101
|
+
YOU HANDLE:
|
|
102
|
+
- Bearing capacity calculations (Terzaghi, Meyerhof, Hansen, Vesic)
|
|
103
|
+
- Liquefaction triggering analysis (Boulanger & Idriss 2014)
|
|
104
|
+
- TBM performance prediction, type selection, cutter wear
|
|
105
|
+
- Tunnel settlement calculation (Peck)
|
|
106
|
+
- Sending commands to PLAXIS/FLAC/Rocscience
|
|
107
|
+
- Saving results, derived parameters, and output artifacts to persistent project storage
|
|
108
|
+
|
|
109
|
+
YOUR TOOLS:
|
|
110
|
+
${getToolDescriptionsFor(SIMULATION_TOOLS)}
|
|
111
|
+
|
|
112
|
+
RULES:
|
|
113
|
+
- Use the data provided by the Interpretation Agent; do not re-read files.
|
|
114
|
+
- Run ALL relevant calculations for the task.
|
|
115
|
+
- If an upstream or tool result is blocked, incomplete, or low confidence, do not continue blindly. Retry, use a safer alternative, or pass the limitation to the reviewer.
|
|
116
|
+
- Save significant reusable outputs back into project memory when a project context is available.
|
|
117
|
+
- After completing calculations, output a handoff to the Reviewer:
|
|
118
|
+
|
|
119
|
+
\`\`\`handoff
|
|
120
|
+
{"to": "reviewer", "results": {<all calculation results>}, "summary": "<what was calculated>"}
|
|
121
|
+
\`\`\`
|
|
122
|
+
|
|
123
|
+
To call a tool:
|
|
124
|
+
\`\`\`tool
|
|
125
|
+
{"tool": "<name>", "args": {<params>}}
|
|
126
|
+
\`\`\``;
|
|
127
|
+
}
|
|
128
|
+
function reviewerPrompt() {
|
|
129
|
+
return `You are the REVIEWER AGENT in geotechCLI's multi-agent system.
|
|
130
|
+
|
|
131
|
+
YOUR ROLE: Safety check, sanity check, and standards compliance review.
|
|
132
|
+
|
|
133
|
+
YOU RECEIVE: Calculation results from the Simulation Agent.
|
|
134
|
+
|
|
135
|
+
YOU CHECK:
|
|
136
|
+
1. SAFETY FACTORS: Are FOS values above code minimums?
|
|
137
|
+
2. PHYSICAL SANITY: Are values within physically reasonable ranges?
|
|
138
|
+
3. STANDARDS COMPLIANCE: Do methods used match the applicable standard?
|
|
139
|
+
4. PARAMETER CONSISTENCY: Are input parameters consistent with each other?
|
|
140
|
+
5. COMPLETENESS: Were all necessary checks performed?
|
|
141
|
+
6. PARSE SAFETY: If any upstream result includes parseStatus/confidence/warnings or canAutoProceed=false, flag it explicitly and reject automatic conclusions that depend on that output.
|
|
142
|
+
|
|
143
|
+
YOUR TOOLS:
|
|
144
|
+
${getToolDescriptionsFor(REVIEWER_TOOLS)}
|
|
145
|
+
|
|
146
|
+
OUTPUT FORMAT - you MUST output exactly one of:
|
|
147
|
+
|
|
148
|
+
If everything passes:
|
|
149
|
+
\`\`\`review
|
|
150
|
+
{"verdict": "APPROVED", "notes": ["<any advisory notes>"], "confidence": <0-100>}
|
|
151
|
+
\`\`\`
|
|
152
|
+
|
|
153
|
+
If issues found:
|
|
154
|
+
\`\`\`review
|
|
155
|
+
{"verdict": "REJECTED", "issues": ["<specific issue 1>", "<issue 2>"], "corrections": ["<what simulation agent should fix>"], "confidence": <0-100>}
|
|
156
|
+
\`\`\`
|
|
157
|
+
|
|
158
|
+
To call a tool:
|
|
159
|
+
\`\`\`tool
|
|
160
|
+
{"tool": "<name>", "args": {<params>}}
|
|
161
|
+
\`\`\``;
|
|
162
|
+
}
|
|
163
|
+
function orchestratorPrompt() {
|
|
164
|
+
return `You are the SWARM ORCHESTRATOR for geotechCLI.
|
|
165
|
+
|
|
166
|
+
You coordinate three specialist agents:
|
|
167
|
+
1. INTERPRETATION AGENT - reads data, classifies soils/rocks, structures input
|
|
168
|
+
2. SIMULATION AGENT - runs calculations, executes numerical models
|
|
169
|
+
3. REVIEWER AGENT - safety checks, standards compliance, sanity validation
|
|
170
|
+
|
|
171
|
+
For the given task, produce the FINAL engineering report by synthesizing all agent outputs.
|
|
172
|
+
|
|
173
|
+
If the Reviewer rejected results, incorporate the corrections and note the issues that were found and resolved.
|
|
174
|
+
|
|
175
|
+
Produce a comprehensive, professional engineering report with:
|
|
176
|
+
- Data summary
|
|
177
|
+
- Calculation results with key numbers
|
|
178
|
+
- Review status, confidence, and any advisory notes
|
|
179
|
+
- Explicit limitations where blocked low-confidence outputs prevented automatic conclusions
|
|
180
|
+
- Final recommendations`;
|
|
181
|
+
}
|
|
182
|
+
async function runAgentLoop(input, config, systemPrompt, agentName, onStep, maxIter = 8) {
|
|
183
|
+
const messages = [
|
|
184
|
+
{ role: 'system', content: systemPrompt },
|
|
185
|
+
{ role: 'user', content: input },
|
|
186
|
+
];
|
|
187
|
+
const context = {};
|
|
188
|
+
let totalTokens = 0;
|
|
189
|
+
let totalLatency = 0;
|
|
190
|
+
for (let index = 0; index < maxIter; index++) {
|
|
191
|
+
let response;
|
|
192
|
+
try {
|
|
193
|
+
response = await generateChat(messages, config, {
|
|
194
|
+
temperature: 0.15,
|
|
195
|
+
maxTokens: 3000,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
200
|
+
onStep({ agent: agentName, type: 'error', content: message, timestamp: Date.now() });
|
|
201
|
+
return { output: `Error: ${message}`, context, tokens: totalTokens, latency: totalLatency };
|
|
202
|
+
}
|
|
203
|
+
totalTokens += response.usage.totalTokens;
|
|
204
|
+
totalLatency += response.latencyMs;
|
|
205
|
+
const text = response.text;
|
|
206
|
+
messages.push({ role: 'assistant', content: text });
|
|
207
|
+
const toolMatch = text.match(/```tool\s*\n?([\s\S]*?)\n?```/);
|
|
208
|
+
if (toolMatch) {
|
|
209
|
+
const thought = text.slice(0, toolMatch.index).trim();
|
|
210
|
+
if (thought) {
|
|
211
|
+
onStep({ agent: agentName, type: 'thought', content: thought, timestamp: Date.now() });
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const call = JSON.parse(toolMatch[1]);
|
|
215
|
+
onStep({
|
|
216
|
+
agent: agentName,
|
|
217
|
+
type: 'tool_call',
|
|
218
|
+
content: `${call.tool}`,
|
|
219
|
+
toolName: call.tool,
|
|
220
|
+
toolArgs: call.args,
|
|
221
|
+
timestamp: Date.now(),
|
|
222
|
+
});
|
|
223
|
+
const guard = validateToolArgs(call.tool, call.args);
|
|
224
|
+
if (!guard.passed) {
|
|
225
|
+
const message = formatViolations(guard);
|
|
226
|
+
onStep({
|
|
227
|
+
agent: agentName,
|
|
228
|
+
type: 'error',
|
|
229
|
+
content: `Guardrail blocked: ${guard.violations.filter((violation) => violation.severity === 'error').map((violation) => violation.rule).join('; ')}`,
|
|
230
|
+
timestamp: Date.now(),
|
|
231
|
+
});
|
|
232
|
+
messages.push({
|
|
233
|
+
role: 'user',
|
|
234
|
+
content: `[GUARDRAIL BLOCKED: ${call.tool}]\n${message}\nFix the parameters and retry.`,
|
|
235
|
+
});
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const result = await toolRegistry.execute(call.tool, call.args);
|
|
239
|
+
onStep({
|
|
240
|
+
agent: agentName,
|
|
241
|
+
type: 'tool_result',
|
|
242
|
+
content: result.success ? result.summary : `Error: ${result.error}`,
|
|
243
|
+
toolName: call.tool,
|
|
244
|
+
toolResult: result,
|
|
245
|
+
timestamp: Date.now(),
|
|
246
|
+
});
|
|
247
|
+
if (!result.success) {
|
|
248
|
+
messages.push({
|
|
249
|
+
role: 'user',
|
|
250
|
+
content: `[Tool FAILED: ${call.tool}]\nError: ${result.error}\n\nFix or try alternative.`,
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
context[call.tool] = result.data;
|
|
255
|
+
const safetyIssue = extractToolSafetyIssue(result.data);
|
|
256
|
+
if (safetyIssue) {
|
|
257
|
+
onStep({
|
|
258
|
+
agent: agentName,
|
|
259
|
+
type: 'error',
|
|
260
|
+
content: `${call.tool} returned blocked output: ${safetyIssue.message}`,
|
|
261
|
+
toolName: call.tool,
|
|
262
|
+
toolResult: result,
|
|
263
|
+
timestamp: Date.now(),
|
|
264
|
+
});
|
|
265
|
+
messages.push({
|
|
266
|
+
role: 'user',
|
|
267
|
+
content: `[Tool Blocked: ${call.tool}]\n${safetyIssue.message}\nWarnings: ${safetyIssue.warnings.join('; ') || 'None'}\n\nDo NOT continue downstream deterministic work from this output. Retry, choose a safer alternative, or carry the limitation forward explicitly.`,
|
|
268
|
+
});
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const compactData = JSON.stringify(result.data);
|
|
272
|
+
const dataStr = compactData.length > 3000 ? `${compactData.slice(0, 3000)}...(truncated)` : compactData;
|
|
273
|
+
messages.push({
|
|
274
|
+
role: 'user',
|
|
275
|
+
content: `[Tool Result: ${call.tool}]\n${result.summary}\nData: ${dataStr}\n\nContinue your work.`,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
messages.push({ role: 'user', content: 'Error: Invalid tool JSON. Fix and retry.' });
|
|
280
|
+
}
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const handoffMatch = text.match(/```handoff\s*\n?([\s\S]*?)\n?```/);
|
|
284
|
+
const reviewMatch = text.match(/```review\s*\n?([\s\S]*?)\n?```/);
|
|
285
|
+
if (handoffMatch || reviewMatch) {
|
|
286
|
+
const thought = text.slice(0, (handoffMatch ?? reviewMatch).index).trim();
|
|
287
|
+
if (thought) {
|
|
288
|
+
onStep({ agent: agentName, type: 'thought', content: thought, timestamp: Date.now() });
|
|
289
|
+
}
|
|
290
|
+
return { output: text, context, tokens: totalTokens, latency: totalLatency };
|
|
291
|
+
}
|
|
292
|
+
return { output: text, context, tokens: totalTokens, latency: totalLatency };
|
|
293
|
+
}
|
|
294
|
+
return { output: 'Agent reached max iterations.', context, tokens: totalTokens, latency: totalLatency };
|
|
295
|
+
}
|
|
296
|
+
const MAX_REVIEW_CYCLES = 2;
|
|
297
|
+
export async function runSwarm(task, config, onStep, sessionContext) {
|
|
298
|
+
const session = {
|
|
299
|
+
steps: [],
|
|
300
|
+
context: { ...(sessionContext ?? {}) },
|
|
301
|
+
totalTokens: 0,
|
|
302
|
+
totalLatencyMs: 0,
|
|
303
|
+
reviewPassed: false,
|
|
304
|
+
corrections: [],
|
|
305
|
+
};
|
|
306
|
+
const trackStep = (step) => {
|
|
307
|
+
session.steps.push(step);
|
|
308
|
+
onStep(step);
|
|
309
|
+
};
|
|
310
|
+
const serializedContext = serializeContextForPrompt(sessionContext, 5000);
|
|
311
|
+
const contextBlock = serializedContext ? `Project/session context:\n${serializedContext}\n\n` : '';
|
|
312
|
+
trackStep({ agent: 'orchestrator', type: 'handoff', content: 'Routing to Interpretation Agent', timestamp: Date.now() });
|
|
313
|
+
const interpResult = await runAgentLoop(`${contextBlock}Task: ${task}\n\nRead, classify, and structure all relevant data for this task.`, config, interpretationPrompt(), 'interpretation', trackStep);
|
|
314
|
+
session.totalTokens += interpResult.tokens;
|
|
315
|
+
session.totalLatencyMs += interpResult.latency;
|
|
316
|
+
session.context = { ...session.context, interpretation: interpResult.context };
|
|
317
|
+
let interpData = '';
|
|
318
|
+
const interpHandoff = interpResult.output.match(/```handoff\s*\n?([\s\S]*?)\n?```/);
|
|
319
|
+
if (interpHandoff) {
|
|
320
|
+
try {
|
|
321
|
+
const parsed = JSON.parse(interpHandoff[1]);
|
|
322
|
+
interpData = JSON.stringify(parsed.data ?? {});
|
|
323
|
+
trackStep({
|
|
324
|
+
agent: 'interpretation',
|
|
325
|
+
type: 'handoff',
|
|
326
|
+
content: `Handoff to Simulation: ${parsed.summary ?? ''}`,
|
|
327
|
+
timestamp: Date.now(),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
interpData = interpResult.output;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
interpData = interpResult.output;
|
|
336
|
+
}
|
|
337
|
+
let simOutput = '';
|
|
338
|
+
for (let cycle = 0; cycle < MAX_REVIEW_CYCLES; cycle++) {
|
|
339
|
+
trackStep({
|
|
340
|
+
agent: 'orchestrator',
|
|
341
|
+
type: 'handoff',
|
|
342
|
+
content: `Routing to Simulation Agent${cycle > 0 ? ` (retry ${cycle}, applying corrections)` : ''}`,
|
|
343
|
+
timestamp: Date.now(),
|
|
344
|
+
});
|
|
345
|
+
const correctionNote = session.corrections.length > 0
|
|
346
|
+
? `\n\nREVIEWER CORRECTIONS FROM PREVIOUS CYCLE:\n${session.corrections.join('\n')}\nApply these corrections in your calculations.`
|
|
347
|
+
: '';
|
|
348
|
+
const simResult = await runAgentLoop(`${contextBlock}Data from Interpretation Agent:\n${interpData}\n\nOriginal task: ${task}${correctionNote}\n\nRun all necessary calculations.`, config, simulationPrompt(), 'simulation', trackStep);
|
|
349
|
+
session.totalTokens += simResult.tokens;
|
|
350
|
+
session.totalLatencyMs += simResult.latency;
|
|
351
|
+
session.context = { ...session.context, simulation: simResult.context };
|
|
352
|
+
simOutput = simResult.output;
|
|
353
|
+
let simData = '';
|
|
354
|
+
const simHandoff = simResult.output.match(/```handoff\s*\n?([\s\S]*?)\n?```/);
|
|
355
|
+
if (simHandoff) {
|
|
356
|
+
try {
|
|
357
|
+
const parsed = JSON.parse(simHandoff[1]);
|
|
358
|
+
simData = JSON.stringify(parsed.results ?? {});
|
|
359
|
+
trackStep({
|
|
360
|
+
agent: 'simulation',
|
|
361
|
+
type: 'handoff',
|
|
362
|
+
content: `Handoff to Reviewer: ${parsed.summary ?? ''}`,
|
|
363
|
+
timestamp: Date.now(),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
simData = simResult.output;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
simData = simResult.output;
|
|
372
|
+
}
|
|
373
|
+
trackStep({ agent: 'orchestrator', type: 'handoff', content: 'Routing to Reviewer Agent', timestamp: Date.now() });
|
|
374
|
+
const reviewResult = await runAgentLoop(`${contextBlock}Original task: ${task}\n\nInterpretation summary:\n${interpData}\n\nSimulation results:\n${simData}\n\nReview these results for safety, sanity, standards compliance, and parse safety.`, config, reviewerPrompt(), 'reviewer', trackStep);
|
|
375
|
+
session.totalTokens += reviewResult.tokens;
|
|
376
|
+
session.totalLatencyMs += reviewResult.latency;
|
|
377
|
+
const reviewBlock = reviewResult.output.match(/```review\s*\n?([\s\S]*?)\n?```/);
|
|
378
|
+
if (!reviewBlock) {
|
|
379
|
+
session.reviewPassed = true;
|
|
380
|
+
trackStep({
|
|
381
|
+
agent: 'reviewer',
|
|
382
|
+
type: 'review',
|
|
383
|
+
content: reviewResult.output.slice(0, 200),
|
|
384
|
+
timestamp: Date.now(),
|
|
385
|
+
});
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const verdict = JSON.parse(reviewBlock[1]);
|
|
390
|
+
if (verdict.verdict === 'APPROVED') {
|
|
391
|
+
session.reviewPassed = true;
|
|
392
|
+
trackStep({
|
|
393
|
+
agent: 'reviewer',
|
|
394
|
+
type: 'review',
|
|
395
|
+
content: `APPROVED (confidence: ${verdict.confidence ?? '?'}%). Notes: ${(verdict.notes ?? []).join('; ') || 'None'}`,
|
|
396
|
+
timestamp: Date.now(),
|
|
397
|
+
});
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
session.corrections = verdict.corrections ?? [];
|
|
401
|
+
trackStep({
|
|
402
|
+
agent: 'reviewer',
|
|
403
|
+
type: 'correction',
|
|
404
|
+
content: `REJECTED. Issues: ${(verdict.issues ?? []).join('; ')}. Corrections: ${session.corrections.join('; ')}`,
|
|
405
|
+
timestamp: Date.now(),
|
|
406
|
+
});
|
|
407
|
+
if (cycle === MAX_REVIEW_CYCLES - 1) {
|
|
408
|
+
trackStep({
|
|
409
|
+
agent: 'orchestrator',
|
|
410
|
+
type: 'thought',
|
|
411
|
+
content: 'Max review cycles reached. Proceeding with noted issues.',
|
|
412
|
+
timestamp: Date.now(),
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
session.reviewPassed = true;
|
|
418
|
+
trackStep({
|
|
419
|
+
agent: 'reviewer',
|
|
420
|
+
type: 'review',
|
|
421
|
+
content: reviewResult.output.slice(0, 200),
|
|
422
|
+
timestamp: Date.now(),
|
|
423
|
+
});
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
trackStep({ agent: 'orchestrator', type: 'thought', content: 'Synthesizing final report from all agents.', timestamp: Date.now() });
|
|
428
|
+
const finalResult = await generateText(`${contextBlock}Task: ${task}\n\nInterpretation output:\n${interpData}\n\nSimulation output:\n${simOutput}\n\nReview status: ${session.reviewPassed ? 'APPROVED' : 'APPROVED WITH NOTES'}\nCorrections applied: ${session.corrections.length > 0 ? session.corrections.join('; ') : 'None'}\n\nSynthesize the final engineering report.`, config, { systemPrompt: orchestratorPrompt(), temperature: 0.2, maxTokens: 4000 });
|
|
429
|
+
session.totalTokens += finalResult.usage.totalTokens;
|
|
430
|
+
session.totalLatencyMs += finalResult.latencyMs;
|
|
431
|
+
trackStep({ agent: 'orchestrator', type: 'answer', content: finalResult.text, timestamp: Date.now() });
|
|
432
|
+
return session;
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=swarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/agents/swarm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAmB,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAEhF,kCAAkC;AAClC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,iBAAiB,CAAC;AAuBzB,MAAM,oBAAoB,GAAG;IAC3B,WAAW;IACX,gBAAgB;IAChB,WAAW;IACX,cAAc;IACd,WAAW;IACX,WAAW;IACX,eAAe;IACf,gBAAgB;IAChB,mBAAmB;IACnB,iBAAiB;IACjB,sBAAsB;IACtB,wBAAwB;IACxB,wBAAwB;CACzB,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACvB,4BAA4B;IAC5B,wBAAwB;IACxB,yBAAyB;IACzB,iBAAiB;IACjB,qBAAqB;IACrB,6BAA6B;IAC7B,yBAAyB;IACzB,kCAAkC;IAClC,yBAAyB;IACzB,2BAA2B;IAC3B,kCAAkC;IAClC,gBAAgB;IAChB,oB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AAE,EAAE,CAAC,CAAC;IAEvG,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
parameters: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface ToolResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
data: unknown;
|
|
9
|
+
summary: string;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
type ToolExecutor = (args: Record<string, unknown>) => ToolResult | Promise<ToolResult>;
|
|
13
|
+
interface RegisteredTool {
|
|
14
|
+
definition: ToolDefinition;
|
|
15
|
+
execute: ToolExecutor;
|
|
16
|
+
}
|
|
17
|
+
declare class ToolRegistry {
|
|
18
|
+
private tools;
|
|
19
|
+
register(def: ToolDefinition, execute: ToolExecutor): void;
|
|
20
|
+
get(name: string): RegisteredTool | undefined;
|
|
21
|
+
list(): ToolDefinition[];
|
|
22
|
+
execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
|
|
23
|
+
/** Format all tool definitions for LLM system prompt injection */
|
|
24
|
+
toToolDescriptions(): string;
|
|
25
|
+
/** Format as function-calling tool array for providers that support it */
|
|
26
|
+
toFunctionCallingFormat(): Array<{
|
|
27
|
+
type: 'function';
|
|
28
|
+
function: {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
parameters: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export declare const toolRegistry: ToolRegistry;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agents/tools.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;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