sync: Agent Architecture Overhaul - AI SDK 6 + workflow optimization
Synced from private repo (feature/ai-sdk-6-upgrade): - Upgrade AI SDK 5 → 6 (packages + API changes) - Add sqliteQuery tool for flexible read-only queries - New WorkflowExecutor with workflow-specific tools - 83% token reduction for workflow execution - Remove mini-rah dead code (simplified architecture) - Add context management usage endpoint - Fix Connect workflow instructions - Clickable node references in workflow UI Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
f9271aeeb4
commit
3f0426ecf4
@@ -1,5 +1,5 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import { streamText, convertToCoreMessages } from 'ai';
|
||||
import { streamText, convertToModelMessages } from 'ai';
|
||||
import { createAnthropic } from '@ai-sdk/anthropic';
|
||||
import { createOpenAI } from '@ai-sdk/openai';
|
||||
import { getHelperTools, getDefaultToolNamesForRole } from '@/tools/infrastructure/registry';
|
||||
@@ -265,7 +265,7 @@ export async function POST(request: NextRequest) {
|
||||
} : {})
|
||||
}));
|
||||
|
||||
const coreMessages = convertToCoreMessages(sanitizedMessages);
|
||||
const coreMessages = await convertToModelMessages(sanitizedMessages);
|
||||
const allMessages = [...systemMessages, ...coreMessages];
|
||||
|
||||
// Debug logging (can be removed in production)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import { getSQLiteClient } from '@/services/database/sqlite-client';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const sessionId = request.nextUrl.searchParams.get('sessionId');
|
||||
|
||||
if (!sessionId) {
|
||||
return Response.json({ inputTokens: 0 });
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlite = getSQLiteClient();
|
||||
const row = sqlite.prepare(`
|
||||
SELECT json_extract(metadata, '$.input_tokens') as input_tokens
|
||||
FROM chats
|
||||
WHERE thread_id LIKE ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
`).get(`%${sessionId}%`) as { input_tokens: number | null } | undefined;
|
||||
|
||||
return Response.json({
|
||||
inputTokens: row?.input_tokens ?? 0
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Usage fetch error:', error);
|
||||
return Response.json({ inputTokens: 0 });
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { WorkflowRegistry } from '@/services/workflows/registry';
|
||||
import { getSQLiteClient } from '@/services/database/sqlite-client';
|
||||
import { AgentDelegationService } from '@/services/agents/delegation';
|
||||
import { WiseRAHExecutor } from '@/services/agents/wiseRAHExecutor';
|
||||
import { WorkflowExecutor } from '@/services/agents/workflowExecutor';
|
||||
import { getAutoContextSummaries } from '@/services/context/autoContext';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
@@ -112,12 +112,12 @@ ${nodeId ? `Target Node ID: ${nodeId}` : 'No specific node targeted (general wor
|
||||
task,
|
||||
context: contextLines,
|
||||
expectedOutcome: workflow.expectedOutcome,
|
||||
agentType: 'wise-rah',
|
||||
agentType: 'workflow',
|
||||
supabaseToken: null,
|
||||
});
|
||||
|
||||
// Fire-and-forget execution
|
||||
void WiseRAHExecutor.execute({
|
||||
void WorkflowExecutor.execute({
|
||||
sessionId: delegation.sessionId,
|
||||
task,
|
||||
context: contextLines,
|
||||
|
||||
Reference in New Issue
Block a user