跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
AI 与知识库

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:

  1. deeprefine loop validate
  2. deeprefine review
  3. 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).

ComponentAgent modeCLI deeprefine refine
Retrievalgraphify query + k-hop from graph.jsonFAISS retriever
LLMYour session modelExternal API / vLLM
Graph writesDry-run proposal + deeprefine review; deeprefine apply only after user approvalDry-run by default; --apply persists

FORBIDDEN (hard stop)

Do NOT:

  1. Run deeprefine refine (unless the user explicitly asks for CLI/FAISS mode).
  2. Call deeprefine apply without a valid loop_trace_<query_id>.json (CLI will reject).
  3. Call deeprefine apply before running deeprefine review and receiving explicit user approval.
  4. Ignore LOW-confidence review warnings unless the user explicitly requests --allow-low-confidence.
  5. Skip any hop’s <judge>Yes</judge> / <judge>No</judge> judgement.
  6. Skip error abduction when len(interaction_history) > 1.
  7. Write <refinement> before abduction when refinement is required.
  8. Hand-edit graph.json with Python or ad-hoc JSON patches.
  9. Ignore pending history and refine only one latest query when unrefined queries already exist.
  10. 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.

  1. 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
  2. Read pending queue from graphify-out/.deeprefine/history.jsonl:
    • include rows where refined != true
    • dedupe by id (first occurrence)
    • preserve file order
  3. If pending queue is non-empty: set target_queries = pending_queue.
  4. If pending queue is empty: set target_queries = [current session question].
  5. Run the full refinement loop for each query in target_queries, one by one.
  6. 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
阅读完整来源 ↗