deeprefine-cli 0.1.6__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {deeprefine_cli-0.1.6/deeprefine_cli.egg-info → deeprefine_cli-0.1.7}/PKG-INFO +15 -15
  2. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/README.md +14 -12
  3. deeprefine_cli-0.1.7/SKILL.md +311 -0
  4. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7/deeprefine_cli.egg-info}/PKG-INFO +15 -15
  5. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_cli.egg-info/SOURCES.txt +3 -0
  6. deeprefine_cli-0.1.7/deeprefine_skill/SKILL.md +311 -0
  7. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/__init__.py +1 -1
  8. deeprefine_cli-0.1.7/deeprefine_skill/agent_graph.py +194 -0
  9. deeprefine_cli-0.1.7/deeprefine_skill/agent_loop.py +212 -0
  10. deeprefine_cli-0.1.7/deeprefine_skill/agent_prompts.py +56 -0
  11. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/cli.py +163 -0
  12. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/refine_runner.py +4 -1
  13. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/pyproject.toml +2 -1
  14. deeprefine_cli-0.1.6/SKILL.md +0 -80
  15. deeprefine_cli-0.1.6/deeprefine_skill/SKILL.md +0 -80
  16. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/LICENSE +0 -0
  17. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/MANIFEST.in +0 -0
  18. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_cli.egg-info/dependency_links.txt +0 -0
  19. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_cli.egg-info/entry_points.txt +0 -0
  20. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_cli.egg-info/requires.txt +0 -0
  21. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_cli.egg-info/top_level.txt +0 -0
  22. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/adapter_graphify.py +0 -0
  23. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/history.py +0 -0
  24. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/installers.py +0 -0
  25. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/deeprefine_skill/paths.py +0 -0
  26. {deeprefine_cli-0.1.6 → deeprefine_cli-0.1.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deeprefine-cli
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: CLI and Cursor skill to refine graphify knowledge graphs with DeepRefine
5
5
  Author: HKUST-KnowComp
6
6
  License-Expression: MIT
@@ -20,17 +20,15 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
21
  Requires-Python: >=3.10
22
22
  Description-Content-Type: text/markdown
23
- License-File: LICENSE
24
23
  Requires-Dist: openai>=1.0
25
- Dynamic: license-file
26
24
 
27
25
  <div align="center">
28
26
 
29
27
  # DeepRefine-Skill
30
28
 
31
29
 
32
- [![PyPi](https://img.shields.io/badge/PyPi-v0.1.6-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
33
- [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
30
+ [![PyPi](https://img.shields.io/badge/PyPi-v0.1.7-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
31
+ [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
34
32
  [![Paper](https://img.shields.io/badge/Paper-DeepRefine-b31b1b.svg)](https://arxiv.org/pdf/2605.10488)
35
33
  [![Project](https://img.shields.io/badge/Project-DeepRefine-green.svg)](https://github.com/HKUST-KnowComp/DeepRefine)
36
34
 
@@ -38,13 +36,13 @@ Dynamic: license-file
38
36
 
39
37
  Type `/deeprefine` in your AI coding assistant after you've built a **[graphify](https://github.com/safishamsi/graphify)** knowledge base — it patches `graphify-out/graph.json` from your session's query history to evolve your LLM-Wiki.
40
38
 
41
- Works in **Cursor** (install the skill once with `deeprefine cursor install`). In Cursor, `/deeprefine` tells the agent to run **`deeprefine refine`** in your project the full Reafiner loop (judgement abduction action generation), not a hand-edited `graph.json`.
39
+ Works in **Cursor** (`deeprefine cursor install`). **`/deeprefine`** runs the **same control flow as `Reafiner.refine()`** in the agent: `graphify query` / k-hop reads (no FAISS), session LLM for judgement/abduction/actions, mandatory `loop_trace_*.json`, then `deeprefine apply`. Optional **`deeprefine refine`** = full FAISS + API runtime.
42
40
 
43
41
  ```
44
42
  /deeprefine
45
43
  ```
46
44
 
47
- **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent runs `deeprefine refine` for session queries).
45
+ **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent loop: search → judge → abduct → actions → `deeprefine apply`).
48
46
 
49
47
  That's it. Under `graphify-out/.deeprefine/` you get:
50
48
 
@@ -58,13 +56,13 @@ graphify-out/
58
56
  ```
59
57
 
60
58
  > **Standalone repo.** Model code (`autorefiner`, `atlas_rag`) lives in a separate [DeepRefine](https://github.com/HKUST-KnowComp/DeepRefine) checkout.
61
- > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. `/deeprefine` and terminal `deeprefine refine` both use the same DeepRefine runtime (vLLM or API keys in your shell). Configure inference once in `atlastune`.
59
+ > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. **Agent mode** (`/deeprefine`): same loop logic, no FAISS retriever, no extra API keys. **CLI mode** (`deeprefine refine`): full `Reafiner` + embeddings (vLLM or API).
62
60
 
63
61
  ---
64
62
 
65
63
  ## News
66
64
 
67
- - [2026/6/2] deeprefine-cli v0.1.6 has been released! Customize your LLM api in CLI.
65
+ - [2026/6/2] deeprefine-cli v0.1.7 agent Reafiner loop + `deeprefine loop` / `apply --trace-file`.
68
66
 
69
67
  ---
70
68
 
@@ -76,7 +74,7 @@ graphify-out/
76
74
  | 2 | `pip install deeprefine-cli` |
77
75
  | 3 | `deeprefine cursor install` in your KB project |
78
76
  | 4 | (Optional) start local vLLM, or use your API provider |
79
- | 5 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine`)*; or terminal: `history add` + `refine` |
77
+ | 5 | Cursor: `/deeprefine` *(agent loop)*; or terminal: `history add` + `deeprefine refine` |
80
78
 
81
79
  ```bash
82
80
  # 1) DeepRefine (once)
@@ -105,9 +103,9 @@ export DEEPREFINE_EMBED_MODEL=your_embed_model
105
103
  # export DEEPREFINE_API_KEY=your_shared_api_key
106
104
  # optional model overrides:
107
105
 
108
- # 5) Refine — full Reafiner loop
109
- # Cursor chat: type /deeprefine (agent runs deeprefine refine --query "..." per session question)
110
- # Terminal manual flow:
106
+ # 5) Refine
107
+ # Cursor: /deeprefine (agent loop: graphify query + judgement/abduction/actions + deeprefine apply)
108
+ # Terminal CLI mode:
111
109
  deeprefine history add --query "your question"
112
110
  deeprefine refine
113
111
  ```
@@ -255,8 +253,8 @@ deeprefine cursor install
255
253
  |:-:|--------|
256
254
  | 1 | `graphify .` or `/graphify .` → `graphify-out/graph.json` |
257
255
  | 2 | `graphify query "..."` |
258
- | 3 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine` / `--query` for session questions)* |
259
- | 4 | Terminal alternative: `deeprefine history add --query "..."` → `deeprefine refine` |
256
+ | 3 | Cursor chat: `/deeprefine` *(agent loop; no manual history add)* |
257
+ | 4 | Terminal: `deeprefine history add` → `deeprefine refine` *(FAISS + API/vLLM)* |
260
258
  | 5 | *(optional)* `graphify query "..."` to verify |
261
259
 
262
260
  ---
@@ -273,6 +271,8 @@ All commands below run from **KB project root**.
273
271
  | `deeprefine refine` | Refine all pending queries |
274
272
  | `deeprefine refine --query "..."` | Refine one query (also recorded) |
275
273
  | `deeprefine refine --rebuild-index` | Rebuild FAISS before refine |
274
+ | `deeprefine loop init/validate/finish` | Agent loop trace (enforces Reafiner rules) |
275
+ | `deeprefine apply --trace-file T --refinement-file F` | Apply actions (requires valid trace) |
276
276
  | `deeprefine index --rebuild` | Rebuild FAISS cache only |
277
277
  | `deeprefine cursor install \| uninstall` | Manage Cursor skill |
278
278
 
@@ -3,8 +3,8 @@
3
3
  # DeepRefine-Skill
4
4
 
5
5
 
6
- [![PyPi](https://img.shields.io/badge/PyPi-v0.1.6-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
7
- [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
6
+ [![PyPi](https://img.shields.io/badge/PyPi-v0.1.7-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
7
+ [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
8
8
  [![Paper](https://img.shields.io/badge/Paper-DeepRefine-b31b1b.svg)](https://arxiv.org/pdf/2605.10488)
9
9
  [![Project](https://img.shields.io/badge/Project-DeepRefine-green.svg)](https://github.com/HKUST-KnowComp/DeepRefine)
10
10
 
@@ -12,13 +12,13 @@
12
12
 
13
13
  Type `/deeprefine` in your AI coding assistant after you've built a **[graphify](https://github.com/safishamsi/graphify)** knowledge base — it patches `graphify-out/graph.json` from your session's query history to evolve your LLM-Wiki.
14
14
 
15
- Works in **Cursor** (install the skill once with `deeprefine cursor install`). In Cursor, `/deeprefine` tells the agent to run **`deeprefine refine`** in your project the full Reafiner loop (judgement abduction action generation), not a hand-edited `graph.json`.
15
+ Works in **Cursor** (`deeprefine cursor install`). **`/deeprefine`** runs the **same control flow as `Reafiner.refine()`** in the agent: `graphify query` / k-hop reads (no FAISS), session LLM for judgement/abduction/actions, mandatory `loop_trace_*.json`, then `deeprefine apply`. Optional **`deeprefine refine`** = full FAISS + API runtime.
16
16
 
17
17
  ```
18
18
  /deeprefine
19
19
  ```
20
20
 
21
- **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent runs `deeprefine refine` for session queries).
21
+ **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent loop: search → judge → abduct → actions → `deeprefine apply`).
22
22
 
23
23
  That's it. Under `graphify-out/.deeprefine/` you get:
24
24
 
@@ -32,13 +32,13 @@ graphify-out/
32
32
  ```
33
33
 
34
34
  > **Standalone repo.** Model code (`autorefiner`, `atlas_rag`) lives in a separate [DeepRefine](https://github.com/HKUST-KnowComp/DeepRefine) checkout.
35
- > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. `/deeprefine` and terminal `deeprefine refine` both use the same DeepRefine runtime (vLLM or API keys in your shell). Configure inference once in `atlastune`.
35
+ > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. **Agent mode** (`/deeprefine`): same loop logic, no FAISS retriever, no extra API keys. **CLI mode** (`deeprefine refine`): full `Reafiner` + embeddings (vLLM or API).
36
36
 
37
37
  ---
38
38
 
39
39
  ## News
40
40
 
41
- - [2026/6/2] deeprefine-cli v0.1.6 has been released! Customize your LLM api in CLI.
41
+ - [2026/6/2] deeprefine-cli v0.1.7 agent Reafiner loop + `deeprefine loop` / `apply --trace-file`.
42
42
 
43
43
  ---
44
44
 
@@ -50,7 +50,7 @@ graphify-out/
50
50
  | 2 | `pip install deeprefine-cli` |
51
51
  | 3 | `deeprefine cursor install` in your KB project |
52
52
  | 4 | (Optional) start local vLLM, or use your API provider |
53
- | 5 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine`)*; or terminal: `history add` + `refine` |
53
+ | 5 | Cursor: `/deeprefine` *(agent loop)*; or terminal: `history add` + `deeprefine refine` |
54
54
 
55
55
  ```bash
56
56
  # 1) DeepRefine (once)
@@ -79,9 +79,9 @@ export DEEPREFINE_EMBED_MODEL=your_embed_model
79
79
  # export DEEPREFINE_API_KEY=your_shared_api_key
80
80
  # optional model overrides:
81
81
 
82
- # 5) Refine — full Reafiner loop
83
- # Cursor chat: type /deeprefine (agent runs deeprefine refine --query "..." per session question)
84
- # Terminal manual flow:
82
+ # 5) Refine
83
+ # Cursor: /deeprefine (agent loop: graphify query + judgement/abduction/actions + deeprefine apply)
84
+ # Terminal CLI mode:
85
85
  deeprefine history add --query "your question"
86
86
  deeprefine refine
87
87
  ```
@@ -229,8 +229,8 @@ deeprefine cursor install
229
229
  |:-:|--------|
230
230
  | 1 | `graphify .` or `/graphify .` → `graphify-out/graph.json` |
231
231
  | 2 | `graphify query "..."` |
232
- | 3 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine` / `--query` for session questions)* |
233
- | 4 | Terminal alternative: `deeprefine history add --query "..."` → `deeprefine refine` |
232
+ | 3 | Cursor chat: `/deeprefine` *(agent loop; no manual history add)* |
233
+ | 4 | Terminal: `deeprefine history add` → `deeprefine refine` *(FAISS + API/vLLM)* |
234
234
  | 5 | *(optional)* `graphify query "..."` to verify |
235
235
 
236
236
  ---
@@ -247,6 +247,8 @@ All commands below run from **KB project root**.
247
247
  | `deeprefine refine` | Refine all pending queries |
248
248
  | `deeprefine refine --query "..."` | Refine one query (also recorded) |
249
249
  | `deeprefine refine --rebuild-index` | Rebuild FAISS before refine |
250
+ | `deeprefine loop init/validate/finish` | Agent loop trace (enforces Reafiner rules) |
251
+ | `deeprefine apply --trace-file T --refinement-file F` | Apply actions (requires valid trace) |
250
252
  | `deeprefine index --rebuild` | Rebuild FAISS cache only |
251
253
  | `deeprefine cursor install \| uninstall` | Manage Cursor skill |
252
254
 
@@ -0,0 +1,311 @@
1
+ ---
2
+ name: deeprefine
3
+ description: >-
4
+ Agent-native DeepRefine Reafiner loop — same control flow as Reafiner.refine(),
5
+ graphify search instead of FAISS, session LLM, deeprefine apply for graph writes.
6
+ disable-model-invocation: false
7
+ ---
8
+
9
+ # DeepRefine — Agent Reafiner loop (strict)
10
+
11
+ You **MUST** implement the **same control flow** as `Reafiner.refine()` in DeepRefine (`autorefiner/src/reafiner.py`).
12
+
13
+ | Component | Agent mode | CLI `deeprefine refine` |
14
+ |-----------|------------|-------------------------|
15
+ | Retrieval | `graphify query` + k-hop from `graph.json` | FAISS retriever |
16
+ | LLM | **Your session model** | External API / vLLM |
17
+ | Graph writes | `deeprefine apply` + validated `loop_trace_*.json` | In-process |
18
+
19
+ ---
20
+
21
+ ## FORBIDDEN (hard stop)
22
+
23
+ Do **NOT**:
24
+
25
+ 1. Run `deeprefine refine` (unless the user explicitly asks for CLI/FAISS mode).
26
+ 2. Call `deeprefine apply` without a valid `loop_trace_<query_id>.json` (CLI will reject).
27
+ 3. Skip any hop’s `<judge>Yes</judge>` / `<judge>No</judge>` judgement.
28
+ 4. Skip error abduction when `len(interaction_history) > 1`.
29
+ 5. Write `<refinement>` before abduction when refinement is required.
30
+ 6. Hand-edit `graph.json` with Python or ad-hoc JSON patches.
31
+ 7. Run `deeprefine history add` at the start of `/deeprefine` (only `loop finish` updates history).
32
+ 8. Invent a shorter pipeline (“read file → write refinement → apply”).
33
+
34
+ If validation fails, **fix the trace and re-run the missing step** — do not bypass with `--skip-trace-check`.
35
+
36
+ ---
37
+
38
+ ## Constants (match `refine_runner.py` / Reafiner)
39
+
40
+ ```text
41
+ MAX_HOPS = 4
42
+ INCREMENT_HOP = 1
43
+ BASE_TOP_K = 10
44
+ MAX_TRIPLE_NUM_BY_STEP = [5, 10, 15, 20] # cap triples per step
45
+ HISTORY_HORIZON = 4 # abduction uses last N steps
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Mandatory artifact
51
+
52
+ For each query, maintain:
53
+
54
+ `graphify-out/.deeprefine/loop_trace_<query_id>.json`
55
+
56
+ Create template:
57
+
58
+ ```bash
59
+ deeprefine loop init --query "<exact question>"
60
+ ```
61
+
62
+ Append each hop to `interaction_history` **before** starting the next hop.
63
+ Run `deeprefine loop validate --trace-file ...` after abduction and before `apply`.
64
+
65
+ ---
66
+
67
+ ## Control flow (must match `Reafiner.refine()`)
68
+
69
+ Pseudocode — follow **exactly**:
70
+
71
+ ```text
72
+ interaction_history = []
73
+ for step in 1..MAX_HOPS:
74
+ print "[Step: {step}]" # show in chat
75
+
76
+ if step == 1:
77
+ # Vector-retrieval equivalent: graphify query on full question
78
+ RUN: graphify query "<question>"
79
+ triples = parse NODE/EDGE → [{subject, relation, object}, ...]
80
+ cap = MAX_TRIPLE_NUM_BY_STEP[0] # 5
81
+ record retrieval.method = "graphify_query"
82
+ else:
83
+ # k-hop expansion from entities in previous hop (NOT a new random search)
84
+ entities = unique subjects/objects from previous triples
85
+ expand 1-hop neighbors from graphify-out/graph.json (or graphify query on entities)
86
+ cap = MAX_TRIPLE_NUM_BY_STEP[step-1]
87
+ record retrieval.method = "k_hop_expansion" or "graphify_query+k_hop_expansion"
88
+
89
+ triples = dedupe; len(triples) <= cap
90
+
91
+ # Answerable judgement — session LLM, prompts below
92
+ answerable, judgement_raw = LLM_judge(question, triples)
93
+ MUST output ONLY: <judge>Yes</judge> or <judge>No</judge>
94
+
95
+ append interaction_history with:
96
+ step, query, num_hops=(step-1)*INCREMENT_HOP, base_top_k=10,
97
+ retrieved_subgraph, answerable, judgement_raw,
98
+ retrieval: {method, evidence: "<command output excerpt>"}
99
+
100
+ if answerable:
101
+ BREAK # stop hop loop
102
+
103
+ # --- same branch as Reafiner.refine() line 314+ ---
104
+ if len(interaction_history) <= 1:
105
+ # Early exit: first hop was answerable — NO graph refinement
106
+ set trace.early_exit = true
107
+ deeprefine loop finish --trace-file ... # no --refinement-file
108
+ STOP
109
+ else:
110
+ # len > 1 → ALWAYS error abduction + actions (even if last hop was Yes)
111
+ error_abduction = LLM_abduction(interaction_history[-HISTORY_HORIZON:])
112
+ MUST output: <abduction>...</abduction>
113
+
114
+ actions = LLM_kg_refinement(
115
+ last_hop.retrieved_subgraph,
116
+ error_abduction,
117
+ question,
118
+ source file hints from triples,
119
+ )
120
+ MUST output: <refinement>insert_edge(...)|...</refinement>
121
+
122
+ save refinement to graphify-out/.deeprefine/refinement_actions_<id>.txt
123
+ deeprefine loop validate --trace-file ... --refinement-file ...
124
+ deeprefine apply --trace-file ... --refinement-file ...
125
+ deeprefine loop finish --trace-file ... --refinement-file ...
126
+ ```
127
+
128
+ **Critical Reafiner rule:** refinement runs when `len(interaction_history) > 1`, not only when all judgements are `No`.
129
+
130
+ ---
131
+
132
+ ## LLM prompts (verbatim — do not paraphrase)
133
+
134
+ ### Judgement (`_answerable_judgement`)
135
+
136
+ **System:**
137
+
138
+ ```text
139
+ As an advanced judgement assistant, your task is to judge whether the given question is answerable based on the provided KG context.
140
+
141
+ Evaluate whether the given question is answerable based on the provided KG context. Output your judgment in the following format:
142
+ <judge>Yes</judge> or <judge>No</judge>
143
+
144
+ **Important:** You must think carefully about the question and the KG context before making your judgment. And output your judgment result directly in the specified format.
145
+ ```
146
+
147
+ **User:**
148
+
149
+ ```text
150
+ Question: {question}
151
+ Knowledge Graph (KG) context: {triples_string}
152
+ ```
153
+
154
+ `{triples_string}` = one triple per line: `subject | relation | object`
155
+
156
+ ### Error abduction (`_error_abduction`) — only if `len(interaction_history) > 1`
157
+
158
+ **System:**
159
+
160
+ ```text
161
+ As an advanced error abduction assistant, your task is to analyze the error reasons based on the given interaction history.
162
+
163
+ Analyze the reasons of the unanswerable questions based on the given interaction history from the incompleteness, incorrectness, and redundancy perspectives. Output your analysis in the following format:
164
+ <abduction>...</abduction>
165
+
166
+ **Important:** You must think carefully about the interaction history before making your analysis. And output your analysis result directly in the specified format.
167
+ ```
168
+
169
+ **User:**
170
+
171
+ ```text
172
+ Interaction history: {interaction_history}
173
+ ```
174
+
175
+ `{interaction_history}` format (same as Reafiner):
176
+
177
+ ```text
178
+ Step1:
179
+ ['Query': ..., 'Subgraph_hop': ..., 'Subgraph_content': ..., 'Answerable': ...]
180
+
181
+ Step2:
182
+ ...
183
+ ```
184
+
185
+ ### KG refinement actions (`_kg_refinement_action`) — only if `len(interaction_history) > 1`
186
+
187
+ **System:**
188
+
189
+ ```text
190
+ As an advanced knowledge graph refinement assistant, your task is to generate a series of actions (**within 10 actions**) to refine the given KG to make it more suitable for answering the given question.
191
+
192
+ Based on the given KG and the analysed error reasons, refine the given KG to make it more easily for retrieval and answering the given question. You have the following three types of actions to conduct:
193
+
194
+ - insert_edge(subject, relation, object): Insert a new edge into the KG to complete the missing information.
195
+ - delete_edge(subject, relation, object): Delete an edge from the KG to remove the redundant information or conflicting information.
196
+ - replace_node(old_entity, new_entity): Replace an entity in the KG to correct the errors or deal with disambiguation.
197
+
198
+ Output a series of actions (**within 10 actions**) in the following format:
199
+ <refinement>insert_edge("...", "...", "...")|delete_edge("...", "...", "...")|replace_node("...", "...")|...</refinement>
200
+
201
+ **Important:** You must think carefully about the given KG and the analysed error reasons before making your refinement. DO NOT DELETE ANY IRRELEVANT TRIPLES FROM THE ORIGINAL KG. TRY TO KEEP THE ORIGINAL KG AS MUCH AS POSSIBLE. DO NOT GENERATE TOO MANY ACTIONS. And output your refinement result directly in the specified format.
202
+ ```
203
+
204
+ **User:**
205
+
206
+ ```text
207
+ Original Text: {original_text}
208
+ KG: {triples_string}
209
+ Question: {question}
210
+ Error reasons: {error_reasons}
211
+ ```
212
+
213
+ Use **last hop’s** `retrieved_subgraph` as `{triples_string}` (JSON list is OK in trace; string form for the prompt).
214
+
215
+ ---
216
+
217
+ ## Per-query checklist (report in chat)
218
+
219
+ Copy and tick each item in your final message:
220
+
221
+ ```text
222
+ [ ] Backup: graphify-out/.deeprefine/graph.json.bak
223
+ [ ] loop_trace_<id>.json created
224
+ [ ] Step 1: graphify query executed (evidence in trace)
225
+ [ ] Each step: <judge>Yes|No</judge> shown in chat
226
+ [ ] Hops stopped on Yes OR reached MAX_HOPS
227
+ [ ] early_exit OR (abduction + refinement) per Reafiner branch
228
+ [ ] deeprefine loop validate passed
229
+ [ ] deeprefine apply (only if refinement path)
230
+ [ ] deeprefine loop finish
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Commands (in order)
236
+
237
+ ```bash
238
+ # 0. KB project root; graphify-out/graph.json exists
239
+ mkdir -p graphify-out/.deeprefine
240
+ cp graphify-out/graph.json graphify-out/.deeprefine/graph.json.bak
241
+ deeprefine loop init --query "<question>"
242
+
243
+ # 1–4. For each hop: graphify/graph read → judge → append to loop_trace_*.json
244
+
245
+ # 5a. Early exit (len(history)==1 and answerable)
246
+ deeprefine loop validate --trace-file graphify-out/.deeprefine/loop_trace_<id>.json
247
+ deeprefine loop finish --trace-file graphify-out/.deeprefine/loop_trace_<id>.json
248
+
249
+ # 5b. Refinement path (len(history)>1)
250
+ deeprefine loop validate --trace-file ... --refinement-file graphify-out/.deeprefine/refinement_actions_<id>.txt
251
+ deeprefine apply --trace-file ... --refinement-file graphify-out/.deeprefine/refinement_actions_<id>.txt
252
+ deeprefine loop finish --trace-file ... --refinement-file graphify-out/.deeprefine/refinement_actions_<id>.txt
253
+ ```
254
+
255
+ ---
256
+
257
+ ## `loop_trace_*.json` schema
258
+
259
+ ```json
260
+ {
261
+ "schema_version": 1,
262
+ "mode": "agent-loop",
263
+ "query": "what is dulce?",
264
+ "query_id": "5cdc0798eb59b486",
265
+ "constants": { "max_hops": 4, "increment_hop": 1, "base_top_k": 10,
266
+ "max_triple_num_by_step": [5, 10, 15, 20], "history_horizon_size": 4 },
267
+ "interaction_history": [
268
+ {
269
+ "step": 1,
270
+ "num_hops": 0,
271
+ "base_top_k": 10,
272
+ "query": "what is dulce?",
273
+ "retrieval": {
274
+ "method": "graphify_query",
275
+ "evidence": "graphify query \"what is dulce?\" → …"
276
+ },
277
+ "retrieved_subgraph": [
278
+ {"subject": "A", "relation": "r", "object": "B"}
279
+ ],
280
+ "answerable": false,
281
+ "judgement_raw": "<judge>No</judge>"
282
+ }
283
+ ],
284
+ "error_abduction_reason": "…",
285
+ "error_abduction_raw": "<abduction>…</abduction>",
286
+ "refinement_action_file": "graphify-out/.deeprefine/refinement_actions_<id>.txt",
287
+ "early_exit": false
288
+ }
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Optional: CLI mode (FAISS + API)
294
+
295
+ Only when the user **explicitly** requests `deeprefine refine` / full runtime:
296
+
297
+ ```bash
298
+ conda activate atlastune
299
+ export DEEPREFINE_EMBED_URL=... DEEPREFINE_LLM_URL=...
300
+ deeprefine refine --query "..."
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Paths
306
+
307
+ - `graphify-out/graph.json`
308
+ - `graphify-out/.deeprefine/loop_trace_*.json` (**required**)
309
+ - `graphify-out/.deeprefine/refinement_actions_*.txt`
310
+ - `graphify-out/.deeprefine/refinement_results_*.jsonl`
311
+ - `graphify-out/.deeprefine/graph.json.bak`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deeprefine-cli
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: CLI and Cursor skill to refine graphify knowledge graphs with DeepRefine
5
5
  Author: HKUST-KnowComp
6
6
  License-Expression: MIT
@@ -20,17 +20,15 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
21
  Requires-Python: >=3.10
22
22
  Description-Content-Type: text/markdown
23
- License-File: LICENSE
24
23
  Requires-Dist: openai>=1.0
25
- Dynamic: license-file
26
24
 
27
25
  <div align="center">
28
26
 
29
27
  # DeepRefine-Skill
30
28
 
31
29
 
32
- [![PyPi](https://img.shields.io/badge/PyPi-v0.1.6-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
33
- [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.6/)
30
+ [![PyPi](https://img.shields.io/badge/PyPi-v0.1.7-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
31
+ [![Python](https://img.shields.io/badge/Python-3.10,3.11,3.12-blue.svg)](https://pypi.org/project/deeprefine-cli/0.1.7/)
34
32
  [![Paper](https://img.shields.io/badge/Paper-DeepRefine-b31b1b.svg)](https://arxiv.org/pdf/2605.10488)
35
33
  [![Project](https://img.shields.io/badge/Project-DeepRefine-green.svg)](https://github.com/HKUST-KnowComp/DeepRefine)
36
34
 
@@ -38,13 +36,13 @@ Dynamic: license-file
38
36
 
39
37
  Type `/deeprefine` in your AI coding assistant after you've built a **[graphify](https://github.com/safishamsi/graphify)** knowledge base — it patches `graphify-out/graph.json` from your session's query history to evolve your LLM-Wiki.
40
38
 
41
- Works in **Cursor** (install the skill once with `deeprefine cursor install`). In Cursor, `/deeprefine` tells the agent to run **`deeprefine refine`** in your project the full Reafiner loop (judgement abduction action generation), not a hand-edited `graph.json`.
39
+ Works in **Cursor** (`deeprefine cursor install`). **`/deeprefine`** runs the **same control flow as `Reafiner.refine()`** in the agent: `graphify query` / k-hop reads (no FAISS), session LLM for judgement/abduction/actions, mandatory `loop_trace_*.json`, then `deeprefine apply`. Optional **`deeprefine refine`** = full FAISS + API runtime.
42
40
 
43
41
  ```
44
42
  /deeprefine
45
43
  ```
46
44
 
47
- **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent runs `deeprefine refine` for session queries).
45
+ **Typical flow:** `graphify .` → `graphify query "..."` → `/deeprefine` (agent loop: search → judge → abduct → actions → `deeprefine apply`).
48
46
 
49
47
  That's it. Under `graphify-out/.deeprefine/` you get:
50
48
 
@@ -58,13 +56,13 @@ graphify-out/
58
56
  ```
59
57
 
60
58
  > **Standalone repo.** Model code (`autorefiner`, `atlas_rag`) lives in a separate [DeepRefine](https://github.com/HKUST-KnowComp/DeepRefine) checkout.
61
- > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. `/deeprefine` and terminal `deeprefine refine` both use the same DeepRefine runtime (vLLM or API keys in your shell). Configure inference once in `atlastune`.
59
+ > `pip install deeprefine-cli` ships the CLI and `SKILL.md`. **Agent mode** (`/deeprefine`): same loop logic, no FAISS retriever, no extra API keys. **CLI mode** (`deeprefine refine`): full `Reafiner` + embeddings (vLLM or API).
62
60
 
63
61
  ---
64
62
 
65
63
  ## News
66
64
 
67
- - [2026/6/2] deeprefine-cli v0.1.6 has been released! Customize your LLM api in CLI.
65
+ - [2026/6/2] deeprefine-cli v0.1.7 agent Reafiner loop + `deeprefine loop` / `apply --trace-file`.
68
66
 
69
67
  ---
70
68
 
@@ -76,7 +74,7 @@ graphify-out/
76
74
  | 2 | `pip install deeprefine-cli` |
77
75
  | 3 | `deeprefine cursor install` in your KB project |
78
76
  | 4 | (Optional) start local vLLM, or use your API provider |
79
- | 5 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine`)*; or terminal: `history add` + `refine` |
77
+ | 5 | Cursor: `/deeprefine` *(agent loop)*; or terminal: `history add` + `deeprefine refine` |
80
78
 
81
79
  ```bash
82
80
  # 1) DeepRefine (once)
@@ -105,9 +103,9 @@ export DEEPREFINE_EMBED_MODEL=your_embed_model
105
103
  # export DEEPREFINE_API_KEY=your_shared_api_key
106
104
  # optional model overrides:
107
105
 
108
- # 5) Refine — full Reafiner loop
109
- # Cursor chat: type /deeprefine (agent runs deeprefine refine --query "..." per session question)
110
- # Terminal manual flow:
106
+ # 5) Refine
107
+ # Cursor: /deeprefine (agent loop: graphify query + judgement/abduction/actions + deeprefine apply)
108
+ # Terminal CLI mode:
111
109
  deeprefine history add --query "your question"
112
110
  deeprefine refine
113
111
  ```
@@ -255,8 +253,8 @@ deeprefine cursor install
255
253
  |:-:|--------|
256
254
  | 1 | `graphify .` or `/graphify .` → `graphify-out/graph.json` |
257
255
  | 2 | `graphify query "..."` |
258
- | 3 | Cursor chat: `/deeprefine` *(agent runs `deeprefine refine` / `--query` for session questions)* |
259
- | 4 | Terminal alternative: `deeprefine history add --query "..."` → `deeprefine refine` |
256
+ | 3 | Cursor chat: `/deeprefine` *(agent loop; no manual history add)* |
257
+ | 4 | Terminal: `deeprefine history add` → `deeprefine refine` *(FAISS + API/vLLM)* |
260
258
  | 5 | *(optional)* `graphify query "..."` to verify |
261
259
 
262
260
  ---
@@ -273,6 +271,8 @@ All commands below run from **KB project root**.
273
271
  | `deeprefine refine` | Refine all pending queries |
274
272
  | `deeprefine refine --query "..."` | Refine one query (also recorded) |
275
273
  | `deeprefine refine --rebuild-index` | Rebuild FAISS before refine |
274
+ | `deeprefine loop init/validate/finish` | Agent loop trace (enforces Reafiner rules) |
275
+ | `deeprefine apply --trace-file T --refinement-file F` | Apply actions (requires valid trace) |
276
276
  | `deeprefine index --rebuild` | Rebuild FAISS cache only |
277
277
  | `deeprefine cursor install \| uninstall` | Manage Cursor skill |
278
278
 
@@ -12,6 +12,9 @@ deeprefine_cli.egg-info/top_level.txt
12
12
  deeprefine_skill/SKILL.md
13
13
  deeprefine_skill/__init__.py
14
14
  deeprefine_skill/adapter_graphify.py
15
+ deeprefine_skill/agent_graph.py
16
+ deeprefine_skill/agent_loop.py
17
+ deeprefine_skill/agent_prompts.py
15
18
  deeprefine_skill/cli.py
16
19
  deeprefine_skill/history.py
17
20
  deeprefine_skill/installers.py