mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-01 12:27:41 +08:00
agent tools do something now
This commit is contained in:
parent
0d4b6a71fc
commit
90db570e30
@ -289,6 +289,7 @@ export class ContextualThinkingTool {
|
||||
getThinkingSummary(thinkingId: string): string {
|
||||
const process = this.getThinkingProcess(thinkingId);
|
||||
if (!process) {
|
||||
log.error(`No thinking process found for id: ${thinkingId}`);
|
||||
return "No thinking process available.";
|
||||
}
|
||||
|
||||
@ -301,6 +302,8 @@ export class ContextualThinkingTool {
|
||||
const evidence = process.steps.filter(s => s.type === 'evidence');
|
||||
const conclusions = process.steps.filter(s => s.type === 'conclusion');
|
||||
|
||||
log.info(`Generating thinking summary with: ${observations.length} observations, ${questions.length} questions, ${hypotheses.length} hypotheses, ${evidence.length} evidence, ${conclusions.length} conclusions`);
|
||||
|
||||
// Add observations
|
||||
if (observations.length > 0) {
|
||||
summary += "### Observations:\n";
|
||||
@ -346,6 +349,7 @@ export class ContextualThinkingTool {
|
||||
summary += "\n";
|
||||
}
|
||||
|
||||
log.info(`Generated thinking summary with ${summary.length} characters`);
|
||||
return summary;
|
||||
}
|
||||
|
||||
|
@ -443,11 +443,32 @@ export class NoteNavigatorTool {
|
||||
try {
|
||||
log.info(`Getting note structure for note ${noteId}`);
|
||||
|
||||
// Special handling for 'root' or other special notes
|
||||
if (noteId === 'root' || !noteId) {
|
||||
log.info('Using root as the special note for structure');
|
||||
return {
|
||||
noteId: 'root',
|
||||
title: 'Root',
|
||||
type: 'root',
|
||||
childCount: 0, // We don't know how many direct children root has
|
||||
attributes: [],
|
||||
parentPath: []
|
||||
};
|
||||
}
|
||||
|
||||
// Get the note from becca
|
||||
const note = becca.notes[noteId];
|
||||
|
||||
if (!note) {
|
||||
throw new Error(`Note ${noteId} not found`);
|
||||
log.error(`Note ${noteId} not found in becca.notes`);
|
||||
return {
|
||||
noteId,
|
||||
title: 'Unknown',
|
||||
type: 'unknown',
|
||||
childCount: 0,
|
||||
attributes: [],
|
||||
parentPath: []
|
||||
};
|
||||
}
|
||||
|
||||
// Get child notes count
|
||||
|
@ -44,6 +44,16 @@ export class QueryDecompositionTool {
|
||||
// Log the decomposition attempt for tracking
|
||||
log.info(`Decomposing query: "${query.substring(0, 100)}..."`);
|
||||
|
||||
if (!query || query.trim().length === 0) {
|
||||
log.info("Query decomposition called with empty query");
|
||||
return {
|
||||
originalQuery: query,
|
||||
subQueries: [],
|
||||
status: 'pending',
|
||||
complexity: 0
|
||||
};
|
||||
}
|
||||
|
||||
// Assess query complexity to determine if decomposition is needed
|
||||
const complexity = this.assessQueryComplexity(query);
|
||||
log.info(`Query complexity assessment: ${complexity}/10`);
|
||||
@ -52,14 +62,25 @@ export class QueryDecompositionTool {
|
||||
// Use a lower threshold (2 instead of 3) to decompose more queries
|
||||
if (complexity < 2) {
|
||||
log.info(`Query is simple (complexity ${complexity}), returning as single sub-query`);
|
||||
return {
|
||||
originalQuery: query,
|
||||
subQueries: [{
|
||||
|
||||
const mainSubQuery = {
|
||||
id: this.generateSubQueryId(),
|
||||
text: query,
|
||||
reason: 'Direct question that can be answered without decomposition',
|
||||
isAnswered: false
|
||||
}],
|
||||
};
|
||||
|
||||
// Still add a generic exploration query to get some related content
|
||||
const genericQuery = {
|
||||
id: this.generateSubQueryId(),
|
||||
text: `Information related to ${query}`,
|
||||
reason: "Generic exploration to find related content",
|
||||
isAnswered: false
|
||||
};
|
||||
|
||||
return {
|
||||
originalQuery: query,
|
||||
subQueries: [mainSubQuery, genericQuery],
|
||||
status: 'pending',
|
||||
complexity
|
||||
};
|
||||
|
@ -147,10 +147,13 @@ export class ContextService {
|
||||
|
||||
// Step 4: Add agent tools context with thinking process if requested
|
||||
let enhancedContext = context;
|
||||
if (contextNoteId) {
|
||||
try {
|
||||
// Pass 'root' as the default noteId when no specific note is selected
|
||||
const noteIdToUse = contextNoteId || 'root';
|
||||
log.info(`Calling getAgentToolsContext with noteId=${noteIdToUse}, showThinking=${showThinking}`);
|
||||
|
||||
const agentContext = await this.getAgentToolsContext(
|
||||
contextNoteId,
|
||||
noteIdToUse,
|
||||
userQuestion,
|
||||
showThinking,
|
||||
relevantNotes
|
||||
@ -163,7 +166,6 @@ export class ContextService {
|
||||
log.error(`Error getting agent tools context: ${error}`);
|
||||
// Continue with the basic context
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
context: enhancedContext,
|
||||
@ -402,8 +404,13 @@ export class ContextService {
|
||||
|
||||
// Add thinking process if requested
|
||||
if (showThinking) {
|
||||
log.info(`Including thinking process in context (showThinking=true)`);
|
||||
agentContext += `\n## Reasoning Process\n`;
|
||||
agentContext += contextualThinkingTool.getThinkingSummary(thinkingId);
|
||||
const thinkingSummary = contextualThinkingTool.getThinkingSummary(thinkingId);
|
||||
log.info(`Thinking summary length: ${thinkingSummary.length} characters`);
|
||||
agentContext += thinkingSummary;
|
||||
} else {
|
||||
log.info(`Skipping thinking process in context (showThinking=false)`);
|
||||
}
|
||||
|
||||
// Log stats about the context
|
||||
|
Loading…
x
Reference in New Issue
Block a user