@lota-sdk/core 0.1.26 → 0.1.27
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lota-sdk/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@chat-adapter/slack": "^4.23.0",
|
|
33
33
|
"@chat-adapter/state-ioredis": "^4.23.0",
|
|
34
34
|
"@logtape/logtape": "^2.0.5",
|
|
35
|
-
"@lota-sdk/shared": "0.1.
|
|
35
|
+
"@lota-sdk/shared": "0.1.27",
|
|
36
36
|
"@mendable/firecrawl-js": "^4.18.0",
|
|
37
37
|
"@surrealdb/node": "^3.0.3",
|
|
38
38
|
"ai": "^6.0.141",
|
|
@@ -116,30 +116,68 @@ function resolveDelegatedAgentTemperature(definition: {
|
|
|
116
116
|
return definition.temperature ?? 0.2
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
function extractToolResultText(messages: ModelMessage[]): string {
|
|
120
|
+
const chunks: string[] = []
|
|
121
|
+
for (const message of messages) {
|
|
122
|
+
if (message.role === 'tool') {
|
|
123
|
+
for (const part of message.content) {
|
|
124
|
+
if ('result' in part && typeof part.result === 'string' && part.result.length > 50) {
|
|
125
|
+
chunks.push(part.result.slice(0, 2000))
|
|
126
|
+
} else if ('result' in part && typeof part.result === 'object' && part.result !== null) {
|
|
127
|
+
const serialized = JSON.stringify(part.result)
|
|
128
|
+
if (serialized.length > 50) {
|
|
129
|
+
chunks.push(serialized.slice(0, 2000))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return chunks.join('\n\n---\n\n')
|
|
136
|
+
}
|
|
137
|
+
|
|
119
138
|
async function generateSubstantiveDelegatedAgentResult(params: {
|
|
120
139
|
label: string
|
|
121
140
|
task: string
|
|
122
141
|
abortSignal?: AbortSignal
|
|
123
142
|
createAgent: () => ToolLoopAgent<never, ToolSet>
|
|
124
143
|
}): Promise<string> {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
const agent = params.createAgent()
|
|
145
|
+
const result = await agent.generate({ prompt: params.task, abortSignal: params.abortSignal })
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
return assertSubstantiveAgentResult(result.text, params.label)
|
|
149
|
+
} catch (firstError) {
|
|
150
|
+
aiLogger.warn`Delegated agent returned non-substantive result, attempting follow-up synthesis (label=${params.label}, textLength=${result.text.length})`
|
|
151
|
+
|
|
152
|
+
if (params.abortSignal?.aborted) {
|
|
153
|
+
throw firstError
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Try a follow-up: feed the agent's tool results back as context and ask for synthesis
|
|
157
|
+
const toolContext = extractToolResultText(result.messages)
|
|
158
|
+
if (toolContext.length > 100) {
|
|
159
|
+
const followUpPrompt = [
|
|
160
|
+
params.task,
|
|
161
|
+
'',
|
|
162
|
+
'Here is the research data you already gathered:',
|
|
163
|
+
'',
|
|
164
|
+
toolContext.slice(0, 8000),
|
|
165
|
+
'',
|
|
166
|
+
NON_SUBSTANTIVE_AGENT_RESULT_RETRY_PROMPT,
|
|
167
|
+
].join('\n')
|
|
168
|
+
|
|
169
|
+
const followUp = await params.createAgent().generate({ prompt: followUpPrompt, abortSignal: params.abortSignal })
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
return assertSubstantiveAgentResult(followUp.text, params.label)
|
|
173
|
+
} catch (secondError) {
|
|
174
|
+
aiLogger.error`Delegated agent follow-up also non-substantive (label=${params.label}, textLength=${followUp.text.length}, textPreview=${followUp.text.slice(0, 200)})`
|
|
175
|
+
throw secondError
|
|
138
176
|
}
|
|
139
177
|
}
|
|
140
|
-
}
|
|
141
178
|
|
|
142
|
-
|
|
179
|
+
throw firstError
|
|
180
|
+
}
|
|
143
181
|
}
|
|
144
182
|
|
|
145
183
|
export function createDelegatedAgentTool(definition: DelegatedAgentDefinition): ToolDefinition<void> {
|