title: CloudSlash - Graph Traversal Reference description: DEVI's AI agent doesn't query the graph with SQL. It traverses it generatively: building new paths as it reasons about topology. Translating unstructured hum...
Graph Traversal¶
DEVI's AI agent doesn't query the graph with SQL. It traverses it generatively: building new paths as it reasons about topology.
Note
Translating unstructured human intent into deterministic infrastructure queries requires bridging fuzzy language models with rigid programmatic schemas. We document the techniques used to anchor the AI Copilot against the local Universal Graph context within pkg/ai/.
Context Window¶
Constraint
Standard inference limits (e.g., 128,000 tokens) aren't enough to ingest a .tfstate dump from a 10,000-node architecture. Injecting the raw JSON of the Devi graph into the prompt causes extreme context fragmentation, degrading the model's topological reasoning.
We solve this with a constrained Retrieval-Augmented Generation (RAG) loop that runs strictly against the local BadgerDB index.
Schema-Aware Function Calling¶
Instead of injecting the graph into the prompt, the daemon exposes the API structure as executable functions using the provider's native function-calling constraints (e.g., Gemini's Tools parameter):
// pkg/ai/tools.go
var GraphSearchTool = &llm.Tool{
Name: "query_graph",
Description: "Search the local graph for physical infrastructure matching properties.",
Parameters: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"node_type": map[string]string{"type": "string"},
"tag_key": map[string]string{"type": "string"},
"tag_value": map[string]string{"type": "string"},
},
},
}
When you ask: "Find me all idle databases missing the Owner tag", execution runs in three steps:
- Inference 1: The LLM parses the intent, recognizes it lacks topological data, and returns a structured
{"name": "query_graph", "arguments": {...}}response. - Local Execution: The daemon runs the query against the in-memory graph in \(O(1)\) time, returning the specific array of CRNs and telemetry metadata.
- Inference 2: The daemon appends the results to the context window and re-prompts for natural language synthesis.
Reversibility¶
and Safe Execution
If you request a mutable action ("Quarantine all databases from the previous query"), the LLM generates a proposed cs cleanup command target list.
The daemon never executes LLM output autonomously. The sequence pipes exclusively to the TUI's confirmation buffer. You physically press [Enter] to bind it to a s.a.u saga.
All execution sequences initiated via the LLM are permanently flagged in the s.a.u Audit Ledger with author_identifier: ai-copilot.