Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ MEMORY_GRAPH_LLM_EXTRACTION_MAX_EPISODES=2
MEMORY_GRAPH_LLM_EXTRACTION_MIN_CONFIDENCE=0.8
MEMORY_GOVERNANCE_AUTO_CLEANUP_ENABLED=true
MEMORY_GOVERNANCE_INTERVAL_SECONDS=86400
MEMORY_GROUP_GRAPH_AUTO_ACCEPT=true
MEMORY_GROUP_GRAPH_CO_PARTICIPATION_EDGES=false
MEMORY_GROUP_GRAPH_AUTO_REVIEW_BATCH=200
MEMORY_GROUP_RELATION_REVIEW_RETENTION_DAYS=14
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ENABLED=true
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_LLM_ENABLED=true
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_INTERVAL_SECONDS=3600
Expand All @@ -141,8 +145,17 @@ MEMORY_GROUP_GRAPH_AUTO_EXTRACT_MAX_WINDOWS_PER_SESSION=20
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_WINDOW_SIZE=50
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_TIME_BUDGET_SECONDS=180
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ROLES=scheduler
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED=true
# Group relationship targets come from imported memory events and live group
# observations. The legacy SDK history sync before each tick is opt-in.
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED=false
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_MAX_MESSAGES=200
# LLM window pass: fixed per-window timeout, queued per window, bounded per tick.
# tier-1 (non-reasoning) answers a 50-message window in 10-16s; reasoning tiers time out.
MEMORY_GROUP_GRAPH_LLM_MODEL_TIER=tier-1
MEMORY_GROUP_GRAPH_LLM_TIMEOUT_SECONDS=60
MEMORY_GROUP_GRAPH_LLM_JOBS_PER_TICK=6
MEMORY_GROUP_GRAPH_LLM_JOB_MAX_ATTEMPTS=3
MEMORY_LLM_EXTRACTION_JOB_STALE_DAYS=30
MEMORY_NEEDS_REVIEW_RETENTION_DAYS=30
MEMORY_REJECTED_RETENTION_DAYS=7
MEMORY_AUTO_EXPIRE_DAYS=180
Expand Down Expand Up @@ -409,6 +422,10 @@ COMPOSE_MEMORY_GRAPH_LLM_EXTRACTION_MAX_EPISODES=2
COMPOSE_MEMORY_GRAPH_LLM_EXTRACTION_MIN_CONFIDENCE=0.8
COMPOSE_MEMORY_GOVERNANCE_AUTO_CLEANUP_ENABLED=true
COMPOSE_MEMORY_GOVERNANCE_INTERVAL_SECONDS=86400
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_ACCEPT=true
COMPOSE_MEMORY_GROUP_GRAPH_CO_PARTICIPATION_EDGES=false
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_REVIEW_BATCH=200
COMPOSE_MEMORY_GROUP_RELATION_REVIEW_RETENTION_DAYS=14
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ENABLED=true
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_LLM_ENABLED=true
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_INTERVAL_SECONDS=3600
Expand All @@ -418,8 +435,13 @@ COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_MAX_WINDOWS_PER_SESSION=20
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_WINDOW_SIZE=50
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_TIME_BUDGET_SECONDS=180
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ROLES=scheduler
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED=true
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED=false
COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_MAX_MESSAGES=200
COMPOSE_MEMORY_GROUP_GRAPH_LLM_MODEL_TIER=tier-1
COMPOSE_MEMORY_GROUP_GRAPH_LLM_TIMEOUT_SECONDS=60
COMPOSE_MEMORY_GROUP_GRAPH_LLM_JOBS_PER_TICK=6
COMPOSE_MEMORY_GROUP_GRAPH_LLM_JOB_MAX_ATTEMPTS=3
COMPOSE_MEMORY_LLM_EXTRACTION_JOB_STALE_DAYS=30
COMPOSE_MEMORY_NEEDS_REVIEW_RETENTION_DAYS=30
COMPOSE_MEMORY_REJECTED_RETENTION_DAYS=7
COMPOSE_MEMORY_AUTO_EXPIRE_DAYS=180
Expand Down
31 changes: 30 additions & 1 deletion app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,18 @@ def guarded_dotenv_settings() -> dict[str, Any]:
memory_governance_auto_cleanup_enabled: bool = True
memory_governance_interval_seconds: float = Field(default=86_400.0, gt=0)
memory_group_graph_auto_accept: bool = True
# Same-window co-participation pairs mostly mean "both were online"; the
# rule layer relies on quoted replies, @-mentions and explicit reply
# prefixes instead. Opt in to keep writing co_participated edges.
memory_group_graph_co_participation_edges: bool = False
# Pending model relations are promoted automatically once the accepted
# graph corroborates them (same term used by another accepted relation, or
# an accepted direct edge between the two people) or once they repeat on a
# second day; this is how many candidates one tick re-checks.
memory_group_graph_auto_review_batch: int = Field(default=200, ge=0, le=1000)
# A model relation that is neither corroborated nor repeated within this
# window is expired by governance instead of waiting for a reviewer.
memory_group_relation_review_retention_days: int = Field(default=14, ge=1)
memory_group_graph_auto_extract_enabled: bool = True
memory_group_graph_auto_extract_llm_enabled: bool = True
memory_group_graph_auto_extract_interval_seconds: float = Field(default=3_600.0, gt=0)
Expand All @@ -433,7 +445,24 @@ def guarded_dotenv_settings() -> dict[str, Any]:
memory_group_graph_auto_extract_window_size: int = Field(default=50, ge=10, le=100)
memory_group_graph_auto_extract_time_budget_seconds: int = Field(default=180, ge=5, le=180)
memory_group_graph_auto_extract_roles: str = "scheduler"
memory_group_graph_auto_extract_sync_enabled: bool = True
# Per-window LLM timeout. The time budget decides how many windows fit in a
# run; it is never divided across windows any more.
memory_group_graph_llm_timeout_seconds: int = Field(default=60, ge=5, le=600)
# Model tier for the window extraction prompt. Structured JSON over a short
# transcript is a fast-model task; reasoning tiers were measured at >60s per
# window on the production gateway versus 10-16s for the non-reasoning tier.
memory_group_graph_llm_model_tier: str = "tier-1"
# The scheduler tick queues one durable LLM job per window and processes at
# most this many per tick with the full timeout each. 0 disables the pass.
memory_group_graph_llm_jobs_per_tick: int = Field(default=6, ge=0, le=50)
memory_group_graph_llm_job_max_attempts: int = Field(default=3, ge=1, le=10)
# Governance marks extraction jobs that stayed pending/failed this long as
# dead so a disabled drain cannot leave them queued forever.
memory_llm_extraction_job_stale_days: int = Field(default=30, ge=1)
# The pre-tick SDK history sync only works for the legacy account-wide
# wxbot connection; live groups already stream into
# plugin_wxbot_group_observations, which the tick now reads directly.
memory_group_graph_auto_extract_sync_enabled: bool = False
memory_group_graph_auto_extract_sync_max_messages: int = Field(default=200, ge=20, le=500)
memory_needs_review_retention_days: int = Field(default=30, ge=1)
memory_rejected_retention_days: int = Field(default=7, ge=1)
Expand Down
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ x-app-env: &app-env
MEMORY_GRAPH_LLM_EXTRACTION_MIN_CONFIDENCE: ${COMPOSE_MEMORY_GRAPH_LLM_EXTRACTION_MIN_CONFIDENCE:-0.8}
MEMORY_GOVERNANCE_AUTO_CLEANUP_ENABLED: ${COMPOSE_MEMORY_GOVERNANCE_AUTO_CLEANUP_ENABLED:-true}
MEMORY_GOVERNANCE_INTERVAL_SECONDS: ${COMPOSE_MEMORY_GOVERNANCE_INTERVAL_SECONDS:-86400}
MEMORY_GROUP_GRAPH_AUTO_ACCEPT: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_ACCEPT:-true}
MEMORY_GROUP_GRAPH_CO_PARTICIPATION_EDGES: ${COMPOSE_MEMORY_GROUP_GRAPH_CO_PARTICIPATION_EDGES:-false}
MEMORY_GROUP_GRAPH_AUTO_REVIEW_BATCH: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_REVIEW_BATCH:-200}
MEMORY_GROUP_RELATION_REVIEW_RETENTION_DAYS: ${COMPOSE_MEMORY_GROUP_RELATION_REVIEW_RETENTION_DAYS:-14}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ENABLED: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ENABLED:-true}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_LLM_ENABLED: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_LLM_ENABLED:-true}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_INTERVAL_SECONDS: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_INTERVAL_SECONDS:-3600}
Expand All @@ -142,8 +146,13 @@ x-app-env: &app-env
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_WINDOW_SIZE: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_WINDOW_SIZE:-50}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_TIME_BUDGET_SECONDS: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_TIME_BUDGET_SECONDS:-180}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ROLES: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_ROLES:-scheduler}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED:-true}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_ENABLED:-false}
MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_MAX_MESSAGES: ${COMPOSE_MEMORY_GROUP_GRAPH_AUTO_EXTRACT_SYNC_MAX_MESSAGES:-200}
MEMORY_GROUP_GRAPH_LLM_MODEL_TIER: ${COMPOSE_MEMORY_GROUP_GRAPH_LLM_MODEL_TIER:-tier-1}
MEMORY_GROUP_GRAPH_LLM_TIMEOUT_SECONDS: ${COMPOSE_MEMORY_GROUP_GRAPH_LLM_TIMEOUT_SECONDS:-60}
MEMORY_GROUP_GRAPH_LLM_JOBS_PER_TICK: ${COMPOSE_MEMORY_GROUP_GRAPH_LLM_JOBS_PER_TICK:-6}
MEMORY_GROUP_GRAPH_LLM_JOB_MAX_ATTEMPTS: ${COMPOSE_MEMORY_GROUP_GRAPH_LLM_JOB_MAX_ATTEMPTS:-3}
MEMORY_LLM_EXTRACTION_JOB_STALE_DAYS: ${COMPOSE_MEMORY_LLM_EXTRACTION_JOB_STALE_DAYS:-30}
MEMORY_NEEDS_REVIEW_RETENTION_DAYS: ${COMPOSE_MEMORY_NEEDS_REVIEW_RETENTION_DAYS:-30}
MEMORY_REJECTED_RETENTION_DAYS: ${COMPOSE_MEMORY_REJECTED_RETENTION_DAYS:-7}
MEMORY_AUTO_EXPIRE_DAYS: ${COMPOSE_MEMORY_AUTO_EXPIRE_DAYS:-180}
Expand Down
71 changes: 71 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,32 @@ export type GroupGraphEdge = {
acceptance_score?: number | null;
acceptance_reason?: string | null;
evidence_dates?: string[];
evidence_day_count?: number;
/** `memory_event`, `observation` or `mixed`: which table backs this edge's evidence. */
evidence_source?: string;
observation_count?: number;
first_seen_date?: string | null;
last_seen_date?: string | null;
/** When the relation row was written, as opposed to when the messages happened. */
extracted_at?: string | null;
/** Accumulated interaction strength in [0, 1] (direct signals + distinct days). */
strength?: number | null;
signals?: Record<string, number> | null;
/** Fact ids folded into this edge when a symmetric relation was stored in both directions. */
mirror_ids?: string[];
history?: unknown[];
};

export type GroupGraphObservationEvidence = {
id: number;
session_id?: string;
sender_label?: string | null;
sender_is_technical?: boolean;
occurred_at?: string | null;
source?: string;
[key: string]: unknown;
};

export type GroupGraphResponse = {
schema?: {
version?: string;
Expand All @@ -527,6 +550,14 @@ export type GroupGraphResponse = {
nodes?: number;
edges?: number;
};
/** Server-side paging info: `total` matched the filters, `truncated` means the row cap cut some. */
page?: {
limit?: number;
total?: number;
truncated?: boolean;
order?: string;
next_cursor?: string | null;
};
generated_from?: string[];
};

Expand Down Expand Up @@ -566,24 +597,49 @@ export type GroupGraphEdgeEvidenceResponse = {
updated_at?: string | null;
valid_at?: string | null;
invalid_at?: string | null;
/** Fact row timestamp, i.e. when the relation was extracted. */
extracted_at?: string | null;
first_observed_at?: string | null;
last_observed_at?: string | null;
};
evidence_ids?: {
memory_item_ids?: Array<string | number>;
event_ids?: Array<string | number>;
episode_ids?: Array<string | number>;
observation_ids?: Array<string | number>;
};
evidence_counts?: {
memory_items?: number;
events?: number;
episodes?: number;
observations?: number;
evidence_days?: number;
[key: string]: number | undefined;
};
evidence_source?: string;
evidence_dates?: string[];
memory_items?: GroupGraphEdgeEvidenceEntity[];
events?: GroupGraphEdgeEvidenceEntity[];
episodes?: GroupGraphEdgeEvidenceEntity[];
observations?: GroupGraphObservationEvidence[];
/** Why the pipeline believes this edge: method, signals, policy, model rationale. No chat text. */
judgement?: GroupGraphEdgeJudgement;
[key: string]: unknown;
};

export type GroupGraphEdgeJudgement = {
extraction_method?: string;
signals?: Record<string, number>;
policy?: string;
acceptance_status?: string;
reviewed_by?: string;
review_reason?: string;
/** The model's own one-line rationale (a paraphrase, never a message). */
model_reason?: string;
day_count?: number;
strength?: number | null;
};

export type GroupGraphQuery = {
tenant_id: string;
channel?: string;
Expand Down Expand Up @@ -767,8 +823,16 @@ export type GroupGraphWindowExtractionRequest = {
cursor_event_id?: number;
dry_run?: boolean;
include_llm?: boolean;
/** Per-window model timeout in seconds (server clamps to 5–180). */
llm_timeout_seconds?: number;
};

/**
* `inline` waits for the model inside the request; `enqueue` only runs the rule
* layer and leaves one LLM job per window for the scheduler.
*/
export type GroupGraphLlmMode = "inline" | "enqueue";

export type GroupGraphWindowCatchupRequest = {
tenant_id: string;
channel?: string;
Expand All @@ -782,6 +846,8 @@ export type GroupGraphWindowCatchupRequest = {
dry_run?: boolean;
time_budget_seconds?: number;
include_llm?: boolean;
llm_timeout_seconds?: number;
llm_mode?: GroupGraphLlmMode;
};

export type GroupGraphWindowExtractionResponse = {
Expand Down Expand Up @@ -848,6 +914,11 @@ export type GroupGraphWindowCatchupResponse = {
more_remain?: boolean;
stop_reason?: string;
generated_from?: string[];
/** Windows whose LLM pass was handed to the scheduler (enqueue mode). */
llm_jobs_enqueued?: number;
llm_failures?: number;
signal_counts?: Record<string, number>;
unresolved_targets?: number;
[key: string]: unknown;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function RelationshipActionPanel(controller: RelationshipGraphController)
<small>仅演练</small>
</label>
<em>当前游标 {windowExtractionCursor}</em>
<em>单窗口抽取会等模型最多 45 秒;追平只跑规则,语义部分排成任务由调度进程每小时处理。</em>
</div>
<RelationshipUnavailableReset />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
displayEdgeSource,
displayEdgeTarget,
evidenceCountsLabel,
evidenceObservedRange,
evidenceSourceLabel,
formatConfidence,
formatTimestamp,
graphNodeLabel,
Expand All @@ -19,6 +21,7 @@ import {
edgeCanReturnToReview,
evidenceQuality,
extractionMethodLabel,
judgementSummary,
counterpartEdges,
firstMemoryItemId,
formatAcceptanceScore,
Expand Down Expand Up @@ -169,6 +172,7 @@ export function RelationshipUnavailableReset() {
export function RelationshipDetailPanel(controller: RelationshipGraphController) {
const {
selection,
setSelection,
selectedNode,
selectedEdge,
nodesById,
Expand All @@ -185,6 +189,7 @@ export function RelationshipDetailPanel(controller: RelationshipGraphController)
const replaceableEdges = selectedEdge
? counterpartEdges(selectedEdge, [...(graphEdges || []), ...(pendingEdges || [])])
: [];
const judgement = judgementSummary(evidence?.judgement);

return (
<section className="panel relationship-detail-panel">
Expand All @@ -193,6 +198,16 @@ export function RelationshipDetailPanel(controller: RelationshipGraphController)
<p className="section-kicker">详情</p>
<h3>{selection ? (selection.kind === "node" ? "这个人" : "这条互动") : "点一个人或一条线"}</h3>
</div>
{selection && (
<button
type="button"
className="button button-secondary button-compact"
onClick={() => setSelection(null)}
title="回到整张图(也可以点空白处或按 Esc)"
>
取消选中
</button>
)}
</div>
{!selection && (
<div className="relationship-empty is-compact">
Expand Down Expand Up @@ -359,10 +374,39 @@ export function RelationshipDetailPanel(controller: RelationshipGraphController)
<>
<dl className="relationship-detail-list">
<div><dt>证据来源</dt><dd>{evidenceCountsLabel(evidence)}</dd></div>
{evidenceSourceLabel(evidence.evidence_source) && (
<div><dt>证据类型</dt><dd>{evidenceSourceLabel(evidence.evidence_source)}</dd></div>
)}
<div><dt>审核状态</dt><dd><span className={acceptanceClass(evidence.edge?.acceptance_status)}>{acceptanceStatusLabel(evidence.edge?.acceptance_status)}</span></dd></div>
<div><dt>首次出现</dt><dd>{formatTimestamp(evidence.edge?.first_seen)}</dd></div>
<div><dt>最近出现</dt><dd>{formatTimestamp(evidence.edge?.last_seen)}</dd></div>
{evidenceObservedRange(evidence) && (
<div><dt>群消息时间</dt><dd>{evidenceObservedRange(evidence)}</dd></div>
)}
{(evidence.evidence_counts?.evidence_days ?? 0) > 0 && (
<div><dt>覆盖天数</dt><dd>{evidence.evidence_counts?.evidence_days}</dd></div>
)}
</dl>
{judgement && (
<div className="relationship-judgement" data-testid="relationship-judgement">
<h4>怎么判定的</h4>
<dl className="relationship-detail-list">
<div><dt>抽取方式</dt><dd>{judgement.method}</dd></div>
{judgement.signals.length > 0 && (
<div><dt>信号</dt><dd>{judgement.signals.join(",")}</dd></div>
)}
{judgement.policyText && (
<div><dt>通过依据</dt><dd>{judgement.policyText}</dd></div>
)}
{judgement.reviewerText && (
<div><dt>判定者</dt><dd>{judgement.reviewerText}</dd></div>
)}
{judgement.modelReason && (
<div><dt>模型理由</dt><dd>{judgement.modelReason}<small className="muted-copy"> 模型自己的转述,不是聊天原文;主题词可能是模型归纳的(如把成员名归为组合名),按"群消息时间"去原聊天里核对。</small></dd></div>
)}
</dl>
</div>
)}
<TechnicalDetails summary="查看证据技术详情" value={evidence} />
</>
)}
Expand Down
Loading
Loading