2026-06-24 07:27:29 +00:00
|
|
|
from __future__ import annotations
|
2026-06-24 07:09:26 +00:00
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
from meeting_memory.service import MeetingMemoryService
|
2026-06-24 07:09:26 +00:00
|
|
|
|
|
|
|
|
from .registry import ToolContext, ToolRegistry
|
|
|
|
|
|
|
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
def build_meeting_registry() -> ToolRegistry:
|
2026-06-24 07:09:26 +00:00
|
|
|
registry = ToolRegistry()
|
2026-06-24 07:27:29 +00:00
|
|
|
meeting_service = MeetingMemoryService()
|
2026-06-24 07:09:26 +00:00
|
|
|
registry.register(
|
2026-06-24 07:27:29 +00:00
|
|
|
name="store_meeting_memory",
|
|
|
|
|
description="将会议原文写入长期会议记忆系统,抽取实体、事实、指标、行动项,并同步归档与图谱索引。",
|
2026-06-24 07:09:26 +00:00
|
|
|
parameters={
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
2026-06-24 07:27:29 +00:00
|
|
|
"file_path": {
|
2026-06-24 07:09:26 +00:00
|
|
|
"type": "string",
|
2026-06-24 07:27:29 +00:00
|
|
|
"description": "会议转录文本文件路径。与 content 二选一;优先使用 file_path。",
|
2026-06-24 07:09:26 +00:00
|
|
|
},
|
2026-06-24 07:27:29 +00:00
|
|
|
"content": {
|
2026-06-24 07:09:26 +00:00
|
|
|
"type": "string",
|
2026-06-24 07:27:29 +00:00
|
|
|
"description": "直接传入会议原文内容。适用于用户在消息里直接给出文本。",
|
|
|
|
|
},
|
|
|
|
|
"force": {
|
|
|
|
|
"type": "boolean",
|
|
|
|
|
"description": "是否在发现重复会议时强制覆盖。默认 false。",
|
|
|
|
|
},
|
|
|
|
|
"use_multistep_extraction": {
|
|
|
|
|
"type": "boolean",
|
|
|
|
|
"description": "是否使用多阶段抽取流程。默认 true。",
|
2026-06-24 07:09:26 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"additionalProperties": False,
|
|
|
|
|
},
|
2026-06-24 07:27:29 +00:00
|
|
|
handler=lambda ctx, args: _store_meeting_memory(meeting_service, ctx, args),
|
2026-06-24 07:09:26 +00:00
|
|
|
)
|
|
|
|
|
registry.register(
|
2026-06-24 07:27:29 +00:00
|
|
|
name="query_meeting_memory",
|
|
|
|
|
description="查询长期会议记忆中的最近会议、实体关系、关键事实、指标变化、待办事项和上下文摘要。",
|
2026-06-24 07:09:26 +00:00
|
|
|
parameters={
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"query": {"type": "string", "description": "用户查询。"},
|
2026-06-24 07:27:29 +00:00
|
|
|
"top_k": {"type": "integer", "description": "最多返回多少条候选上下文。", "minimum": 1, "maximum": 20},
|
2026-06-24 07:09:26 +00:00
|
|
|
},
|
|
|
|
|
"required": ["query"],
|
|
|
|
|
"additionalProperties": False,
|
|
|
|
|
},
|
2026-06-24 07:27:29 +00:00
|
|
|
handler=lambda ctx, args: _query_meeting_memory(meeting_service, ctx, args),
|
2026-06-24 07:09:26 +00:00
|
|
|
)
|
|
|
|
|
return registry
|
|
|
|
|
|
|
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
def _store_meeting_memory(service: MeetingMemoryService, ctx: ToolContext, args: dict[str, Any]) -> dict[str, Any]:
|
2026-06-24 07:09:26 +00:00
|
|
|
live_event_sink = ctx.session.get("_live_event_sink")
|
|
|
|
|
|
|
|
|
|
def progress_callback(payload: dict[str, Any]) -> None:
|
|
|
|
|
if callable(live_event_sink):
|
|
|
|
|
live_event_sink({"kind": "subagent_progress", "payload": payload})
|
|
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
if bool(ctx.session.get("_cancel_requested")):
|
|
|
|
|
raise RuntimeError("Agent run cancelled by user.")
|
2026-06-24 07:09:26 +00:00
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
result = service.store_meeting_memory(
|
|
|
|
|
file_path=args.get("file_path"),
|
|
|
|
|
content=args.get("content"),
|
|
|
|
|
force=bool(args.get("force", False)),
|
2026-06-24 07:09:26 +00:00
|
|
|
progress_callback=progress_callback,
|
2026-06-24 07:27:29 +00:00
|
|
|
use_multistep_extraction=bool(args.get("use_multistep_extraction", True)),
|
2026-06-24 07:09:26 +00:00
|
|
|
)
|
2026-06-24 07:27:29 +00:00
|
|
|
ctx.session["last_memory_archive_path"] = result.get("archive_path")
|
2026-06-24 07:09:26 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
2026-06-24 07:27:29 +00:00
|
|
|
def _query_meeting_memory(service: MeetingMemoryService, ctx: ToolContext, args: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
result = service.query_meeting_memory(query=str(args["query"]), top_k=int(args.get("top_k") or 5))
|
|
|
|
|
ctx.session["last_memory_query"] = str(args["query"])
|
2026-06-24 07:09:26 +00:00
|
|
|
return result
|