@anonx3247/universal-agent-harness 0.1.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/LICENSE +21 -0
- package/README.md +265 -0
- package/dist/agent-harness.d.ts +3 -0
- package/dist/agent-harness.d.ts.map +1 -0
- package/dist/agent-harness.js +326 -0
- package/dist/agent-harness.js.map +1 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +11 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +335 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +39 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/assert.d.ts +2 -0
- package/dist/lib/assert.d.ts.map +1 -0
- package/dist/lib/assert.js +4 -0
- package/dist/lib/assert.js.map +1 -0
- package/dist/lib/async.d.ts +18 -0
- package/dist/lib/async.d.ts.map +1 -0
- package/dist/lib/async.js +41 -0
- package/dist/lib/async.js.map +1 -0
- package/dist/lib/error.d.ts +47 -0
- package/dist/lib/error.d.ts.map +1 -0
- package/dist/lib/error.js +101 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/fs.d.ts +3 -0
- package/dist/lib/fs.d.ts.map +1 -0
- package/dist/lib/fs.js +17 -0
- package/dist/lib/fs.js.map +1 -0
- package/dist/lib/mcp-config.d.ts +62 -0
- package/dist/lib/mcp-config.d.ts.map +1 -0
- package/dist/lib/mcp-config.js +80 -0
- package/dist/lib/mcp-config.js.map +1 -0
- package/dist/lib/mcp.d.ts +19 -0
- package/dist/lib/mcp.d.ts.map +1 -0
- package/dist/lib/mcp.js +105 -0
- package/dist/lib/mcp.js.map +1 -0
- package/dist/lib/prompts.d.ts +5 -0
- package/dist/lib/prompts.d.ts.map +1 -0
- package/dist/lib/prompts.js +63 -0
- package/dist/lib/prompts.js.map +1 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +13 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/models/anthropic.d.ts +20 -0
- package/dist/models/anthropic.d.ts.map +1 -0
- package/dist/models/anthropic.js +312 -0
- package/dist/models/anthropic.js.map +1 -0
- package/dist/models/deepseek/index.d.ts +20 -0
- package/dist/models/deepseek/index.d.ts.map +1 -0
- package/dist/models/deepseek/index.js +210 -0
- package/dist/models/deepseek/index.js.map +1 -0
- package/dist/models/gemini.d.ts +20 -0
- package/dist/models/gemini.d.ts.map +1 -0
- package/dist/models/gemini.js +250 -0
- package/dist/models/gemini.js.map +1 -0
- package/dist/models/index.d.ts +70 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +30 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/mistral.d.ts +19 -0
- package/dist/models/mistral.d.ts.map +1 -0
- package/dist/models/mistral.js +259 -0
- package/dist/models/mistral.js.map +1 -0
- package/dist/models/moonshotai.d.ts +20 -0
- package/dist/models/moonshotai.d.ts.map +1 -0
- package/dist/models/moonshotai.js +220 -0
- package/dist/models/moonshotai.js.map +1 -0
- package/dist/models/openai.d.ts +21 -0
- package/dist/models/openai.d.ts.map +1 -0
- package/dist/models/openai.js +302 -0
- package/dist/models/openai.js.map +1 -0
- package/dist/models/provider.d.ts +19 -0
- package/dist/models/provider.d.ts.map +1 -0
- package/dist/models/provider.js +95 -0
- package/dist/models/provider.js.map +1 -0
- package/dist/resources/experiment.d.ts +18 -0
- package/dist/resources/experiment.d.ts.map +1 -0
- package/dist/resources/experiment.js +55 -0
- package/dist/resources/experiment.js.map +1 -0
- package/dist/resources/messages.d.ts +23 -0
- package/dist/resources/messages.d.ts.map +1 -0
- package/dist/resources/messages.js +81 -0
- package/dist/resources/messages.js.map +1 -0
- package/dist/runner/config.d.ts +4 -0
- package/dist/runner/config.d.ts.map +1 -0
- package/dist/runner/config.js +2 -0
- package/dist/runner/config.js.map +1 -0
- package/dist/runner/index.d.ts +41 -0
- package/dist/runner/index.d.ts.map +1 -0
- package/dist/runner/index.js +370 -0
- package/dist/runner/index.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -0
- package/package.json +57 -0
- package/profiles/example/prompt.md +54 -0
- package/profiles/example/settings.json +11 -0
- package/profiles/example/settings.json.example +38 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { withRetries, err, ok } from "@app/lib/error";
|
|
2
|
+
import { MessageResource } from "@app/resources/messages";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
import { errorToCallToolResult, createClientFromConfig } from "@app/lib/mcp";
|
|
5
|
+
import { loadProfileMCPConfig } from "@app/lib/mcp-config";
|
|
6
|
+
import { concurrentExecutor } from "@app/lib/async";
|
|
7
|
+
import { assertNever } from "@app/lib/assert";
|
|
8
|
+
import { createLLM } from "@app/models/provider";
|
|
9
|
+
import { readFileSync } from "fs";
|
|
10
|
+
import { join, dirname } from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
function loadPromptForProfile(profile) {
|
|
15
|
+
const promptPath = join(__dirname, "../../profiles", profile, "prompt.md");
|
|
16
|
+
return readFileSync(promptPath, "utf-8");
|
|
17
|
+
}
|
|
18
|
+
export class Runner {
|
|
19
|
+
experiment;
|
|
20
|
+
agentIndex;
|
|
21
|
+
mcpClients;
|
|
22
|
+
model;
|
|
23
|
+
contextPruning;
|
|
24
|
+
messages; // ordered by position asc
|
|
25
|
+
constructor(experiment, agentIndex, mcpClients, model) {
|
|
26
|
+
this.experiment = experiment;
|
|
27
|
+
this.agentIndex = agentIndex;
|
|
28
|
+
this.mcpClients = mcpClients;
|
|
29
|
+
this.model = model;
|
|
30
|
+
this.messages = [];
|
|
31
|
+
this.contextPruning = {
|
|
32
|
+
lastAgentLoopStartIdx: 0,
|
|
33
|
+
lastAgentLoopInnerStartIdx: 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static async builder(experiment, agentIndex, config) {
|
|
37
|
+
const profile = experiment.toJSON().profile;
|
|
38
|
+
const clients = [];
|
|
39
|
+
// Load and connect to configured MCP servers
|
|
40
|
+
const mcpConfigResult = loadProfileMCPConfig(profile);
|
|
41
|
+
if (mcpConfigResult.isErr()) {
|
|
42
|
+
return mcpConfigResult;
|
|
43
|
+
}
|
|
44
|
+
const mcpConfigs = mcpConfigResult.value;
|
|
45
|
+
if (mcpConfigs.length > 0) {
|
|
46
|
+
console.log(`\x1b[36mLoading ${mcpConfigs.length} MCP server(s) for agent ${agentIndex}...\x1b[0m`);
|
|
47
|
+
for (const mcpConfig of mcpConfigs) {
|
|
48
|
+
const clientResult = await createClientFromConfig(mcpConfig);
|
|
49
|
+
if (clientResult.isErr()) {
|
|
50
|
+
console.error(`\x1b[33mWarning: Failed to connect to MCP server '${mcpConfig.name}': ${clientResult.error.message}\x1b[0m`);
|
|
51
|
+
// Continue with other servers even if one fails
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
clients.push(clientResult.value);
|
|
55
|
+
console.log(`\x1b[32m✓ Connected to MCP server '${mcpConfig.name}'\x1b[0m`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const model = createLLM(experiment.toJSON().model, {
|
|
59
|
+
thinking: config.thinking,
|
|
60
|
+
});
|
|
61
|
+
const runner = await Runner.initialize(experiment, agentIndex, clients, model);
|
|
62
|
+
if (runner.isErr()) {
|
|
63
|
+
return runner;
|
|
64
|
+
}
|
|
65
|
+
return ok(runner.value);
|
|
66
|
+
}
|
|
67
|
+
static async initialize(experiment, agentIndex, mcpClients, model) {
|
|
68
|
+
const runner = new Runner(experiment, agentIndex, mcpClients, model);
|
|
69
|
+
const messages = await MessageResource.listMessagesByAgent(runner.experiment, runner.agentIndex);
|
|
70
|
+
runner.messages = messages;
|
|
71
|
+
return ok(runner);
|
|
72
|
+
}
|
|
73
|
+
async tools() {
|
|
74
|
+
const tools = [];
|
|
75
|
+
for (const client of this.mcpClients) {
|
|
76
|
+
try {
|
|
77
|
+
const ct = await client.listTools();
|
|
78
|
+
for (const tool of ct.tools) {
|
|
79
|
+
tools.push({
|
|
80
|
+
name: `${client.getServerVersion()?.name}-${tool.name}`,
|
|
81
|
+
description: tool.description,
|
|
82
|
+
inputSchema: tool.inputSchema,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return err("tool_error", `Error listing tools from client ${client.getServerVersion()?.name}`, error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return ok(tools);
|
|
91
|
+
}
|
|
92
|
+
async executeTool(t) {
|
|
93
|
+
for (const client of this.mcpClients) {
|
|
94
|
+
try {
|
|
95
|
+
const ct = await client.listTools();
|
|
96
|
+
for (const tool of ct.tools) {
|
|
97
|
+
if (`${client.getServerVersion()?.name}-${tool.name}` === t.name) {
|
|
98
|
+
const result = await client.callTool({
|
|
99
|
+
name: tool.name,
|
|
100
|
+
arguments: t.input,
|
|
101
|
+
});
|
|
102
|
+
const toolResult = {
|
|
103
|
+
type: "tool_result",
|
|
104
|
+
toolUseId: t.id,
|
|
105
|
+
toolUseName: t.name,
|
|
106
|
+
content: result.content,
|
|
107
|
+
isError: (result.isError ?? false),
|
|
108
|
+
};
|
|
109
|
+
return toolResult;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
type: "tool_result",
|
|
116
|
+
toolUseId: t.id,
|
|
117
|
+
toolUseName: t.name,
|
|
118
|
+
content: errorToCallToolResult(err("tool_execution_error", `Error executing tool ${t.name}`, error)).content,
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
type: "tool_result",
|
|
125
|
+
toolUseId: t.id,
|
|
126
|
+
toolUseName: t.name,
|
|
127
|
+
content: errorToCallToolResult(err("tool_execution_error", `No MCP client found to execute tool ${t.name}`)).content,
|
|
128
|
+
isError: true,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
isNewUserMessageNeeded() {
|
|
132
|
+
if (this.messages.length === 0) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
// If the role is agent it means we had no tool use in the last tick and we need a user message.
|
|
136
|
+
const last = this.messages[this.messages.length - 1];
|
|
137
|
+
if (last.toJSON().role === "agent") {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
async newUserMessage() {
|
|
143
|
+
const position = this.messages.length > 0
|
|
144
|
+
? this.messages[this.messages.length - 1].position() + 1
|
|
145
|
+
: 0;
|
|
146
|
+
const m = {
|
|
147
|
+
role: "user",
|
|
148
|
+
content: [
|
|
149
|
+
{
|
|
150
|
+
type: "text",
|
|
151
|
+
text: `\
|
|
152
|
+
<system>
|
|
153
|
+
This is an automated system message and there is no user available to respond. Proceed autonomously, making sure to use tools as only tools have visible effects on the system. Never stay idle and always pro-actively work on solving the problem.
|
|
154
|
+
</system>
|
|
155
|
+
`,
|
|
156
|
+
provider: null,
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
const message = await MessageResource.create(this.experiment, this.agentIndex, m, position, 0, // User messages have no token usage
|
|
161
|
+
0);
|
|
162
|
+
return ok(message);
|
|
163
|
+
}
|
|
164
|
+
isAgentLoopStartMessage(message) {
|
|
165
|
+
// A user message with only text content marks the start of an agentic loop.
|
|
166
|
+
return (message.role === "user" && message.content.every((c) => c.type === "text"));
|
|
167
|
+
}
|
|
168
|
+
isAgentLoopInnerStartMessage(m) {
|
|
169
|
+
// We prune at tool_uses because it ensures the conversation is valid (since any following
|
|
170
|
+
// tool_result is guaranteed to have its corresponding tool_use before it).
|
|
171
|
+
return m.role === "agent" && m.content.some((c) => c.type === "tool_use");
|
|
172
|
+
}
|
|
173
|
+
shiftContextPruning() {
|
|
174
|
+
/**
|
|
175
|
+
* We bump lastAgentLoopInnerStartIdx whilst ensuring that the conversation is valid. This is
|
|
176
|
+
* done by pruning messages before a tool_use (since any following tool_result is guaranteed to
|
|
177
|
+
* have its corresponding tool_use before it).
|
|
178
|
+
*/
|
|
179
|
+
assert(this.contextPruning.lastAgentLoopInnerStartIdx < this.messages.length, "lastLoopInnerStartIdx is out of bounds.");
|
|
180
|
+
let idx = this.contextPruning.lastAgentLoopInnerStartIdx >
|
|
181
|
+
this.contextPruning.lastAgentLoopStartIdx
|
|
182
|
+
? this.contextPruning.lastAgentLoopInnerStartIdx + 1
|
|
183
|
+
: /* This avoids an unneeded iteration, without this, if they were equal, the result of the
|
|
184
|
+
* iteration would have been: lastAgentLoopInnerStartIdx === lastAgentLoopStartIdx + 1.
|
|
185
|
+
* Which results in no change to `messages` since:
|
|
186
|
+
* forall idx, messages.slice(idx) === [messages[idx], ...messages.slice(idx+1)] */
|
|
187
|
+
this.contextPruning.lastAgentLoopInnerStartIdx + 2;
|
|
188
|
+
let foundNewAgenticLoop = false;
|
|
189
|
+
for (; idx < this.messages.length; idx++) {
|
|
190
|
+
const m = this.messages[idx].toJSON();
|
|
191
|
+
if (this.isAgentLoopInnerStartMessage(m)) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (this.isAgentLoopStartMessage(m)) {
|
|
195
|
+
foundNewAgenticLoop = true;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (idx >= this.messages.length) {
|
|
200
|
+
return err("agent_loop_overflow_error", "No agentic loop start position found after last.");
|
|
201
|
+
}
|
|
202
|
+
if (foundNewAgenticLoop) {
|
|
203
|
+
this.contextPruning.lastAgentLoopStartIdx = idx;
|
|
204
|
+
}
|
|
205
|
+
this.contextPruning.lastAgentLoopInnerStartIdx = idx;
|
|
206
|
+
return ok(undefined);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Render past agent messages to the model handling truncation to fit the model context window as
|
|
210
|
+
* needed.
|
|
211
|
+
*
|
|
212
|
+
* @param systemPrompt System prompt to use for the model call.
|
|
213
|
+
* @param tools Tools to provide to the model.
|
|
214
|
+
*/
|
|
215
|
+
async renderForModel(systemPrompt, tools) {
|
|
216
|
+
/**
|
|
217
|
+
* Invariants:
|
|
218
|
+
* (1) The agent loop is always started by a user message (with only text content).
|
|
219
|
+
* (2) Tool Result must be preceded by a corresponding (i.e. same tool_use_id) Tool Use.
|
|
220
|
+
*
|
|
221
|
+
* - If lastAgentLoopInnerStartIdx === lastAgentLoopStartIdx: we have a full agent loop. And we
|
|
222
|
+
* select all messages from lastAgentLoopStartIdx (messages[lastAgentLoopInnerStartIdx]
|
|
223
|
+
* verifies (1)). And since the agent loop is not pruned we also automatically verify (2).
|
|
224
|
+
*
|
|
225
|
+
* If lastAgentLoopInnerStartIdx > lastAgentLoopStartIdx: we prune messages *in* the agent loop.
|
|
226
|
+
* We select messages from lastAgentLoopInnerStartIdx (messages[lastAgentLoopInnerStartIdx]
|
|
227
|
+
* verifies (2)). BUT we also need to include the user text message at the start of the agent
|
|
228
|
+
* loop (at lastAgentLoopStartIdx) to ensure (1).
|
|
229
|
+
*/
|
|
230
|
+
let tokenCount = 0;
|
|
231
|
+
do {
|
|
232
|
+
// Prune messages before contextPruning.lastAgentLoopInnerStartIdx.
|
|
233
|
+
let messages = [...this.messages]
|
|
234
|
+
.slice(this.contextPruning.lastAgentLoopInnerStartIdx)
|
|
235
|
+
.map((m) => m.toJSON());
|
|
236
|
+
if (this.contextPruning.lastAgentLoopInnerStartIdx >
|
|
237
|
+
this.contextPruning.lastAgentLoopStartIdx) {
|
|
238
|
+
// A valid conversation must begin with a user message. In this case we use the
|
|
239
|
+
// user message at the start of the agent loop. Ensuring (1).
|
|
240
|
+
const agentLoopStartUserMessage = this.messages[this.contextPruning.lastAgentLoopStartIdx].toJSON();
|
|
241
|
+
messages = [agentLoopStartUserMessage, ...messages];
|
|
242
|
+
}
|
|
243
|
+
const res = await this.model.tokens(messages, systemPrompt, tools);
|
|
244
|
+
if (res.isErr()) {
|
|
245
|
+
console.log("Agent: " + this.agentIndex);
|
|
246
|
+
console.log(messages.length);
|
|
247
|
+
messages.forEach((m) => {
|
|
248
|
+
console.log(m.role);
|
|
249
|
+
console.log(m.content);
|
|
250
|
+
console.log("----");
|
|
251
|
+
});
|
|
252
|
+
return res;
|
|
253
|
+
}
|
|
254
|
+
tokenCount = res.value;
|
|
255
|
+
if (tokenCount > this.model.maxTokens()) {
|
|
256
|
+
const res = this.shiftContextPruning();
|
|
257
|
+
if (res.isErr()) {
|
|
258
|
+
return res;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
return ok(messages);
|
|
263
|
+
}
|
|
264
|
+
} while (tokenCount > this.model.maxTokens());
|
|
265
|
+
return err("agent_loop_overflow_error", "Unreachable");
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Logs message content during runner execution to display progress.
|
|
269
|
+
*/
|
|
270
|
+
logContent(c, messageId) {
|
|
271
|
+
let out = `\x1b[1m\x1b[37mAgent ${this.agentIndex}\x1b[0m`; // name: bold white
|
|
272
|
+
if (messageId) {
|
|
273
|
+
out += ` \x1b[1m\x1b[33m#${messageId}\x1b[0m`; // message id: bold yellow if available
|
|
274
|
+
}
|
|
275
|
+
switch (c.type) {
|
|
276
|
+
case "thinking": {
|
|
277
|
+
out += ` \x1b[90m>\x1b[0m `; // separator: grey
|
|
278
|
+
out += `\x1b[1m\x1b[95mThinking:\x1b[0m `; // label: bold magenta/purple
|
|
279
|
+
out += `\x1b[90m${c.thinking.replace(/\n/g, " ")}\x1b[0m`; // text: grey
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case "text": {
|
|
283
|
+
out += ` \x1b[90m>\x1b[0m `; // separator: grey
|
|
284
|
+
out += `\x1b[1m\x1b[38;5;208mText:\x1b[0m `; // label: bold orange (256-color)
|
|
285
|
+
out += `\x1b[90m${c.text.replace(/\n/g, " ")}\x1b[0m`; // content: grey
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "tool_use": {
|
|
289
|
+
out += ` \x1b[90m>\x1b[0m `; // separator: grey
|
|
290
|
+
out += `\x1b[1m\x1b[32mToolUse:\x1b[0m `; // label: bold green
|
|
291
|
+
out += `${c.name}`;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case "tool_result": {
|
|
295
|
+
out += ` \x1b[90m<\x1b[0m `; // separator: grey
|
|
296
|
+
out += `\x1b[1m\x1b[34mToolResult:\x1b[0m `; // label: bold blue
|
|
297
|
+
out +=
|
|
298
|
+
`${c.toolUseName} ` +
|
|
299
|
+
`${c.isError
|
|
300
|
+
? "\x1b[1m\x1b[31m[error]\x1b[0m"
|
|
301
|
+
: "\x1b[1m\x1b[32m[success]\x1b[0m"}`;
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
default:
|
|
305
|
+
assertNever(c);
|
|
306
|
+
}
|
|
307
|
+
console.log(out);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Advance runer by one tick (one agent call + associated tools executions).
|
|
311
|
+
*/
|
|
312
|
+
async tick() {
|
|
313
|
+
const tools = await this.tools();
|
|
314
|
+
if (tools.isErr()) {
|
|
315
|
+
return tools;
|
|
316
|
+
}
|
|
317
|
+
if (this.isNewUserMessageNeeded()) {
|
|
318
|
+
const newMessage = await this.newUserMessage();
|
|
319
|
+
if (newMessage.isErr()) {
|
|
320
|
+
return newMessage;
|
|
321
|
+
}
|
|
322
|
+
this.messages.push(newMessage.value);
|
|
323
|
+
}
|
|
324
|
+
const profile = this.experiment.toJSON().profile;
|
|
325
|
+
const systemPrompt = loadPromptForProfile(profile).replace("{{PROBLEM}}", this.experiment.toJSON().problem);
|
|
326
|
+
const messagesForModel = await this.renderForModel(systemPrompt, tools.value);
|
|
327
|
+
if (messagesForModel.isErr()) {
|
|
328
|
+
return messagesForModel;
|
|
329
|
+
}
|
|
330
|
+
const res = await withRetries(async () => {
|
|
331
|
+
return this.model.run(messagesForModel.value, systemPrompt, tools.value);
|
|
332
|
+
})({});
|
|
333
|
+
if (res.isErr()) {
|
|
334
|
+
return res;
|
|
335
|
+
}
|
|
336
|
+
const { message, tokenUsage } = res.value;
|
|
337
|
+
if (message.content.length === 0) {
|
|
338
|
+
console.log(`WARNING: Skipping empty agent response content for agent ${this.agentIndex}`);
|
|
339
|
+
return ok(undefined);
|
|
340
|
+
}
|
|
341
|
+
const toolResults = await concurrentExecutor(message.content.filter((content) => content.type === "tool_use"), async (t) => {
|
|
342
|
+
return await this.executeTool(t);
|
|
343
|
+
}, { concurrency: 8 });
|
|
344
|
+
const last = this.messages[this.messages.length - 1];
|
|
345
|
+
// Calculate cost and tokens for this message
|
|
346
|
+
const totalTokens = tokenUsage?.total ?? 0;
|
|
347
|
+
const cost = tokenUsage ? this.model.cost([tokenUsage]) : 0;
|
|
348
|
+
const agentMessage = await MessageResource.create(this.experiment, this.agentIndex, message, last.position() + 1, totalTokens, cost);
|
|
349
|
+
this.messages.push(agentMessage);
|
|
350
|
+
message.content.forEach((c) => {
|
|
351
|
+
this.logContent(c, agentMessage.toJSON().id);
|
|
352
|
+
});
|
|
353
|
+
if (toolResults.length > 0) {
|
|
354
|
+
const toolResultsMessage = await MessageResource.create(this.experiment, this.agentIndex, {
|
|
355
|
+
role: "user",
|
|
356
|
+
content: toolResults,
|
|
357
|
+
}, last.position() + 2, 0, // Tool results have no token usage
|
|
358
|
+
0);
|
|
359
|
+
this.messages.push(toolResultsMessage);
|
|
360
|
+
toolResults.forEach((tr) => {
|
|
361
|
+
this.logContent(tr, toolResultsMessage.toJSON().id);
|
|
362
|
+
if (tr.isError) {
|
|
363
|
+
console.error(tr.content);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
return ok(undefined);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runner/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,WAAW,EAAU,GAAG,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,SAAS,oBAAoB,CAAC,OAAe;IAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAC3E,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,OAAO,MAAM;IACT,UAAU,CAAqB;IAC/B,UAAU,CAAS;IACnB,UAAU,CAAW;I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,EACf,OAAO,EACP,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,EACnB,WAAW,EACX,IAAI,CACL,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEjC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC5B,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAC,MAAM,CACrD,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,EACf;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW;aACrB,EACD,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,EACnB,CAAC,EAAE,mCAAmC;YACtC,CAAC,CACF,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAEvC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;gBACzB,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBACpD,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";AAAA,eAAe;AACf,qDAAqD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@anonx3247/universal-agent-harness",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal multi-agent orchestration system with MCP server support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"imports": {
|
|
15
|
+
"@app/*": "./src/*"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"agent-harness": "./dist/agent-harness.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"profiles",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "NODE_OPTIONS='--max-old-space-size=8192' eslint --cache --cache-location .eslintcache src/",
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"dev": "tsx src/agent-harness.ts"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
33
|
+
"@types/dockerode": "^3.3.44",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"@types/tar-stream": "^3.1.4",
|
|
36
|
+
"drizzle-kit": "^0.31.4",
|
|
37
|
+
"eslint": "^9.39.1",
|
|
38
|
+
"tsx": "^4.0.0",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"typescript-eslint": "^8.46.3"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@anthropic-ai/sdk": "^0.57.0",
|
|
44
|
+
"@google/genai": "^1.13.0",
|
|
45
|
+
"@huggingface/transformers": "^3.8.1",
|
|
46
|
+
"@mistralai/mistralai": "^1.10.0",
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.17.1",
|
|
48
|
+
"@types/json-schema": "^7.0.15",
|
|
49
|
+
"better-sqlite3": "^12.2.0",
|
|
50
|
+
"commander": "^14.0.0",
|
|
51
|
+
"dockerode": "^4.0.8",
|
|
52
|
+
"drizzle-orm": "^0.44.3",
|
|
53
|
+
"jiti": "^2.6.1",
|
|
54
|
+
"openai": "^5.16.0",
|
|
55
|
+
"tar-stream": "^3.1.7"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
You are an AI agent working autonomously to solve problems using the tools available to you.
|
|
2
|
+
|
|
3
|
+
## Your Environment
|
|
4
|
+
|
|
5
|
+
You have access to various tools through MCP (Model Context Protocol) servers. The specific tools available depend on your configuration, but may include:
|
|
6
|
+
- File system operations
|
|
7
|
+
- Code execution
|
|
8
|
+
- API integrations
|
|
9
|
+
- Data storage and retrieval
|
|
10
|
+
- And more...
|
|
11
|
+
|
|
12
|
+
Use the tools you have access to creatively and effectively to solve the problem at hand.
|
|
13
|
+
|
|
14
|
+
## Primary Objective
|
|
15
|
+
|
|
16
|
+
**Problem Solving**: Your fundamental goal is to solve the problem systematically and thoroughly. Approach every task with:
|
|
17
|
+
- Intellectual honesty
|
|
18
|
+
- Skepticism of unsubstantiated claims
|
|
19
|
+
- Commitment to following evidence wherever it leads
|
|
20
|
+
- Rigorous verification of results
|
|
21
|
+
|
|
22
|
+
## Core Principles
|
|
23
|
+
|
|
24
|
+
**Rigorous Thinking**: Employ critical thinking and rigorous justification. A solution cannot be considered valid unless every step is logically sound and clearly explained.
|
|
25
|
+
|
|
26
|
+
**Honesty About Completeness**: If you cannot find a complete solution, present only significant partial results that you can rigorously justify. Do not guess or create solutions with hidden flaws.
|
|
27
|
+
|
|
28
|
+
**Divide and Conquer**: Break complex problems into manageable sub-problems. Solve them independently and combine results to form a complete solution.
|
|
29
|
+
|
|
30
|
+
**Challenge Assumptions**: Actively seek out and challenge existing assumptions, methodologies, and conclusions. Be open to revising your views based on new evidence.
|
|
31
|
+
|
|
32
|
+
## Working Method
|
|
33
|
+
|
|
34
|
+
1. **Understand the Problem**: Read and analyze the problem carefully. Break it down into components if needed.
|
|
35
|
+
|
|
36
|
+
2. **Plan Your Approach**: Outline the steps you'll take to solve the problem.
|
|
37
|
+
|
|
38
|
+
3. **Execute Systematically**: Use your available tools to:
|
|
39
|
+
- Gather and analyze information
|
|
40
|
+
- Test hypotheses
|
|
41
|
+
- Verify results
|
|
42
|
+
- Document findings
|
|
43
|
+
|
|
44
|
+
4. **Verify Results**: Always verify your work. Test edge cases, check calculations, and ensure logical soundness.
|
|
45
|
+
|
|
46
|
+
5. **Document Progress**: Keep clear reasoning about your findings and any obstacles encountered.
|
|
47
|
+
|
|
48
|
+
## Autonomous Operation
|
|
49
|
+
|
|
50
|
+
There is no user interacting with you. Never ask for confirmation or approval - proceed autonomously with your plan. Work persistently toward solving the problem, exploring different approaches as needed.
|
|
51
|
+
|
|
52
|
+
## Problem
|
|
53
|
+
|
|
54
|
+
{{PROBLEM}}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": [
|
|
3
|
+
{
|
|
4
|
+
"name": "filesystem",
|
|
5
|
+
"transport": "stdio",
|
|
6
|
+
"command": "npx",
|
|
7
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
|
|
8
|
+
"enabled": true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "github",
|
|
12
|
+
"transport": "stdio",
|
|
13
|
+
"command": "npx",
|
|
14
|
+
"args": ["-y", "@modelcontextprotocol/server-github"],
|
|
15
|
+
"env": {
|
|
16
|
+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
|
|
17
|
+
},
|
|
18
|
+
"enabled": false
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "brave-search",
|
|
22
|
+
"transport": "stdio",
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
|
|
25
|
+
"env": {
|
|
26
|
+
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
|
|
27
|
+
},
|
|
28
|
+
"enabled": false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "custom-api",
|
|
32
|
+
"transport": "sse",
|
|
33
|
+
"url": "https://api.example.com/mcp",
|
|
34
|
+
"token": "${API_TOKEN}",
|
|
35
|
+
"enabled": false
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|