Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/frontend/src/hooks/useAgentGraph.tsx (TypeScript)

Code before:
      };
    });

    const links = edges.map((edge) => {
      let sourceName = edge.sourceHandle || "";
      if (sourceName.toLowerCase() === "tools") {
        const sinkNode = nodes.find((node) => node.id === edge.target);

        const sinkNodeName = sinkNode
          ? sinkNode.data.block_id === "e189baac-8c20-45a1-94a7-55177ea42565" // AgentExecutorBlock ID
            ? sinkNode.data.hardcodedValues?.graph_id
              ? availableFlows
                  .find(
                    (flow) =>
                      flow.id === sinkNode.data.hardcodedValues.graph_id,
                  )
                  ?.name?.toLowerCase()
                  .replace(/ /g, "_") || "agentexecutorblock"
              : "agentexecutorblock"
            : sinkNode.data.title.toLowerCase().replace(/ /g, "_").split("_")[0]
          : "";

        sourceName =
          `tools_^_${sinkNodeName}_${edge.targetHandle || ""}`.toLowerCase();
      }
      return {
        source_id: edge.source,
        sink_id: edge.target,
        source_name: sourceName,
        sink_name: edge.targetHandle || "",
      };
    });

    const payload = {
      id: savedAgent?.id!,
      name: agentName || `New Agent ${new Date().toISOString()}`,
      description: agentDescription || "",
      nodes: formattedNodes,
      links: links,
    };

    // To avoid saving the same graph, we compare the payload with the saved agent.
    // Differences in IDs are ignored.
    const comparedPayload = {
      ...(({ id, ...rest }) => rest)(payload),
      nodes: payload.nodes.map(
        ({ id, data, input_nodes, output_nodes, ...rest }) => rest,
      ),
      links: payload.links.map(({ source_id, sink_id, ...rest }) => rest),
    };
    const comparedSavedAgent = {

Review comment (bug):
What the split is for ?
Will this cause any risk of non smart decision block code to be broken due to the split ?

Code after:
      };
    });

    const links = edges.map((edge) => {
      let sourceName = edge.sourceHandle || "";
      const sourceNode = nodes.find((node) => node.id === edge.source);

      // Special case for SmartDecisionMakerBlock
      if (
        sourceNode?.data.block_id === "3b191d9f-356f-482d-8238-ba04b6d18381" &&
        sourceName.toLowerCase() === "tools"
      ) {
        const sinkNode = nodes.find((node) => node.id === edge.target);

        const sinkNodeName = sinkNode
          ? sinkNode.data.block_id === "e189baac-8c20-45a1-94a7-55177ea42565" // AgentExecutorBlock ID
            ? sinkNode.data.hardcodedValues?.graph_id
              ? availableFlows
                  .find(
                    (flow) =>
                      flow.id === sinkNode.data.hardcodedValues.graph_id,
                  )
                  ?.name?.toLowerCase()
                  .replace(/ /g, "_") || "agentexecutorblock"
              : "agentexecutorblock"
            : sinkNode.data.title.toLowerCase().replace(/ /g, "_").split("_")[0]
          : "";

        sourceName =
          `tools_^_${sinkNodeName}_${edge.targetHandle || ""}`.toLowerCase();
      }
      return {
        source_id: edge.source,
        sink_id: edge.target,
        source_name: sourceName,
        sink_name: edge.targetHandle || "",
      };
    });

    const payload = {
      id: savedAgent?.id!,
      name: agentName || `New Agent ${new Date().toISOString()}`,
      description: agentDescription || "",
      nodes: formattedNodes,
      links: links,
    };

    // To avoid saving the same graph, we compare the payload with the saved agent.
    // Differences in IDs are ignored.
    const comparedPayload = {
      ...(({ id, ...rest }) => rest)(payload),