Graphs & Flowcharts
Graphs & Flowcharts Integration
The Graphs & Flowcharts module enables your AI agents to interpret, analyze, and reason across visual logic. By converting spatial diagrams and structural charts into machine-readable formats, Deeptrain bridges the gap between visual documentation and LLM reasoning.
Capabilities
- Structural Analysis: Identifies nodes, edges, and decision paths within flowcharts.
- Relational Mapping: Translates complex graph hierarchies into JSON or textual logic.
- Multi-format Support: Process logic from static images (PNG/JPG), vector graphics (SVG), or script-based diagrams (Mermaid/PlantUML).
Processing Visual Logic
To ingest a flowchart or graph, use the process_visual_logic method. This function extracts the logical flow and provides a structured representation that can be injected into an LLM's context window.
Usage Example
from deeptrain import LogicParser
# Initialize the parser
parser = LogicParser()
# Process a flowchart from a local image
graph_data = parser.process_visual_logic(
source="path/to/workflow_diagram.png",
output_format="json",
detail_level="high"
)
print(graph_data)
API Reference: process_visual_logic
| Parameter | Type | Description |
| :--- | :--- | :--- |
| source | str | Path to the image file, URL, or raw diagram script (e.g., Mermaid). |
| output_format | str | The desired structure: "json", "textual_logic", or "adjacency_list". |
| detail_level | str | Controls the depth of extraction: "low" (main nodes) to "high" (includes attributes/sub-text). |
| ocr_refinement | bool | If True, applies specialized OCR to clarify text within small nodes. |
Returns: A dict containing the logical mapping of the diagram.
Handling Script-Based Diagrams
Deeptrain can interpret diagram-as-code formats directly. This is particularly useful for agents that need to validate architectural decisions or generate documentation from codebases.
mermaid_script = """
graph TD
A[User Request] --> B{Authorized?}
B -- Yes --> C[Fetch Data]
B -- No --> D[Error 403]
"""
# Convert Mermaid script into a logical prompt for an LLM
logic_summary = parser.interpret_script(
script=mermaid_script,
provider="mermaid"
)
Logical Output Structure
When processing a visual diagram, Deeptrain returns a structured object. This allows your AI agent to understand not just the labels, but the connectivity of the information.
Sample JSON Output:
{
"diagram_type": "flowchart",
"nodes": [
{"id": "n1", "label": "Start", "type": "entry"},
{"id": "n2", "label": "Process Payment", "type": "action"},
{"id": "n3", "label": "Success?", "type": "decision"}
],
"edges": [
{"from": "n1", "to": "n2", "connection": "direct"},
{"from": "n2", "to": "n3", "connection": "conditional"}
],
"logic_path": "n1 -> n2 -> n3"
}
Best Practices
- Resolution: For image-based flowcharts, ensure a minimum resolution of 720p for accurate text extraction from nodes.
- Contrast: High-contrast diagrams (dark text on light backgrounds) yield the highest accuracy for relational mapping.
- Prompting: When feeding this data to an LLM, use the
textual_logicoutput format to help the model "visualize" the steps sequentially.