@mcpmesh/sdk 0.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/claude-handler.test.d.ts +7 -0
- package/dist/__tests__/claude-handler.test.d.ts.map +1 -0
- package/dist/__tests__/claude-handler.test.js +455 -0
- package/dist/__tests__/claude-handler.test.js.map +1 -0
- package/dist/__tests__/config.test.d.ts +7 -0
- package/dist/__tests__/config.test.d.ts.map +1 -0
- package/dist/__tests__/config.test.js +156 -0
- package/dist/__tests__/config.test.js.map +1 -0
- package/dist/__tests__/errors.test.d.ts +7 -0
- package/dist/__tests__/errors.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test.js +170 -0
- package/dist/__tests__/errors.test.js.map +1 -0
- package/dist/__tests__/generic-handler.test.d.ts +7 -0
- package/dist/__tests__/generic-handler.test.d.ts.map +1 -0
- package/dist/__tests__/generic-handler.test.js +243 -0
- package/dist/__tests__/generic-handler.test.js.map +1 -0
- package/dist/__tests__/llm-provider.test.d.ts +7 -0
- package/dist/__tests__/llm-provider.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider.test.js +217 -0
- package/dist/__tests__/llm-provider.test.js.map +1 -0
- package/dist/__tests__/openai-handler.test.d.ts +7 -0
- package/dist/__tests__/openai-handler.test.d.ts.map +1 -0
- package/dist/__tests__/openai-handler.test.js +359 -0
- package/dist/__tests__/openai-handler.test.js.map +1 -0
- package/dist/__tests__/provider-handler-registry.test.d.ts +9 -0
- package/dist/__tests__/provider-handler-registry.test.d.ts.map +1 -0
- package/dist/__tests__/provider-handler-registry.test.js +187 -0
- package/dist/__tests__/provider-handler-registry.test.js.map +1 -0
- package/dist/__tests__/response-parser.test.d.ts +7 -0
- package/dist/__tests__/response-parser.test.d.ts.map +1 -0
- package/dist/__tests__/response-parser.test.js +360 -0
- package/dist/__tests__/response-parser.test.js.map +1 -0
- package/dist/__tests__/route.test.d.ts +7 -0
- package/dist/__tests__/route.test.d.ts.map +1 -0
- package/dist/__tests__/route.test.js +281 -0
- package/dist/__tests__/route.test.js.map +1 -0
- package/dist/__tests__/sse.test.d.ts +7 -0
- package/dist/__tests__/sse.test.d.ts.map +1 -0
- package/dist/__tests__/sse.test.js +172 -0
- package/dist/__tests__/sse.test.js.map +1 -0
- package/dist/__tests__/template.test.d.ts +7 -0
- package/dist/__tests__/template.test.d.ts.map +1 -0
- package/dist/__tests__/template.test.js +176 -0
- package/dist/__tests__/template.test.js.map +1 -0
- package/dist/__tests__/tracing.test.d.ts +7 -0
- package/dist/__tests__/tracing.test.d.ts.map +1 -0
- package/dist/__tests__/tracing.test.js +264 -0
- package/dist/__tests__/tracing.test.js.map +1 -0
- package/dist/agent.d.ts +165 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +626 -0
- package/dist/agent.js.map +1 -0
- package/dist/api-runtime.d.ts +166 -0
- package/dist/api-runtime.d.ts.map +1 -0
- package/dist/api-runtime.js +459 -0
- package/dist/api-runtime.js.map +1 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/debug.d.ts +47 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +86 -0
- package/dist/debug.js.map +1 -0
- package/dist/errors.d.ts +99 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +110 -0
- package/dist/errors.js.map +1 -0
- package/dist/express.d.ts +146 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +371 -0
- package/dist/express.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-agent.d.ts +193 -0
- package/dist/llm-agent.d.ts.map +1 -0
- package/dist/llm-agent.js +634 -0
- package/dist/llm-agent.js.map +1 -0
- package/dist/llm-provider.d.ts +323 -0
- package/dist/llm-provider.d.ts.map +1 -0
- package/dist/llm-provider.js +446 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/llm.d.ts +194 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +304 -0
- package/dist/llm.js.map +1 -0
- package/dist/provider-handlers/claude-handler.d.ts +98 -0
- package/dist/provider-handlers/claude-handler.d.ts.map +1 -0
- package/dist/provider-handlers/claude-handler.js +268 -0
- package/dist/provider-handlers/claude-handler.js.map +1 -0
- package/dist/provider-handlers/gemini-handler.d.ts +82 -0
- package/dist/provider-handlers/gemini-handler.d.ts.map +1 -0
- package/dist/provider-handlers/gemini-handler.js +152 -0
- package/dist/provider-handlers/gemini-handler.js.map +1 -0
- package/dist/provider-handlers/generic-handler.d.ts +78 -0
- package/dist/provider-handlers/generic-handler.d.ts.map +1 -0
- package/dist/provider-handlers/generic-handler.js +152 -0
- package/dist/provider-handlers/generic-handler.js.map +1 -0
- package/dist/provider-handlers/index.d.ts +29 -0
- package/dist/provider-handlers/index.d.ts.map +1 -0
- package/dist/provider-handlers/index.js +32 -0
- package/dist/provider-handlers/index.js.map +1 -0
- package/dist/provider-handlers/openai-handler.d.ts +86 -0
- package/dist/provider-handlers/openai-handler.d.ts.map +1 -0
- package/dist/provider-handlers/openai-handler.js +160 -0
- package/dist/provider-handlers/openai-handler.js.map +1 -0
- package/dist/provider-handlers/provider-handler-registry.d.ts +124 -0
- package/dist/provider-handlers/provider-handler-registry.d.ts.map +1 -0
- package/dist/provider-handlers/provider-handler-registry.js +180 -0
- package/dist/provider-handlers/provider-handler-registry.js.map +1 -0
- package/dist/provider-handlers/provider-handler.d.ts +245 -0
- package/dist/provider-handlers/provider-handler.d.ts.map +1 -0
- package/dist/provider-handlers/provider-handler.js +238 -0
- package/dist/provider-handlers/provider-handler.js.map +1 -0
- package/dist/proxy.d.ts +44 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +324 -0
- package/dist/proxy.js.map +1 -0
- package/dist/response-parser.d.ts +103 -0
- package/dist/response-parser.d.ts.map +1 -0
- package/dist/response-parser.js +232 -0
- package/dist/response-parser.js.map +1 -0
- package/dist/route.d.ts +185 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +310 -0
- package/dist/route.js.map +1 -0
- package/dist/sse.d.ts +45 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +77 -0
- package/dist/sse.js.map +1 -0
- package/dist/template.d.ts +86 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +206 -0
- package/dist/template.js.map +1 -0
- package/dist/tracing.d.ts +88 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +193 -0
- package/dist/tracing.js.map +1 -0
- package/dist/types.d.ts +618 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MeshLlmAgent - Agentic loop implementation for LLM-powered tools.
|
|
3
|
+
*
|
|
4
|
+
* This class handles:
|
|
5
|
+
* - System prompt rendering (with Handlebars templates)
|
|
6
|
+
* - Agentic loop with tool execution
|
|
7
|
+
* - LLM provider calls (direct LiteLLM or mesh delegation)
|
|
8
|
+
* - Response parsing with Zod validation
|
|
9
|
+
* - Metadata tracking (tokens, latency, tool calls)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const agent = new MeshLlmAgent({
|
|
14
|
+
* provider: "claude",
|
|
15
|
+
* model: "anthropic/claude-sonnet-4-20250514",
|
|
16
|
+
* systemPrompt: "file://prompts/assistant.hbs",
|
|
17
|
+
* maxIterations: 10,
|
|
18
|
+
* returnSchema: ResponseSchema,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const result = await agent.run("Help me calculate 2+2", {
|
|
22
|
+
* templateContext: { user: "John" },
|
|
23
|
+
* tools: resolvedToolProxies,
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
28
|
+
import { renderTemplate } from "./template.js";
|
|
29
|
+
import { ResponseParser } from "./response-parser.js";
|
|
30
|
+
import { MaxIterationsError, LLMAPIError, ToolExecutionError, } from "./errors.js";
|
|
31
|
+
import { parseSSEResponse } from "./sse.js";
|
|
32
|
+
/**
|
|
33
|
+
* Default LiteLLM provider using HTTP proxy.
|
|
34
|
+
* Assumes LiteLLM proxy is running at LITELLM_URL or localhost:4000.
|
|
35
|
+
*/
|
|
36
|
+
export class LiteLLMProvider {
|
|
37
|
+
baseUrl;
|
|
38
|
+
constructor(baseUrl) {
|
|
39
|
+
this.baseUrl = baseUrl || process.env.LITELLM_URL || "http://localhost:4000";
|
|
40
|
+
}
|
|
41
|
+
async complete(model, messages, tools, options) {
|
|
42
|
+
const body = {
|
|
43
|
+
model,
|
|
44
|
+
messages,
|
|
45
|
+
};
|
|
46
|
+
if (tools && tools.length > 0) {
|
|
47
|
+
body.tools = tools;
|
|
48
|
+
body.tool_choice = "auto";
|
|
49
|
+
}
|
|
50
|
+
if (options?.maxOutputTokens)
|
|
51
|
+
body.max_tokens = options.maxOutputTokens;
|
|
52
|
+
if (options?.temperature !== undefined)
|
|
53
|
+
body.temperature = options.temperature;
|
|
54
|
+
if (options?.topP !== undefined)
|
|
55
|
+
body.top_p = options.topP;
|
|
56
|
+
if (options?.stop)
|
|
57
|
+
body.stop = options.stop;
|
|
58
|
+
// Set up timeout with AbortController (default 300s to match Python SDK's stream_timeout)
|
|
59
|
+
const timeoutMs = parseInt(process.env.LITELLM_TIMEOUT_MS || "300000", 10);
|
|
60
|
+
const controller = new AbortController();
|
|
61
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
62
|
+
let response;
|
|
63
|
+
try {
|
|
64
|
+
response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body),
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
clearTimeout(timeoutId);
|
|
75
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
76
|
+
throw new LLMAPIError(408, `Request timed out after ${timeoutMs}ms`, "litellm");
|
|
77
|
+
}
|
|
78
|
+
throw new LLMAPIError(0, `Fetch failed: ${error instanceof Error ? error.message : String(error)}`, "litellm");
|
|
79
|
+
}
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const error = await response.text();
|
|
83
|
+
throw new LLMAPIError(response.status, error, "litellm");
|
|
84
|
+
}
|
|
85
|
+
return (await response.json());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Mesh provider that delegates to an LLM provider discovered via mesh.
|
|
90
|
+
*/
|
|
91
|
+
export class MeshDelegatedProvider {
|
|
92
|
+
endpoint;
|
|
93
|
+
functionName;
|
|
94
|
+
constructor(endpoint, functionName) {
|
|
95
|
+
this.endpoint = endpoint;
|
|
96
|
+
this.functionName = functionName;
|
|
97
|
+
}
|
|
98
|
+
async complete(model, messages, tools, options) {
|
|
99
|
+
// Build MeshLlmRequest structure (matches Python claude_provider schema)
|
|
100
|
+
const modelParams = {};
|
|
101
|
+
// Only pass model if it's a real model name (not "default")
|
|
102
|
+
if (model && model !== "default") {
|
|
103
|
+
modelParams.model = model;
|
|
104
|
+
}
|
|
105
|
+
if (options?.maxOutputTokens)
|
|
106
|
+
modelParams.max_tokens = options.maxOutputTokens;
|
|
107
|
+
if (options?.temperature !== undefined)
|
|
108
|
+
modelParams.temperature = options.temperature;
|
|
109
|
+
if (options?.topP !== undefined)
|
|
110
|
+
modelParams.top_p = options.topP;
|
|
111
|
+
if (options?.stop)
|
|
112
|
+
modelParams.stop = options.stop;
|
|
113
|
+
const request = {
|
|
114
|
+
messages,
|
|
115
|
+
};
|
|
116
|
+
// Only include model_params if there are params
|
|
117
|
+
if (Object.keys(modelParams).length > 0) {
|
|
118
|
+
request.model_params = modelParams;
|
|
119
|
+
}
|
|
120
|
+
if (tools && tools.length > 0) {
|
|
121
|
+
request.tools = tools;
|
|
122
|
+
}
|
|
123
|
+
// Wrap in "request" parameter as expected by Python claude_provider
|
|
124
|
+
const args = { request };
|
|
125
|
+
// Set up timeout with AbortController (default 300s to match Python SDK's stream_timeout)
|
|
126
|
+
const timeoutMs = parseInt(process.env.MESH_PROVIDER_TIMEOUT_MS || "300000", 10);
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
129
|
+
// Call the mesh provider via MCP
|
|
130
|
+
let response;
|
|
131
|
+
try {
|
|
132
|
+
response = await fetch(`${this.endpoint}/mcp`, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: {
|
|
135
|
+
"Content-Type": "application/json",
|
|
136
|
+
"Accept": "application/json, text/event-stream",
|
|
137
|
+
},
|
|
138
|
+
body: JSON.stringify({
|
|
139
|
+
jsonrpc: "2.0",
|
|
140
|
+
id: Date.now(),
|
|
141
|
+
method: "tools/call",
|
|
142
|
+
params: {
|
|
143
|
+
name: this.functionName,
|
|
144
|
+
arguments: args,
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
signal: controller.signal,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
clearTimeout(timeoutId);
|
|
152
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
153
|
+
throw new LLMAPIError(408, `Request timed out after ${timeoutMs}ms`, `mesh:${this.endpoint}`);
|
|
154
|
+
}
|
|
155
|
+
throw new LLMAPIError(0, `Fetch failed: ${error instanceof Error ? error.message : String(error)}`, `mesh:${this.endpoint}`);
|
|
156
|
+
}
|
|
157
|
+
clearTimeout(timeoutId);
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
const error = await response.text();
|
|
160
|
+
throw new LLMAPIError(response.status, error, `mesh:${this.endpoint}`);
|
|
161
|
+
}
|
|
162
|
+
// Handle SSE response from FastMCP stateless HTTP stream
|
|
163
|
+
const responseText = await response.text();
|
|
164
|
+
const result = parseSSEResponse(responseText);
|
|
165
|
+
if (result.error) {
|
|
166
|
+
throw new Error(`Mesh provider RPC error: ${result.error.message}`);
|
|
167
|
+
}
|
|
168
|
+
// Parse the MCP result content
|
|
169
|
+
const content = result.result?.content?.[0];
|
|
170
|
+
if (!content || content.type !== "text") {
|
|
171
|
+
throw new Error("Invalid response from mesh provider");
|
|
172
|
+
}
|
|
173
|
+
// Check for MCP tool execution error (isError flag in result)
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
+
if (result.result?.isError) {
|
|
176
|
+
throw new Error(`Mesh provider tool error: ${content.text}`);
|
|
177
|
+
}
|
|
178
|
+
// Parse the LLM provider response
|
|
179
|
+
// Format: { role, content, tool_calls?, _mesh_usage? }
|
|
180
|
+
const meshResponse = JSON.parse(content.text);
|
|
181
|
+
// Validate role - LLM responses should always be "assistant"
|
|
182
|
+
let validatedRole = "assistant";
|
|
183
|
+
if (meshResponse.role !== "assistant") {
|
|
184
|
+
console.warn(`[mesh.llm] Unexpected role "${meshResponse.role}" from mesh provider, defaulting to "assistant"`);
|
|
185
|
+
}
|
|
186
|
+
// Convert to OpenAI format expected by MeshLlmAgent
|
|
187
|
+
const openAiResponse = {
|
|
188
|
+
id: `mesh-${Date.now()}`,
|
|
189
|
+
object: "chat.completion",
|
|
190
|
+
created: Math.floor(Date.now() / 1000),
|
|
191
|
+
model: "mesh-delegated",
|
|
192
|
+
choices: [
|
|
193
|
+
{
|
|
194
|
+
index: 0,
|
|
195
|
+
message: {
|
|
196
|
+
role: validatedRole,
|
|
197
|
+
content: meshResponse.content,
|
|
198
|
+
tool_calls: meshResponse.tool_calls,
|
|
199
|
+
},
|
|
200
|
+
finish_reason: meshResponse.tool_calls ? "tool_calls" : "stop",
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
usage: meshResponse._mesh_usage
|
|
204
|
+
? {
|
|
205
|
+
prompt_tokens: meshResponse._mesh_usage.prompt_tokens,
|
|
206
|
+
completion_tokens: meshResponse._mesh_usage.completion_tokens,
|
|
207
|
+
total_tokens: meshResponse._mesh_usage.prompt_tokens +
|
|
208
|
+
meshResponse._mesh_usage.completion_tokens,
|
|
209
|
+
}
|
|
210
|
+
: undefined,
|
|
211
|
+
};
|
|
212
|
+
return openAiResponse;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* MeshLlmAgent - The core agentic loop implementation.
|
|
217
|
+
*/
|
|
218
|
+
export class MeshLlmAgent {
|
|
219
|
+
config;
|
|
220
|
+
responseParser;
|
|
221
|
+
_meta = null;
|
|
222
|
+
_systemPromptOverride = null;
|
|
223
|
+
constructor(config) {
|
|
224
|
+
this.config = config;
|
|
225
|
+
this.responseParser = new ResponseParser(config.returnSchema);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get metadata from the last run.
|
|
229
|
+
*/
|
|
230
|
+
get meta() {
|
|
231
|
+
return this._meta;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Override the system prompt at runtime.
|
|
235
|
+
*/
|
|
236
|
+
setSystemPrompt(prompt) {
|
|
237
|
+
this._systemPromptOverride = prompt;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get the effective system prompt (override or config).
|
|
241
|
+
*/
|
|
242
|
+
getSystemPrompt() {
|
|
243
|
+
return this._systemPromptOverride ?? this.config.systemPrompt;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Run the agentic loop.
|
|
247
|
+
*
|
|
248
|
+
* @param messageInput - User message string or multi-turn message array
|
|
249
|
+
* @param context - Runtime context with tools and options
|
|
250
|
+
* @returns Parsed response (validated if schema provided)
|
|
251
|
+
*/
|
|
252
|
+
async run(messageInput, context) {
|
|
253
|
+
const startTime = Date.now();
|
|
254
|
+
const toolCalls = [];
|
|
255
|
+
let totalInputTokens = 0;
|
|
256
|
+
let totalOutputTokens = 0;
|
|
257
|
+
// Resolve provider
|
|
258
|
+
const provider = this.resolveProvider(context);
|
|
259
|
+
// Build initial messages
|
|
260
|
+
const messages = [];
|
|
261
|
+
// Build tool definitions first (needed for schema injection)
|
|
262
|
+
const toolDefs = this.buildToolDefinitions(context.tools);
|
|
263
|
+
// Add system prompt if configured
|
|
264
|
+
const systemPromptTemplate = this.getSystemPrompt();
|
|
265
|
+
if (systemPromptTemplate) {
|
|
266
|
+
let systemContent = await renderTemplate(systemPromptTemplate, context.templateContext ?? {});
|
|
267
|
+
// Inject tool schemas into system prompt (Python parity feature)
|
|
268
|
+
if (toolDefs.length > 0) {
|
|
269
|
+
const toolSchemaSection = this.buildToolSchemaSection(toolDefs);
|
|
270
|
+
systemContent += toolSchemaSection;
|
|
271
|
+
}
|
|
272
|
+
// Inject output schema hint if using "hint" or "strict" mode with a schema
|
|
273
|
+
const outputMode = this.config.outputMode ?? "hint";
|
|
274
|
+
if (outputMode !== "text" && this.config.returnSchema) {
|
|
275
|
+
const outputSchemaSection = this.buildOutputSchemaSection();
|
|
276
|
+
systemContent += outputSchemaSection;
|
|
277
|
+
}
|
|
278
|
+
messages.push({ role: "system", content: systemContent });
|
|
279
|
+
}
|
|
280
|
+
// Handle multi-turn conversation input
|
|
281
|
+
if (typeof messageInput === "string") {
|
|
282
|
+
// Simple string - add as user message
|
|
283
|
+
messages.push({ role: "user", content: messageInput });
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
// Array of messages - add all
|
|
287
|
+
for (const msg of messageInput) {
|
|
288
|
+
messages.push({ role: msg.role, content: msg.content });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Get effective options
|
|
292
|
+
const maxIterations = context.options?.maxIterations ?? this.config.maxIterations;
|
|
293
|
+
const maxTokens = context.options?.maxOutputTokens ?? this.config.maxOutputTokens;
|
|
294
|
+
const temperature = context.options?.temperature ?? this.config.temperature;
|
|
295
|
+
// Determine model
|
|
296
|
+
const model = context.meshProvider?.model ?? this.config.model ?? this.getDefaultModel();
|
|
297
|
+
// Agentic loop
|
|
298
|
+
let iteration = 0;
|
|
299
|
+
let finalContent = "";
|
|
300
|
+
while (iteration < maxIterations) {
|
|
301
|
+
iteration++;
|
|
302
|
+
// Call LLM
|
|
303
|
+
const response = await provider.complete(model, messages, toolDefs.length > 0 ? toolDefs : undefined, { maxOutputTokens: maxTokens, temperature, topP: this.config.topP, stop: this.config.stop });
|
|
304
|
+
// Track tokens
|
|
305
|
+
if (response.usage) {
|
|
306
|
+
totalInputTokens += response.usage.prompt_tokens;
|
|
307
|
+
totalOutputTokens += response.usage.completion_tokens;
|
|
308
|
+
}
|
|
309
|
+
const choice = response.choices[0];
|
|
310
|
+
if (!choice) {
|
|
311
|
+
throw new Error("No response from LLM");
|
|
312
|
+
}
|
|
313
|
+
const assistantMessage = choice.message;
|
|
314
|
+
// Add assistant message to history
|
|
315
|
+
messages.push(assistantMessage);
|
|
316
|
+
// Check for tool calls
|
|
317
|
+
if (assistantMessage.tool_calls && assistantMessage.tool_calls.length > 0) {
|
|
318
|
+
// Execute tool calls
|
|
319
|
+
for (const toolCall of assistantMessage.tool_calls) {
|
|
320
|
+
const toolResult = await this.executeToolCall(toolCall, context.tools, toolCalls);
|
|
321
|
+
// Add tool result to messages
|
|
322
|
+
messages.push({
|
|
323
|
+
role: "tool",
|
|
324
|
+
content: typeof toolResult === "string" ? toolResult : JSON.stringify(toolResult),
|
|
325
|
+
tool_call_id: toolCall.id,
|
|
326
|
+
name: toolCall.function.name,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
// Continue loop to get next response
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
// No tool calls - this is the final response
|
|
333
|
+
finalContent = assistantMessage.content ?? "";
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
// Check if we exhausted iterations without completing
|
|
337
|
+
if (iteration >= maxIterations && finalContent === "") {
|
|
338
|
+
const lastMessage = messages[messages.length - 1];
|
|
339
|
+
throw new MaxIterationsError(iteration, lastMessage, messages);
|
|
340
|
+
}
|
|
341
|
+
// Store metadata
|
|
342
|
+
const endTime = Date.now();
|
|
343
|
+
this._meta = {
|
|
344
|
+
inputTokens: totalInputTokens,
|
|
345
|
+
outputTokens: totalOutputTokens,
|
|
346
|
+
totalTokens: totalInputTokens + totalOutputTokens,
|
|
347
|
+
latencyMs: endTime - startTime,
|
|
348
|
+
iterations: iteration,
|
|
349
|
+
toolCalls,
|
|
350
|
+
model,
|
|
351
|
+
provider: this.getProviderName(context),
|
|
352
|
+
};
|
|
353
|
+
// Parse and validate response
|
|
354
|
+
return this.responseParser.parse(finalContent);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Create a callable LlmAgent interface.
|
|
358
|
+
*/
|
|
359
|
+
createCallable(context) {
|
|
360
|
+
const agent = this;
|
|
361
|
+
const callable = async (message, options) => {
|
|
362
|
+
// Handle context mode
|
|
363
|
+
const contextMode = options?.contextMode ?? "merge";
|
|
364
|
+
let mergedTemplateContext;
|
|
365
|
+
if (contextMode === "replace" && options?.context) {
|
|
366
|
+
// Replace mode - use only the runtime context
|
|
367
|
+
mergedTemplateContext = options.context;
|
|
368
|
+
}
|
|
369
|
+
else if (options?.context) {
|
|
370
|
+
// Merge mode (default) - combine base and runtime context
|
|
371
|
+
mergedTemplateContext = { ...context.templateContext, ...options.context };
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
// No runtime context - use base context
|
|
375
|
+
mergedTemplateContext = context.templateContext ?? {};
|
|
376
|
+
}
|
|
377
|
+
// Merge options
|
|
378
|
+
const mergedContext = {
|
|
379
|
+
...context,
|
|
380
|
+
options: options ? { ...context.options, ...options } : context.options,
|
|
381
|
+
templateContext: mergedTemplateContext,
|
|
382
|
+
};
|
|
383
|
+
return agent.run(message, mergedContext);
|
|
384
|
+
};
|
|
385
|
+
// Attach meta property
|
|
386
|
+
Object.defineProperty(callable, "meta", {
|
|
387
|
+
get: () => agent.meta,
|
|
388
|
+
});
|
|
389
|
+
// Attach tools property
|
|
390
|
+
Object.defineProperty(callable, "tools", {
|
|
391
|
+
get: () => context.tools,
|
|
392
|
+
});
|
|
393
|
+
// Attach setSystemPrompt method
|
|
394
|
+
Object.defineProperty(callable, "setSystemPrompt", {
|
|
395
|
+
value: (prompt) => agent.setSystemPrompt(prompt),
|
|
396
|
+
});
|
|
397
|
+
return callable;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Resolve the LLM provider to use.
|
|
401
|
+
*/
|
|
402
|
+
resolveProvider(context) {
|
|
403
|
+
// If mesh provider is resolved, use it
|
|
404
|
+
if (context.meshProvider) {
|
|
405
|
+
return new MeshDelegatedProvider(context.meshProvider.endpoint, context.meshProvider.functionName);
|
|
406
|
+
}
|
|
407
|
+
// Use direct LiteLLM provider
|
|
408
|
+
return new LiteLLMProvider();
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get provider name for metadata.
|
|
412
|
+
*/
|
|
413
|
+
getProviderName(context) {
|
|
414
|
+
if (context.meshProvider) {
|
|
415
|
+
return `mesh:${context.meshProvider.endpoint}`;
|
|
416
|
+
}
|
|
417
|
+
if (typeof this.config.provider === "string") {
|
|
418
|
+
return this.config.provider;
|
|
419
|
+
}
|
|
420
|
+
return `mesh:${this.config.provider.capability}`;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Get default model based on provider.
|
|
424
|
+
*/
|
|
425
|
+
getDefaultModel() {
|
|
426
|
+
const provider = this.config.provider;
|
|
427
|
+
if (typeof provider === "string") {
|
|
428
|
+
// Map common provider names to models
|
|
429
|
+
const defaultModels = {
|
|
430
|
+
claude: "anthropic/claude-sonnet-4-20250514",
|
|
431
|
+
openai: "gpt-4o",
|
|
432
|
+
anthropic: "anthropic/claude-sonnet-4-20250514",
|
|
433
|
+
gpt4: "gpt-4o",
|
|
434
|
+
gpt35: "gpt-3.5-turbo",
|
|
435
|
+
};
|
|
436
|
+
return defaultModels[provider.toLowerCase()] ?? provider;
|
|
437
|
+
}
|
|
438
|
+
// Mesh delegation - model will be determined by the provider
|
|
439
|
+
return "default";
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Build tool definitions from proxies.
|
|
443
|
+
*/
|
|
444
|
+
buildToolDefinitions(tools) {
|
|
445
|
+
return tools.map((tool) => ({
|
|
446
|
+
type: "function",
|
|
447
|
+
function: {
|
|
448
|
+
name: tool.name,
|
|
449
|
+
description: tool.description,
|
|
450
|
+
parameters: tool.inputSchema ?? { type: "object", properties: {} },
|
|
451
|
+
},
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Build tool schema section for system prompt injection.
|
|
456
|
+
* Helps the LLM understand available tools and their schemas.
|
|
457
|
+
*/
|
|
458
|
+
buildToolSchemaSection(tools) {
|
|
459
|
+
if (tools.length === 0)
|
|
460
|
+
return "";
|
|
461
|
+
const toolDescriptions = tools.map((tool) => {
|
|
462
|
+
const fn = tool.function;
|
|
463
|
+
const schemaStr = fn.parameters
|
|
464
|
+
? JSON.stringify(fn.parameters, null, 2)
|
|
465
|
+
: "{}";
|
|
466
|
+
return `### ${fn.name}\n${fn.description ?? "No description"}\n\nInput Schema:\n\`\`\`json\n${schemaStr}\n\`\`\``;
|
|
467
|
+
});
|
|
468
|
+
return `\n\n## Available Tools\n\nYou have access to the following tools:\n\n${toolDescriptions.join("\n\n")}`;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Build output schema section for system prompt injection.
|
|
472
|
+
* Guides the LLM to produce structured output matching the schema.
|
|
473
|
+
*/
|
|
474
|
+
buildOutputSchemaSection() {
|
|
475
|
+
if (!this.config.returnSchema)
|
|
476
|
+
return "";
|
|
477
|
+
try {
|
|
478
|
+
const jsonSchema = zodToJsonSchema(this.config.returnSchema);
|
|
479
|
+
const schemaStr = JSON.stringify(jsonSchema, null, 2);
|
|
480
|
+
return `\n\n## Output Format\n\nYour response MUST be valid JSON matching this schema:\n\n\`\`\`json\n${schemaStr}\n\`\`\`\n\nRespond ONLY with the JSON object, no additional text.`;
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
// If schema conversion fails, skip injection
|
|
484
|
+
return "";
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Execute a tool call and record metadata.
|
|
489
|
+
*/
|
|
490
|
+
async executeToolCall(toolCall, tools, toolCallRecords) {
|
|
491
|
+
const toolName = toolCall.function.name;
|
|
492
|
+
const tool = tools.find((t) => t.name === toolName);
|
|
493
|
+
const startTime = Date.now();
|
|
494
|
+
let args = {};
|
|
495
|
+
let result;
|
|
496
|
+
let success = true;
|
|
497
|
+
let error;
|
|
498
|
+
try {
|
|
499
|
+
// Parse arguments
|
|
500
|
+
args = JSON.parse(toolCall.function.arguments);
|
|
501
|
+
if (!tool) {
|
|
502
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
503
|
+
}
|
|
504
|
+
// Execute tool
|
|
505
|
+
result = await tool(args);
|
|
506
|
+
}
|
|
507
|
+
catch (err) {
|
|
508
|
+
success = false;
|
|
509
|
+
error = err instanceof Error ? err.message : String(err);
|
|
510
|
+
result = { error };
|
|
511
|
+
}
|
|
512
|
+
const endTime = Date.now();
|
|
513
|
+
// Record tool call
|
|
514
|
+
toolCallRecords.push({
|
|
515
|
+
name: toolName,
|
|
516
|
+
args,
|
|
517
|
+
result,
|
|
518
|
+
success,
|
|
519
|
+
error,
|
|
520
|
+
latencyMs: endTime - startTime,
|
|
521
|
+
});
|
|
522
|
+
return result;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Create a tool proxy from resolved tool info.
|
|
527
|
+
*/
|
|
528
|
+
export function createLlmToolProxy(toolInfo, description) {
|
|
529
|
+
const proxy = async (args) => {
|
|
530
|
+
// Set up timeout with AbortController (default 30s for tool calls)
|
|
531
|
+
const timeoutMs = parseInt(process.env.MESH_TOOL_TIMEOUT_MS || "30000", 10);
|
|
532
|
+
const controller = new AbortController();
|
|
533
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
534
|
+
// Make MCP call to the tool
|
|
535
|
+
let response;
|
|
536
|
+
try {
|
|
537
|
+
response = await fetch(`${toolInfo.endpoint}/mcp`, {
|
|
538
|
+
method: "POST",
|
|
539
|
+
headers: {
|
|
540
|
+
"Content-Type": "application/json",
|
|
541
|
+
"Accept": "application/json, text/event-stream",
|
|
542
|
+
},
|
|
543
|
+
body: JSON.stringify({
|
|
544
|
+
jsonrpc: "2.0",
|
|
545
|
+
id: Date.now(),
|
|
546
|
+
method: "tools/call",
|
|
547
|
+
params: {
|
|
548
|
+
name: toolInfo.functionName,
|
|
549
|
+
arguments: args,
|
|
550
|
+
},
|
|
551
|
+
}),
|
|
552
|
+
signal: controller.signal,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
clearTimeout(timeoutId);
|
|
557
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
558
|
+
throw new ToolExecutionError(toolInfo.functionName, new Error(`Tool call timed out after ${timeoutMs}ms (endpoint: ${toolInfo.endpoint})`));
|
|
559
|
+
}
|
|
560
|
+
throw new ToolExecutionError(toolInfo.functionName, error instanceof Error ? error : new Error(String(error)));
|
|
561
|
+
}
|
|
562
|
+
clearTimeout(timeoutId);
|
|
563
|
+
if (!response.ok) {
|
|
564
|
+
throw new Error(`Tool call failed: ${response.status}`);
|
|
565
|
+
}
|
|
566
|
+
// Handle SSE response from FastMCP stateless HTTP stream
|
|
567
|
+
const responseText = await response.text();
|
|
568
|
+
const result = parseSSEResponse(responseText);
|
|
569
|
+
if (result.error) {
|
|
570
|
+
throw new Error(`Tool error: ${result.error.message}`);
|
|
571
|
+
}
|
|
572
|
+
// Parse result content
|
|
573
|
+
const content = result.result?.content?.[0];
|
|
574
|
+
if (!content) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
if (content.type === "text" && content.text) {
|
|
578
|
+
// Try to parse as JSON
|
|
579
|
+
try {
|
|
580
|
+
return JSON.parse(content.text);
|
|
581
|
+
}
|
|
582
|
+
catch {
|
|
583
|
+
return content.text;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return content;
|
|
587
|
+
};
|
|
588
|
+
// Safely parse inputSchema - don't let malformed JSON break proxy creation
|
|
589
|
+
let parsedInputSchema;
|
|
590
|
+
if (toolInfo.inputSchema) {
|
|
591
|
+
try {
|
|
592
|
+
parsedInputSchema = JSON.parse(toolInfo.inputSchema);
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
console.warn(`[mesh.llm] Failed to parse inputSchema for tool "${toolInfo.functionName}": ${error instanceof Error ? error.message : String(error)}`);
|
|
596
|
+
parsedInputSchema = undefined;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
// Attach metadata using defineProperties to override read-only 'name'
|
|
600
|
+
Object.defineProperties(proxy, {
|
|
601
|
+
name: {
|
|
602
|
+
value: toolInfo.functionName,
|
|
603
|
+
writable: false,
|
|
604
|
+
configurable: true,
|
|
605
|
+
},
|
|
606
|
+
capability: {
|
|
607
|
+
value: toolInfo.capability,
|
|
608
|
+
writable: false,
|
|
609
|
+
configurable: true,
|
|
610
|
+
},
|
|
611
|
+
description: {
|
|
612
|
+
value: description,
|
|
613
|
+
writable: false,
|
|
614
|
+
configurable: true,
|
|
615
|
+
},
|
|
616
|
+
inputSchema: {
|
|
617
|
+
value: parsedInputSchema,
|
|
618
|
+
writable: false,
|
|
619
|
+
configurable: true,
|
|
620
|
+
},
|
|
621
|
+
endpoint: {
|
|
622
|
+
value: toolInfo.endpoint,
|
|
623
|
+
writable: false,
|
|
624
|
+
configurable: true,
|
|
625
|
+
},
|
|
626
|
+
agentId: {
|
|
627
|
+
value: toolInfo.agentId,
|
|
628
|
+
writable: false,
|
|
629
|
+
configurable: true,
|
|
630
|
+
},
|
|
631
|
+
});
|
|
632
|
+
return proxy;
|
|
633
|
+
}
|
|
634
|
+
//# sourceMappingURL=llm-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-agent.js","sourceRoot":"","sources":["../src/llm-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAerD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAmE5C;;;GAGG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,CAAS;IAExB,YAAY,OAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,uBAAuB,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,KAAa,EACb,QAAsB,EACtB,KAA2B,EAC3B,OAKC;QAED,MAAM,IAAI,GAA4B;YACpC,KAAK;YACL,QAAQ;SACT,CAAC;QAEF,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC5B,CAAC;QAED,IAAI,OAAO,EAAE,eAAe;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC;QACxE,IAAI,OAAO,EAAE,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QAC/E,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