This repository contains a two-stage pipeline for building and refining trajectories from dialogue data. The final output is a rewritten trajectory suitable for training models.
The pipeline consists of two scripts that must be run in order:
state_graph_build.pymine_dag_and_message_refine.py
The first script builds a state graph from raw conversation and saves the graph results. The second script takes these graph results, mines the minimal action subgraph (DAG), and refines the assistant messages to produce a compact, coherent trajectory.
-
Create and activate your Python environment.
-
Install dependencies, for example:
pip install -r requirements.txt
-
Create a
.envfile in the project root with content similar to:# For state_graph_build.py EXTRACTOR_API_KEY=your_extractor_api_key EXTRACTOR_BASE_URL=your_extractor_base_url # For mine_dag_and_message_refine.py REWRITER_API_KEY=your_rewriter_api_key REWRITER_BASE_URL=your_rewriter_base_url # PPL model for candidate selection PPL_MODEL_PATH=your_ppl_model_path
Make sure the keys and URLs correspond to valid model endpoints that support the OpenAI-compatible chat API.
Script: state_graph_build.py
This script reads raw conversation data and constructs a state graph containing information nodes, action nodes, and edges. It outputs a JSONL file where each line includes:
raw_message: original message liststate_graph_result: serialized state graph
python state_graph_build.py \
--input /path/to/raw_conversations.jsonl \
--output /path/to/state_graph_result.jsonlThe output file from this step will be used as the input to the second script.
Script: mine_dag_and_message_refine.py
This script takes the state graph results, performs:
- Majority voting over repeated samples (if present) to get a stable minimal action subgraph.
- Mining of the minimal action DAG leading to the final answer.
- LLM-based refinement of the assistant’s internal thinking and responses, with optional PPL-based candidate selection.
The output is a JSONL file where each line typically contains:
messages: the refined, pruned dialogue trajectory- Additional metadata such as perplexity scores (
max_ppl,avg_ppl, etc.)
python mine_dag_and_message_refine.py \
--input /path/to/state_graph_result.jsonl \
--output /path/to/refined_trajectory.jsonl- Prepare raw conversation data as JSONL.
- Run
state_graph_build.pyto generate the state graph file. - Use that state graph file as the input to
mine_dag_and_message_refine.py. - The final output (
refined_trajectory.jsonl) can be used as training data, containing compact and refined trajectories.