Commit 3b9a26c5 by wangzhiyang

feat(meeting_minutes): 新增完整会议纪要处理流水线及Agent工具

- 注册run_pipeline为AgentHub工具,支持智能体调用全流程服务
- 新增状态日志收集模块,实时同步处理进度至会话日志
- 统一纪要生成提示词的缺失占位符为「未提及」
- 新增会议纪要Markdown格式校验逻辑,规范输出格式
- 更新SKILL.md文档,补充Agent Tool调用方式说明
1 parent 9049f2bd
...@@ -42,6 +42,14 @@ async def lifespan(app: FastAPI): ...@@ -42,6 +42,14 @@ async def lifespan(app: FastAPI):
im_service=im_service, im_service=im_service,
) )
# 注册会议纪要管道工具
from skills.meeting_minutes.scripts.pipeline import run_pipeline
agent_hub_instance.tool_manager.register_tool(
run_pipeline,
group="meeting_minutes",
description="执行会议纪要完整流程:接收音频 URL → Fun-ASR 转写 → Qwen3.6-plus 生成纪要 → 导出 docx → 上传 OSS 返回下载链接。各步骤状态会写入会话日志。",
)
yield yield
if agent_hub_instance: if agent_hub_instance:
......
...@@ -114,7 +114,33 @@ CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", " ...@@ -114,7 +114,33 @@ CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "
### 生产调用方式 ### 生产调用方式
生产环境统一使用 Python API 模式(内存流,不写磁盘): **方式一:AgentHub Tool 模式(推荐)**
`run_pipeline` 已注册为 ToolManager 工具(`meeting_minutes` 组),meeting agent 的 LLM 可直接调用:
```python
# 在 main.py 中自动注册
from skills.meeting_minutes.scripts.pipeline import run_pipeline
agent_hub_instance.tool_manager.register_tool(
run_pipeline,
group="meeting_minutes",
description="执行会议纪要完整流程...",
)
```
Tool 执行时各步骤状态通过 `_log_tool_statuses()` 自动写入会话对话日志:
```
[meeting_minutes] ... Fun-ASR 转写中...
[meeting_minutes] OK 转写完成, 82 个句子, 1437 字符
[meeting_minutes] ... Qwen3.6-plus 生成会议纪要中...
[meeting_minutes] OK 纪要生成完成, Markdown 长度=1403
[meeting_minutes] OK 全部完成, 下载链接: http://...
```
管家 Agent 通过读取会话历史消息,即可感知会议纪要处理进度。
**方式二:Python API 直接调用(内存流,不写磁盘)**
```python ```python
from skills.meeting_minutes.scripts.transcriber import transcribe_audio from skills.meeting_minutes.scripts.transcriber import transcribe_audio
......
"""
会议纪要处理管道。
统一入口:接收音频 URL,依次执行转写 → 纪要生成 → docx 导出 → OSS 上传。
每个步骤通过 StatusCollector 产出结构化状态消息,供写入会话 conversation。
"""
import logging
import sys
from pathlib import Path
from typing import Optional
# 确保能导入同目录模块
_SCRIPT_DIR = Path(__file__).parent
if str(_SCRIPT_DIR) not in sys.path:
sys.path.insert(0, str(_SCRIPT_DIR))
from transcriber import transcribe_audio
from markdown_generator import generate_meeting_minutes
from format_converter import convert_markdown_to_bytes
from oss_uploader import upload_bytes_to_oss
from status_logger import StatusCollector
logger = logging.getLogger(__name__)
def run_pipeline(
audio_url: str,
status_callback: Optional[callable] = None,
language_hints: str = '["zh", "en"]',
) -> dict:
"""
执行完整的会议纪要处理管道。
Args:
audio_url: 音频文件的公网可访问 URL
status_callback: 可选回调,每步状态变化时调用 callback(StepStatus)
language_hints: Fun-ASR 语言提示
Returns:
dict: {
"success": bool,
"statuses": list[dict], # 所有步骤的状态记录
"transcript_text": str,
"markdown": str,
"download_url": str, # 仅成功时
"error": str, # 仅失败时
}
"""
sc = StatusCollector(on_status=status_callback)
# Step 1: 音频转写
sc.running("transcribing", "Fun-ASR 转写中...", audio_url=audio_url)
transcribe_result = transcribe_audio(audio_url, language_hints=language_hints)
if not transcribe_result["success"]:
sc.error("transcribing", f"转写失败: {transcribe_result['error']}")
return {
"success": False,
"statuses": sc.to_dicts(),
"error": transcribe_result["error"],
}
transcript_text = transcribe_result["transcript_text"]
sentence_count = transcribe_result.get("sentence_count", 0)
sc.done("transcribing", f"转写完成, {sentence_count} 个句子, {len(transcript_text)} 字符",
sentence_count=sentence_count, char_count=len(transcript_text))
# Step 2: 生成纪要
sc.running("generating", "Qwen3.6-plus 生成会议纪要中...")
minutes_result = generate_meeting_minutes(transcript_text)
if not minutes_result["success"]:
sc.error("generating", f"纪要生成失败: {minutes_result['error']}")
return {
"success": False,
"statuses": sc.to_dicts(),
"transcript_text": transcript_text,
"error": minutes_result["error"],
}
markdown = minutes_result["markdown"]
sc.done("generating", f"纪要生成完成, Markdown 长度={len(markdown)}",
markdown_length=len(markdown))
# Step 3: 导出 docx + 上传 OSS
sc.running("exporting", "导出 docx 并上传 OSS...")
docx_result = convert_markdown_to_bytes(markdown_content=markdown, output_format="docx")
if not docx_result["success"]:
sc.error("exporting", f"docx 导出失败: {docx_result['error']}")
return {
"success": False,
"statuses": sc.to_dicts(),
"transcript_text": transcript_text,
"markdown": markdown,
"error": docx_result["error"],
}
upload_result = upload_bytes_to_oss(
data=docx_result["data"],
filename=docx_result["filename"],
oss_dir="meeting-minutes",
content_type=docx_result["content_type"],
)
if not upload_result["success"]:
sc.error("uploading", f"OSS 上传失败: {upload_result['error']}")
return {
"success": False,
"statuses": sc.to_dicts(),
"transcript_text": transcript_text,
"markdown": markdown,
"error": upload_result["error"],
}
download_url = upload_result["url"]
sc.done("done", f"全部完成, 下载链接: {download_url}",
download_url=download_url, file_size=len(docx_result["data"]))
return {
"success": True,
"statuses": sc.to_dicts(),
"transcript_text": transcript_text,
"markdown": markdown,
"download_url": download_url,
}
def run_pipeline_sync(
audio_url: str,
language_hints: str = '["zh", "en"]',
) -> dict:
"""
同步执行管道(无回调,适合 CLI 模式)。
"""
def _print_status(s):
print(f"[{s.step}] {s.status.upper()}: {s.message}")
return run_pipeline(audio_url, status_callback=_print_status, language_hints=language_hints)
# 支持独立运行
if __name__ == "__main__":
if len(sys.argv) < 2:
print("用法: python pipeline.py <audio_file_url> [language_hints]")
print("示例: python pipeline.py https://example.com/audio.mp3")
sys.exit(1)
audio_url = sys.argv[1]
language_hints = sys.argv[2] if len(sys.argv) > 2 else '["zh", "en"]'
logging.basicConfig(level=logging.INFO)
result = run_pipeline_sync(audio_url, language_hints)
if result["success"]:
print(f"\n下载链接: {result['download_url']}")
else:
print(f"\n失败: {result['error']}", file=sys.stderr)
sys.exit(1)
\ No newline at end of file \ No newline at end of file
"""
管道状态日志工具。
提供 StepStatus 数据类和格式化函数,供 pipeline 在执行过程中
产出结构化状态消息。这些消息最终写入会话 conversation,管家 Agent
可通过读取历史消息感知会议纪要处理进度。
"""
import time
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class StepStatus:
"""单个步骤的状态记录。"""
step: str # 步骤名称: transcribing / generating / exporting / uploading / done
status: str # running / done / error
message: str # 人类可读的状态描述
detail: dict = field(default_factory=dict) # 附加信息(句子数、文件大小、URL 等)
timestamp: float = field(default_factory=time.time)
def to_message(self) -> str:
"""格式化为会话消息文本。"""
icon = {"running": "...", "done": "OK", "error": "FAIL"}.get(self.status, "")
return f"[meeting_minutes] {icon} {self.message}"
def to_dict(self) -> dict:
return {
"step": self.step,
"status": self.status,
"message": self.message,
"detail": self.detail,
"timestamp": self.timestamp,
}
class StatusCollector:
"""收集管道各步骤的状态消息。支持注册回调函数用于写入会话。"""
def __init__(self, on_status: Optional[callable] = None):
self.statuses: list[StepStatus] = []
self._on_status = on_status
def add(self, step: str, status: str, message: str, **detail) -> StepStatus:
s = StepStatus(step=step, status=status, message=message, detail=detail)
self.statuses.append(s)
if self._on_status:
self._on_status(s)
return s
def running(self, step: str, message: str, **detail) -> StepStatus:
return self.add(step, "running", message, **detail)
def done(self, step: str, message: str, **detail) -> StepStatus:
return self.add(step, "done", message, **detail)
def error(self, step: str, message: str, **detail) -> StepStatus:
return self.add(step, "error", message, **detail)
def to_messages(self) -> list[str]:
return [s.to_message() for s in self.statuses]
def to_dicts(self) -> list[dict]:
return [s.to_dict() for s in self.statuses]
def is_success(self) -> bool:
return all(s.status != "error" for s in self.statuses)
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!