feat(agent): 任务内主 Agent 支持多会话,可切换且上下文可重置
主 Agent 会话原为一个任务恒定单例,对话历史随 transcript 只增不减、 上下文越滚越大。现引入会话分段(seq):新建会话切一个干净的 transcript 段,任务的图谱/资产/目标共享保留,旧段以只读历史随时切回查看。 - db: 新增 main_sessions 表与 activity.main_seg 列(ALTER ADD COLUMN IF NOT EXISTS 兼容旧库);ActivitySessionFilter 按段过滤(段 0 兼容 旧 NULL 行);新增 CurrentMainSeg/ListMainSessions/NewMainSession; per-session token 统计按 main:<seg> 分段 - agent: MainAgent.Chat 增加 mainSeg,transcript SessionID 分段 (段 0 保留旧名 exp<id>-main 兼容既有对话) - server: parseActivitySession 支持 main:<seq>;chat handler 每轮 stamp 当前段;新增 GET main-sessions / POST main-session/new - web: 主 Agent 分组渲染多段会话,支持新建(轻确认)、切换、旧段只读
This commit is contained in:
1 parent
9ad88d5ce8
commit
ee3eb22433
8 files changed
+360
-51
No files matched your search
@@ -309,11 +309,20 @@ CREATE TABLE IF NOT EXISTS activity (
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
ALTER TABLE activity ADD COLUMN IF NOT EXISTS metadata JSONB NOT NULL DEFAULT '{}';
|
||||
-- main_seg segments the main-agent session into resettable conversations: a new
|
||||
-- main session bumps the segment so its transcript + activity start clean while the
|
||||
-- task's graph/assets/goal are untouched. NULL == legacy rows == segment 0 (the
|
||||
-- original session). Only worker='mainagent' rows carry it.
|
||||
ALTER TABLE activity ADD COLUMN IF NOT EXISTS main_seg INTEGER;
|
||||
CREATE INDEX IF NOT EXISTS idx_act_node ON activity(exploration_id, node_id, id);
|
||||
CREATE INDEX IF NOT EXISTS idx_act_since ON activity(exploration_id, id);
|
||||
-- Main/Plan history pages filter by worker (both carry NULL node_id, so idx_act_node
|
||||
-- can't distinguish them); this covers reverse pagination of those sessions.
|
||||
CREATE INDEX IF NOT EXISTS idx_act_worker ON activity(exploration_id, worker, id);
|
||||
-- Main-session pages filter by segment on top of worker='mainagent'; this partial
|
||||
-- index covers reverse pagination within one segment.
|
||||
CREATE INDEX IF NOT EXISTS idx_act_main_seg ON activity(exploration_id, main_seg, id)
|
||||
WHERE worker='mainagent';
|
||||
-- Task-list polls aggregate result usage and find the latest event repeatedly.
|
||||
-- Cover the token columns for index-only aggregation and the timestamp order for
|
||||
-- per-exploration latest-activity lookups.
|
||||
@@ -322,6 +331,18 @@ CREATE INDEX IF NOT EXISTS idx_act_result_usage ON activity(exploration_id)
|
||||
WHERE kind='result';
|
||||
CREATE INDEX IF NOT EXISTS idx_act_latest ON activity(exploration_id, created_at DESC);
|
||||
|
||||
-- main_sessions records the resettable main-agent conversation segments of a task.
|
||||
-- Segment 0 (the original session) is implicit and never stored; this table holds
|
||||
-- only the extra segments created by "新建会话" (seq >= 1). The current segment is
|
||||
-- MAX(seq) or 0. Each segment gets its own transcript file + activity slice; the
|
||||
-- task's exploration graph/assets/goal are shared and never reset.
|
||||
CREATE TABLE IF NOT EXISTS main_sessions (
|
||||
exploration_id BIGINT NOT NULL REFERENCES explorations(id) ON DELETE CASCADE,
|
||||
seq INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (exploration_id, seq)
|
||||
);
|
||||
|
||||
-- =====================================================================
|
||||
-- C. LLM profiles
|
||||
-- =====================================================================
|
||||
|
||||
Reference in new issue
Block a user