The Iterative Graph Generator (IGG) is a specialized tool designed for autonomous agents to construct knowledge graphs incrementally. Unlike traditional “text-to-graph” batch processes, IGG operates on a Observe-Reason-Act loop. It maintains an in-memory graph state, allowing the agent to query the existing structure before deciding on the next addition.
This tool is built for scenarios where the graph structure is complex, recursive, or requires logical deduction (e.g., mapping code dependencies, argument mapping, or complex project planning).
The configuration has been restructured to be strictly typed, preventing agent “hallucinations” regarding node types and ensuring resource bounds.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"session_id": "uuid-1234",
"goal_prompt": "Map out the dependencies of the authentication module based on the provided source files.",
"context_data": "...", // The raw text/code/data the agent is analyzing
"config": {
"max_iterations": 20,
"constraints": {
"max_nodes": 50,
"max_edges": 100,
"allow_self_loops": false
},
"schema": {
"node_types": ["Class", "Interface", "Method", "DatabaseTable"],
"edge_types": ["CALLS", "IMPLEMENTS", "READS_FROM", "WRITES_TO"],
"required_attributes": {
"Class": ["name", "package"],
"Method": ["name", "signature"]
}
}
}
}
The tool executes a state machine loop.
TinkerGraph instance.schema definitions into a validation layer.seed_data if the graph should start partially populated.The loop continues until max_iterations is reached, constraints are met, or the Agent signals completion.
The tool generates a context-aware snapshot of the graph to send to the Agent (LLM).
The tool invokes the Agent (LLM) with:
goal_promptcontext_datacurrent_graph_stateschema_definitionsAgent Output Expectation: The Agent must return a structured JSON action list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"reasoning": "I have added the AuthController. Now I need to add the AuthService it depends on.",
"actions": [
{
"type": "ADD_NODE",
"label": "Class",
"properties": { "name": "AuthService", "package": "com.app.auth" }
},
{
"type": "ADD_EDGE",
"label": "CALLS",
"from": { "name": "AuthController" }, // Reference by unique property
"to": { "name": "AuthService" }
}
]
}
The IGG tool processes the actions list:
AuthService match node_types? Are required attributes present?max_nodes?g.addV(...) or g.addE(...).TinkerGraph object to the requested format (GraphML, JSON, or push to a persistent Neo4j instance).1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class GraphGenerationService {
private final Graph graph;
private final GraphTraversalSource g;
private final GraphSchema schema;
private final Constraints constraints;
public GraphGenerationService(GraphConfig config) {
this.graph = TinkerGraph.open();
this.g = graph.traversal();
this.schema = config.getSchema();
this.constraints = config.getConstraints();
}
public GenerationResult executeLoop(AgentInterface agent, String context) {
int iteration = 0;
while (iteration < constraints.getMaxIterations()) {
// 1. Serialize State
String graphView = GraphSerializer.toMarkdown(g);
// 2. Call Agent
AgentResponse response = agent.decide(context, graphView, schema);
// 3. Stop condition
if (response.isFinished()) break;
// 4. Apply Actions
applyActions(response.getActions());
// 5. Check Constraints
if (checkLimitsReached()) break;
iteration++;
}
return new GenerationResult(graph);
}
private void applyActions(List<GraphAction> actions) {
// Implementation of addV/addE with schema validation
// Uses try-catch to ensure robustness
}
}
The tool must enforce the schema strictly to ensure the resulting graph is queryable by other tools in the platform.
node_type not in the config, the action is rejected, and an error feedback loop is provided to the agent in the next iteration.Since this is an autonomous process, detailed logging is required for debugging “why” the graph looks the way it does.
Iteration N:
Graph State: (Summary)Agent Reasoning: “…”Actions Taken: […]Errors: [“Node ‘X’ not found for edge creation”]Graph interface so TinkerGraph can be swapped for JanusGraph for graphs exceeding memory limits.