deeprefine
Agent-native DeepRefine refinement loop — same control flow as DeepRefine.refine(), graphify search instead of FAISS, session LLM, dry-run review before approved graph writes.
HKUST-KnowComp · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add HKUST-KnowComp/DeepRefine-Skill --skill deeprefine技能说明
name: deeprefine description: >- Agent-native DeepRefine refinement loop — same control flow as DeepRefine.refine(), graphify search instead of FAISS, session LLM, dry-run review before approved graph writes. disable-model-invocation: false
DeepRefine — Agent refinement loop (strict)
Default safety policy: dry-run only
A normal /deeprefine invocation MUST NEVER call deeprefine apply.
The default /deeprefine workflow must stop after:
deeprefine loop validatedeeprefine review- showing the proposed actions and HIGH/MEDIUM/LOW review report to the user
Then ask the user for explicit approval.
Only if the user's next message explicitly says to approve/apply/write the graph may you run:
deeprefine apply --refresh-wiki --trace-file ... --refinement-file ...
deeprefine loop finish --trace-file ... --refinement-file ...
Do not treat generation of <refinement> actions as approval. Do not treat a valid trace as approval. Do not apply in the same /deeprefine turn.
You MUST implement the same control flow as DeepRefine.refine() in DeepRefine (autorefiner/src/deeprefine.py).
| Component | Agent mode | CLI deeprefine refine |
|---|---|---|
| Retrieval | graphify query + k-hop from graph.json | FAISS retriever |
| LLM | Your session model | External API / vLLM |
| Graph writes | Dry-run proposal + deeprefine review; deeprefine apply only after user approval | Dry-run by default; --apply persists |
FORBIDDEN (hard stop)
Do NOT:
- Run
deeprefine refine(unless the user explicitly asks for CLI/FAISS mode). - Call
deeprefine applywithout a validloop_trace_<query_id>.json(CLI will reject). - Call
deeprefine applybefore runningdeeprefine reviewand receiving explicit user approval. - Ignore LOW-confidence review warnings unless the user explicitly requests
--allow-low-confidence. - Skip any hop’s
<judge>Yes</judge>/<judge>No</judge>judgement. - Skip error abduction when
len(interaction_history) > 1. - Write
<refinement>before abduction when refinement is required. - Hand-edit
graph.jsonwith Python or ad-hoc JSON patches. - Ignore pending history and refine only one latest query when unrefined queries already exist.
- Invent a shorter pipeline (“read file → write refinement → apply”).
If validation fails, fix the trace and re-run the missing step — do not bypass with --skip-trace-check.
Constants (match refine_runner.py / DeepRefine)
MAX_HOPS = 4
INCREMENT_HOP = 1
BASE_TOP_K = 10
MAX_TRIPLE_NUM_BY_STEP = [5, 10, 15, 20] # cap triples per step
HISTORY_HORIZON = 4 # abduction uses last N steps
Mandatory artifact
For each query, maintain:
graphify-out/.deeprefine/loop_trace_<query_id>.json
Create template:
deeprefine loop init --query "<exact question>"
Append each hop to interaction_history before starting the next hop.
Run deeprefine loop validate --trace-file ... after abduction and before review / approved apply.
Query queue selection (default behavior of /deeprefine)
/deeprefine must process all unrefined history queries first, not just the latest one.
- Sync graphify query memory into DeepRefine history:
- run:
deeprefine history sync-memory - source dir:
graphify-out/memory/query_*.md - target file:
graphify-out/.deeprefine/history.jsonl
- run:
- Read pending queue from
graphify-out/.deeprefine/history.jsonl:- include rows where
refined != true - dedupe by
id(first occurrence) - preserve file order
- include rows where
- If pending queue is non-empty: set
target_queries = pending_queue. - If pending queue is empty: set
target_queries = [current session question]. - Run the full refinement loop for each query in
target_queries, one by one. - For early-exit queries, finish immediately. For refinement-path queries, generate review output and wait for user approval before
apply+loop finish.
Control flow (must match DeepRefine.refine())
Pseudocode — follow exactly:
target_queries = pending_history_queries() # refined != true, dedupe by id, keep order
run "deeprefine history sync-memory" before loading pending history
if target_queries is empty:
target_queries = [current session question]
for question in target_queries:
interaction_history = []
for step in 1..MAX_HOPS:
print "[Step: {step}]" # show in chat
if step == 1:
# Vector-retrieval equivalent: graphify query on full question
RUN: graphify query "<question>"
triples = parse NODE/EDGE → [{subject, relation, object}, ...]
cap = MAX_TRIPLE_NUM_BY_STEP[0] # 5
record retrieval.method = "graphify_query"
else:
# k-hop expansion from entities in previous hop (NOT a new random search)
entities = unique subjects/objects from previous triples
expand 1-hop neighbors from graphify-out/graph.json (or graphify query on entities)
cap = MAX_TRIPLE_NUM_BY_STEP[step-1]
record retrieval.method = "k_hop_expansion" or "graphify_query+k_hop_expansion"
triples = dedupe; len(triples) <= cap
# Answerable judgement — session LLM, prompts below
answerable, judgement_raw = LLM_judge(question, triples)
MUST output ONLY: <judge>Yes</judge> or <judge>No</judge>
append interaction_history with:
step, query, num_hops=(step-1)*INCREMENT_HOP, base_top_k=10,
retrieved_subgraph, answerable, judgement_raw,
retrieval: {method, evidence: "<command output excerpt>"}
if answerable:
BREAK # stop hop loop
# --- same branch as DeepRefine.refine() line 314+ ---
if len(interaction_history) <= 1:
# Early exit: first hop was answerable — NO graph refinement
set trac
阅读完整来源 ↗