MCPcopy Create free account
hub / github.com/MiniMax-AI/OpenRoom / runConversation

Function runConversation

apps/webuiapps/src/components/ChatPanel/index.tsx:747–1030  ·  view source on GitHub ↗
(history: ChatMessage[], cfg: LLMConfig)

Source from the content-addressed store, hash-verified

745
746 // Core conversation loop
747 const runConversation = async (history: ChatMessage[], cfg: LLMConfig) => {
748 await seedMetaFiles();
749 await loadActionsFromMeta();
750 const hasImageGen = !!imageGenConfigRef.current?.apiKey;
751 const mm = modManagerRef.current;
752 const char = characterRef.current;
753
754 const tools = [
755 getRespondToUserToolDef(),
756 getFinishTargetToolDef(),
757 getListAppsToolDefinition(),
758 getAppActionToolDefinition(),
759 ...getFileToolDefinitions(),
760 ...getMemoryToolDefinitions(),
761 ...(hasImageGen ? getImageGenToolDefinitions() : []),
762 ];
763
764 const currentMemories = memoriesRef.current;
765 const fullMessages: ChatMessage[] = [
766 { role: 'system', content: buildSystemPrompt(char, mm, hasImageGen, currentMemories) },
767 ...history,
768 ];
769
770 let currentMessages = fullMessages;
771 let iterations = 0;
772 const maxIterations = 10;
773 pendingToolCallsRef.current = [];
774
775 while (iterations < maxIterations) {
776 iterations++;
777 const response = await chat(currentMessages, tools, cfg);
778
779 if (response.toolCalls.length === 0) {
780 // No tool calls — fallback plain text (shouldn't happen with respond_to_user requirement)
781 if (response.content) {
782 addMessage({
783 id: String(Date.now()),
784 role: 'assistant',
785 content: response.content,
786 toolCalls:
787 pendingToolCallsRef.current.length > 0 ? [...pendingToolCallsRef.current] : undefined,
788 });
789 setChatHistory((prev) => [...prev, { role: 'assistant', content: response.content }]);
790 pendingToolCallsRef.current = [];
791 }
792 break;
793 }
794
795 // Has tool calls
796 const assistantMsg: ChatMessage = {
797 role: 'assistant',
798 content: response.content,
799 tool_calls: response.toolCalls,
800 };
801 currentMessages = [...currentMessages, assistantMsg];
802
803 // Execute each tool call
804 for (const tc of response.toolCalls) {

Callers 1

ChatPanelFunction · 0.85

Calls 15

seedMetaFilesFunction · 0.90
loadActionsFromMetaFunction · 0.90
getFileToolDefinitionsFunction · 0.90
getMemoryToolDefinitionsFunction · 0.90
chatFunction · 0.90
clearEmotionVideoCacheFunction · 0.90
saveModCollectionFunction · 0.90
executeListAppsFunction · 0.90
isFileToolFunction · 0.90

Tested by

no test coverage detected