Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Error buildAgentGraph - Cannot read properties of undefined (reading 'name') #3939

Open
sdadesky opened this issue Jan 29, 2025 · 1 comment

Comments

@sdadesky
Copy link

Describe the bug
This flow is not running I am using Leons video to build a sequential agent

To Reproduce
Load the below json file to observe the flow

Image

test_sequential_2 Agents.json

  1. See error

2025-01-29 00:49:58 [INFO]: Starting Flowise...
2025-01-29 00:49:58 [INFO]: 📦 [server]: Data Source is initializing...
2025-01-29 00:50:10 [INFO]: 📦 [server]: Data Source has been initialized!
2025-01-29 00:50:10 [INFO]: ⚡️ [server]: Flowise Server is listening at :3000
2025-01-29 00:50:48 [INFO]: ⬆️ POST /api/v1/node-load-method/chatOpenAI
2025-01-29 00:51:21 [INFO]: ⬆️ POST /api/v1/internal-prediction/db363059-f2a0-477c-85fc-5d7bb8f276b4
2025-01-29 00:51:21 [ERROR]: [server]: Error: Cannot read properties of undefined (reading 'name')
TypeError: Cannot read properties of undefined (reading 'name')
at buildAgentGraph (/usr/local/lib/node_modules/flowise/dist/utils/buildAgentGraph.js:142:90)
at async utilBuildAgentResponse (/usr/local/lib/node_modules/flowise/dist/utils/buildChatflow.js:443:31)
at async utilBuildChatflow (/usr/local/lib/node_modules/flowise/dist/utils/buildChatflow.js:196:20)
at async createAndStreamInternalPrediction (/usr/local/lib/node_modules/flowise/dist/controllers/internal-predictions/index.js:33:29)

Expected behavior
The agent node should use the serp_api to fetch relative info about a given topic and produce a concise post about the topic.

Screenshots
See attached image

Flow
Has been added in attached files

Setup

  • Installation docker
  • Flowise Version flowise/2.2.2 linux-x64 node-v20.18.1
  • OS:Ubuntu Linux digital ocean droplet
  • Browser [ Brave]

Additional context
I looked to another person who had similar problem but solution offered there not useful:
#3772

This flow has not yet incorporated "loopto" node so answer not relevant.

@sdadesky
Copy link
Author

sdadesky commented Feb 2, 2025

For what it is worth, after receiving no reply I decided to dust off my inexistent node.js skills , and with the help of chatgpt and deepseek resolved multiple issues.

This primary fix involved this:
//modified by Serge
for (const node of [...workerNodes, ...supervisorNodes, ...seqAgentNodes]) {
if (!node.data.instance) {
node.data.instance = {}; // Ensure instance exists
}
if (!node.data.instance.name) {
node.data.instance.name = "dummynode"; // Assign default value
}

       if (!Object.prototype.hasOwnProperty.call(mapNameToLabel, node.data.instance.name)) {
              mapNameToLabel[node.data.instance.name] = {
                       label: node.data.instance.label || "No Label", // Default label if undefined
                        nodeName: node.data.name || "dummyname" // Default node name if undefined
              };
       }
    }

and

                   for (const agentName of Object.keys(output)) {
                        // changes made  below by Serge
                        if (!mapNameToLabel[agentName]) {
                            logger_1.default.warn(`Skipping undefined agent: ${agentName}`);
                            continue;
                        }
                        const nodeId = output[agentName]?.messages
                            ? output[agentName].messages[output[agentName].messages.length - 1]?.additional_kwargs?.nodeId
                            : '';
                        const usedTools = output[agentName].messages
                            ? output[agentName].messages.map(msg => msg.additional_kwargs.usedTools)
                            : [];

and

let prependMessages = [];
    // Only append in the first message changed by Serge missing if statement  for else.
    if (prependHistoryMessages.length === chatHistory.length) {
        for (const message of prependHistoryMessages) {
            if (message.role === 'userMessage' || message.type === 'userMessage') { 
                prependMessages.push(new messages_1.HumanMessage({
                    content: message.message || message.content || ''
                }));
            } else { // ✅ Else correctly attached to the if
                prependMessages.push(new messages_1.AIMessage({
                    content: message.message || message.content || ''
                }));
            }
        }
    }

and

                        //next 2 lines for debugging
                        console.log('DEBUG - mapNameToLabel:', mapNameToLabel[agentName]);
                        console.log('DEBUG - agentName:', agentName);
                        // MODIFIED VERSION STARTS HERE
                        const reasoning = {
                              agentName: mapNameToLabel[agentName]?.label || 'Unknown Agent', // Added ? and default
                              messages: messages || [],
                              next: output[agentName]?.next || '',
                              instructions: output[agentName]?.instructions || '',
                              usedTools: (0, lodash_1.flatten)(usedTools).filter(t => t) || [],
                              sourceDocuments: (0, lodash_1.flatten)(sourceDocuments).filter(d => d) || [],
                              artifacts: (0, lodash_1.flatten)(artifacts).filter(a => a) || [],
                              state: (0, lodash_1.omit)(output[agentName], ['messages']) || {},
                              nodeName: isSequential ? mapNameToLabel[agentName]?.nodeName : undefined,
                              nodeId: nodeId || ''
                        };
                        // MODIFIED VERSION ENDS HERE

FWIW. use at your own risk and peril. It fixed all my issues (so far) But more may follow. I've attached my modified buildAgentGraph.js file as a text file since it won't allow uploading of js files. I hope it can help others. Make sure you backup existing one before deploying this.

Here's how I made this not be overwritten every time new version of flowise is fetched:

Start the container (if not already running)

docker run -dit --name temp-flowise my-modified-flowise sleep infinity

Copy the modified file from the subdirectory

docker cp ./flowise_overrides/buildAgentGraph.js temp-flowise:/usr/local/lib/node_modules/flowise/dist/utils/buildAgentGraph.js
docker stop $(docker ps -aq)
docker-compose down
docker-compose up -d

and FIRST make change to your docker-compose.yml file to point to new ./flowise_overrides/buildAgentGraph.js file:
volumes:
#other directives here
- ./flowise_overrides/buildAgentGraph.js:/usr/local/lib/node_modules/flowise/dist/utils/buildAgentGraph.js

Hopefully future versions of flowise will correct these bugs and I can remove this statement from my docker-compose.yml file.

buildAgentGraph.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant