@game_ryo/lsji 1.2.3 → 1.2.5
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 +1 -1
- package/src/index.js +1 -1
- package/src/llm/llm-agent.js +24 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/llm/llm-agent.js
CHANGED
|
@@ -184,6 +184,7 @@ export class LLMAgent {
|
|
|
184
184
|
maxTokens: 4096,
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
|
|
187
188
|
// Record token usage
|
|
188
189
|
if (this.memory.episodic) {
|
|
189
190
|
this.memory.episodic.recordTokens(response.usage?.totalTokens || 0);
|
|
@@ -270,15 +271,34 @@ export class LLMAgent {
|
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
// No tool calls - check if final answer
|
|
273
|
-
|
|
274
|
+
// Don't treat empty/whitespace-only content as final answer
|
|
275
|
+
const hasContent = response.content && response.content.trim().length > 0;
|
|
276
|
+
const isReActFormat = response.content && (response.content.includes('THOUGHT:') || response.content.includes('ACTION:'));
|
|
277
|
+
const isFinalAnswer = hasContent && !isReActFormat;
|
|
278
|
+
|
|
279
|
+
if (isFinalAnswer) {
|
|
274
280
|
finalAnswer = response.content;
|
|
275
281
|
break;
|
|
276
282
|
}
|
|
277
283
|
|
|
278
|
-
// Parse ReAct format if present
|
|
279
|
-
if (
|
|
284
|
+
// Parse ReAct format if present (THOUGHT: or ACTION:)
|
|
285
|
+
if (isReActFormat) {
|
|
280
286
|
// This is a ReAct formatted response without tool calls
|
|
281
|
-
//
|
|
287
|
+
// Check if it contains a final answer indicator
|
|
288
|
+
if (response.content.includes('FINAL ANSWER:') || response.content.includes('Final Answer:')) {
|
|
289
|
+
// Extract the final answer part
|
|
290
|
+
const finalAnswerMatch = response.content.match(/(?:FINAL ANSWER:|Final Answer:)\s*(.+)/i);
|
|
291
|
+
if (finalAnswerMatch) {
|
|
292
|
+
finalAnswer = finalAnswerMatch[1].trim();
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Continue to next iteration for more ReAct steps
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Skip empty responses
|
|
301
|
+
if (!hasContent) {
|
|
282
302
|
continue;
|
|
283
303
|
}
|
|
284
304
|
|