langgraph_used

This commit is contained in:
lusixing
2026-02-03 21:37:41 -08:00
parent 0aab9a838b
commit c1ce804d14
8 changed files with 613 additions and 5 deletions

View File

@@ -31,6 +31,8 @@ import * as ImagePicker from 'expo-image-picker';
import { AIRole } from '../types';
import { colors, typography, spacing, borderRadius, shadows } from '../theme/colors';
import { aiService, AIMessage } from '../services/ai.service';
import { langGraphService } from '../services/langgraph.service';
import { HumanMessage, AIMessage as LangChainAIMessage, SystemMessage } from "@langchain/core/messages";
import { assetsService } from '../services/assets.service';
import { useAuth } from '../context/AuthContext';
import { AI_CONFIG, getVaultStorageKeys } from '../config';
@@ -280,8 +282,23 @@ export default function FlowScreen() {
setMessages(prev => [...prev, userMsg]);
try {
// Call AI proxy with selected role's system prompt
const aiResponse = await aiService.sendMessage(userMessage, token, selectedRole?.systemPrompt || '');
// 1. Convert current messages history to LangChain format
const history: (HumanMessage | LangChainAIMessage | SystemMessage)[] = messages.map(msg => {
if (msg.role === 'user') return new HumanMessage(msg.content);
return new LangChainAIMessage(msg.content);
});
// 2. Add system prompt
const systemPrompt = new SystemMessage(selectedRole?.systemPrompt || '');
// 3. Add current new message
const currentMsg = new HumanMessage(userMessage);
// 4. Combine all messages for LangGraph processing
const fullMessages = [systemPrompt, ...history, currentMsg];
// 5. Execute via LangGraph service (handles token limits and context)
const aiResponse = await langGraphService.execute(fullMessages, token);
// Add AI response
const aiMsg: ChatMessage = {