feat(planner): done 触发块列出本意图新产生的 fact id
worker 结束触发规划时,除输出结论外,追加该意图经 yields 边产生的 fact id 列表,让规划者聚焦本轮增量、可直接 node_detail 查详情。 新增 ExplorationStore.FactsYielded 查询。
This commit is contained in:
1 parent
dc4645753c
commit
01f223aaa1
2 files changed
+43
No files matched your search
@@ -178,12 +178,30 @@ func renderTriggers(ts *db.ExplorationStore, evs []TriggerEvent) string {
|
|||||||
b.WriteString(fmt.Sprintf("\n- 意图 #%d 由用户删除,意图内容是:%s、删除原因是:%s。该意图已停止(不再执行),其原因已作为事实挂在该意图上;请据此重新规划。", ev.IntentID, intentSummary(ts, ev.IntentID), ev.Detail))
|
b.WriteString(fmt.Sprintf("\n- 意图 #%d 由用户删除,意图内容是:%s、删除原因是:%s。该意图已停止(不再执行),其原因已作为事实挂在该意图上;请据此重新规划。", ev.IntentID, intentSummary(ts, ev.IntentID), ev.Detail))
|
||||||
default: // "done"
|
default: // "done"
|
||||||
b.WriteString(fmt.Sprintf("\n- 意图 #%d(%s)的 worker 结束,输出结论:%s", ev.IntentID, intentSummary(ts, ev.IntentID), workerOutput(ts, ev.IntentID)))
|
b.WriteString(fmt.Sprintf("\n- 意图 #%d(%s)的 worker 结束,输出结论:%s", ev.IntentID, intentSummary(ts, ev.IntentID), workerOutput(ts, ev.IntentID)))
|
||||||
|
if fids := factIDsYielded(ts, ev.IntentID); fids != "" {
|
||||||
|
b.WriteString(fmt.Sprintf(";本意图新产生的事实 id:%s ", fids))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.WriteString("\n(完整细节可 node_detail / get_worker_output / list_findings 再查。)")
|
b.WriteString("\n(完整细节可 node_detail / get_worker_output / list_findings 再查。)")
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// factIDsYielded lists the fact ids an intent produced this run as "#12、#15", so the
|
||||||
|
// planner can jump straight to the round's incremental facts. Empty (best-effort) when
|
||||||
|
// the intent yielded no facts or the lookup fails.
|
||||||
|
func factIDsYielded(ts *db.ExplorationStore, id int64) string {
|
||||||
|
ids, err := ts.FactsYielded(id)
|
||||||
|
if err != nil || len(ids) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
parts := make([]string, len(ids))
|
||||||
|
for i, fid := range ids {
|
||||||
|
parts[i] = fmt.Sprintf("#%d", fid)
|
||||||
|
}
|
||||||
|
return strings.Join(parts, "、")
|
||||||
|
}
|
||||||
|
|
||||||
// intentSummary reads an intent node's one-line summary (best-effort, "?" on miss).
|
// intentSummary reads an intent node's one-line summary (best-effort, "?" on miss).
|
||||||
func intentSummary(ts *db.ExplorationStore, id int64) string {
|
func intentSummary(ts *db.ExplorationStore, id int64) string {
|
||||||
n, err := ts.GetNode(id)
|
n, err := ts.GetNode(id)
|
||||||
|
|||||||
@@ -768,6 +768,31 @@ func (s *ExplorationStore) Edges(limit int) ([]Edge, error) {
|
|||||||
return out, rows.Err()
|
return out, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FactsYielded returns the ids of fact nodes an intent produced (intent --yields-->
|
||||||
|
// fact), oldest first. Used to spell out the round's incremental facts to the planner
|
||||||
|
// alongside the finished worker's output. Best-effort: returns nil for an intent with
|
||||||
|
// no facts (or a missing one).
|
||||||
|
func (s *ExplorationStore) FactsYielded(intentID int64) ([]int64, error) {
|
||||||
|
rows, err := s.db.Query(`SELECT n.id
|
||||||
|
FROM exploration_edges e
|
||||||
|
JOIN exploration_nodes n ON n.id=e.dst_id AND n.exploration_id=e.exploration_id
|
||||||
|
WHERE e.exploration_id=$1 AND e.src_id=$2 AND e.rel=$3 AND n.kind=$4
|
||||||
|
ORDER BY n.id`, s.expID, intentID, RelYields, KindFact)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var ids []int64
|
||||||
|
for rows.Next() {
|
||||||
|
var id int64
|
||||||
|
if err := rows.Scan(&id); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return ids, rows.Err()
|
||||||
|
}
|
||||||
|
|
||||||
// FindingLineage returns the sub-DAG that leads FROM the exploration root TO the
|
// FindingLineage returns the sub-DAG that leads FROM the exploration root TO the
|
||||||
// given node: the node itself plus all its ancestors (nodes reverse-reachable by
|
// given node: the node itself plus all its ancestors (nodes reverse-reachable by
|
||||||
// following edges backward), and every edge whose both endpoints are in that set.
|
// following edges backward), and every edge whose both endpoints are in that set.
|
||||||
|
|||||||
Reference in new issue
Block a user