AGENT SKILL
dialogue-graph
A library for building, validating, visualizing, and serializing dialogue graphs (line + choice nodes) using `Graph`, `Node`, and `Edge`.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- dialogue-graph
- description
- A library for building, validating, visualizing, and serializing dialogue graphs (line + choice nodes) using `Graph`, `Node`, and `Edge`.
02 资源文件 1
- 脚本scripts/dialogue_graph.py5.7 KB
03 SKILL.md 正文
Steps
- Import the primitives and create a graph:
from dialogue_graph import Graph, Node, Edge graph = Graph() - Add nodes (use unique IDs; add them in script order if you want a stable “first node” entry point):
# Regular spoken/narration line node graph.add_node(Node(id="GateScene", speaker="Guard", text="Halt!", type="line")) # Choice hub node graph.add_node(Node(id="NameChoice", type="choice")) - Add edges to connect nodes:
- For non-choice transitions, keep
textempty (the spoken text belongs on the node):graph.add_edge(Edge(source="GateScene", target="NameChoice", text="")) - For choice options, set
Edge.textto the option body without the numeric enumeration (1./2./ …). Keep bracket tags like[Lie]/[Attack]as part of the option body text:graph.add_edge(Edge(source="NameChoice", target="KnightPath", text="I am Sir Aldric, Knight of the Realm.")) graph.add_edge(Edge(source="NameChoice", target="MerchantPath", text="[Lie] I'm a merchant with important goods.")) - Use
"End"as a terminal edge target string; it is treated as a special terminal and does not require a correspondingNode("End").
- For non-choice transitions, keep
- Validate structure with the built-in validator:
errors = graph.validate()validate()checks that edge sources exist and that edge targets exist, with"End"allowed as a missing terminal target. - Export the parsed graph directly (without normalizing the graph by adding/removing nodes/edges):
data = graph.to_dict() # {"nodes":[...], "edges":[...]} json_str = graph.to_json() # JSON string of the same structure - Visualize:
The built-in visualizer draws choice nodes as diamonds, line nodes as rounded boxes, and includes angraph.visualize('dialogue_graph') # dialogue_graph.png graph.visualize('dialogue_graph', format='svg')Endterminal node in the diagram. - Load an existing graph when needed:
graph = Graph.from_file('dialogue.json')
Expected Result
- Nodes serialize as
{"id": ..., "text": ..., "speaker": ..., "type": ...}withtypein{"line","choice"}. - Edges serialize as
{"from": ..., "to": ..., "text": ...}where choice edges’textis the option body (no1./2.prefix), and terminal transitions can target"End"without requiring an"End"node innodes. graph.validate()returns an empty list when all non-Endedge targets exist.
04 同仓库更多 Skills
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
★ 0
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
★ 0
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
★ 0
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
★ 0
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
★ 0
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
★ 0