alibaba/spring-ai-alibaba · error · NoSuchElementException

Graph not found:

Error message

Graph not found: 

What it means

AbstractGraphLoader.loadGraph(String name) throws NoSuchElementException when the name passes validation but no CompiledGraph is registered under that key in getGraphMap(). It signals an unknown/stale graph name, analogous to a map miss. The graph may never have been loaded or may have been unloaded since the name was obtained.

Solutions

  1. Enumerate available graph names (List.copyOf(getGraphMap().keySet()) is exposed by the loader) and pick an exact match
  2. Correct the graph name spelling/case in the caller
  3. Confirm the graph's YAML file exists in the watched config folder and was loaded successfully
  4. If configs were reloaded, refresh the client's cached graph name list before retrying

Example fix

// before
CompiledGraph g = loader.loadGraph(userSuppliedName);
// after
Set<String> available = loader.getGraphMap().keySet();
if (userSuppliedName == null || !available.contains(userSuppliedName.trim())) {
    throw new IllegalArgumentException("Unknown graph; available: " + available);
}
CompiledGraph g = loader.loadGraph(userSuppliedName.trim());
Defensive patterns

Strategy: try-catch

Validate before calling

if (graphName == null || !loader.getGraphMap().keySet().contains(graphName.trim())) {
    throw new IllegalArgumentException("Unknown graph '" + graphName + "'; available: " + loader.getGraphMap().keySet());
}

Try / catch

try {
    return loader.loadGraph(graphName);
} catch (NoSuchElementException e) {
    logger.warn("Graph '{}' not found; available: {}", graphName, loader.getGraphMap().keySet());
    return ResponseEntity.status(404).body("Graph not found");
}

Prevention

When it happens

Trigger: Calling loadGraph("myGraph") when "myGraph" is not a key in the graph map — wrong name, unloaded config, case mismatch, or the graph file was deleted after the client cached the name.

Common situations: Requesting a graph by name taken from a stale bookmark/API response; YAML graph definition removed from the watched config folder; typo between the registered graph name and the requested one; hot-reload removed the graph after a config edit.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/7075e6ae976c84ff. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/loader/AbstractGraphLoader.java:98

			}
		}
		return result;
	}

	@Override
	@Nonnull
	public List<String> listGraphs() {
		return List.copyOf(getGraphMap().keySet());
	}

	@Override
	public CompiledGraph loadGraph(String name) {
		if (name == null || name.trim().isEmpty()) {
			throw new IllegalArgumentException("Graph name cannot be null or empty");
		}
		CompiledGraph graph = getGraphMap().get(name);
		if (graph == null) {
			throw new NoSuchElementException("Graph not found: " + name);
		}
		return graph;
	}
}

View on GitHub (pinned to f82da0b50f)