Skip to content

Commit 6d3b0ff

Browse files
committed
feat: Update Wizard API to include conversation history and enhance logging for better context and debugging
1 parent fa5ff67 commit 6d3b0ff

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

bridge-daemon-legacy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ app.post('/api/ai/chat', async (req, res) => {
21512151
// New Wizard endpoint - simplified single-LLM loop
21522152
app.post('/api/wizard', async (req, res) => {
21532153
try {
2154-
const { message, graphState, config } = req.body || {};
2154+
const { message, graphState, conversationHistory, config } = req.body || {};
21552155
if (!message) {
21562156
return res.status(400).json({ error: 'Message is required' });
21572157
}
@@ -2174,7 +2174,8 @@ app.post('/api/wizard', async (req, res) => {
21742174
model: apiConfig.model,
21752175
temperature: apiConfig.settings?.temperature,
21762176
maxTokens: apiConfig.settings?.max_tokens,
2177-
cid: config.cid || `wizard-${Date.now()}`
2177+
cid: config.cid || `wizard-${Date.now()}`,
2178+
conversationHistory: conversationHistory || [] // Pass conversation history
21782179
};
21792180

21802181
try {

src/components/panel/views/LeftAIView.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,11 @@ const LeftAIView = ({ compact = false, activeGraphId, graphsMap, edgesMap }) =>
569569
activeGraphId: activeGraphId || null
570570
};
571571

572-
console.log('[Wizard] Starting request to /api/wizard', { apiKey: apiKey ? 'present' : 'missing', apiConfig });
572+
console.log('[Wizard] Starting request to /api/wizard', {
573+
apiKey: apiKey ? 'present' : 'missing',
574+
apiConfig,
575+
historyLength: recentMessages.length
576+
});
573577

574578
// Use new Wizard endpoint with SSE streaming
575579
const response = await bridgeFetch('/api/wizard', {
@@ -578,6 +582,7 @@ const LeftAIView = ({ compact = false, activeGraphId, graphsMap, edgesMap }) =>
578582
body: JSON.stringify({
579583
message: question,
580584
graphState,
585+
conversationHistory: recentMessages, // Include conversation history for context
581586
config: {
582587
cid: `wizard-${Date.now()}`,
583588
apiConfig: apiConfig ? {

src/wizard/AgentLoop.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,20 @@ export async function* runAgent(userMessage, graphState, config = {}, ensureSche
6161
.replace('{nodeList}', contextStr.includes('Existing Things') ? contextStr.split('Existing Things:')[1]?.split('\n')[0] || '' : '')
6262
.replace('{edgeList}', ''); // Can be enhanced later
6363

64+
// Build messages array with conversation history
65+
const conversationHistory = config.conversationHistory || [];
66+
const historyMessages = conversationHistory
67+
.filter(msg => msg.content && msg.content.trim()) // Filter out empty messages
68+
.map(msg => ({
69+
role: msg.role === 'user' ? 'user' : 'assistant',
70+
content: msg.content
71+
}));
72+
73+
console.log('[AgentLoop] Conversation history:', historyMessages.length, 'messages');
74+
6475
const messages = [
6576
{ role: 'system', content: fullSystemPrompt + '\n\n' + contextStr },
77+
...historyMessages, // Include prior conversation for context
6678
{ role: 'user', content: userMessage }
6779
];
6880

0 commit comments

Comments
 (0)