feat: add RtpResearcherAgent for RTP/real-time transport research

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 13:35:04 +08:00
co-authored by Claude Sonnet 4.6
parent 0b8e84993e
commit e91fec95b3
2 changed files with 83 additions and 0 deletions
@@ -0,0 +1,50 @@
from __future__ import annotations
import logging
import re
from rockchip_agents.agents.developer import DeveloperAgent
from rockchip_agents.core.queue import Task
logger = logging.getLogger(__name__)
RTP_RESEARCHER_SYSTEM = """你是 RTP 实时传输协议专项调研员,专注于 RK3588 平台的媒体实时传输优化。
调研重点:
- RTP/RTSP 协议栈延迟分析(端到端 < 100ms 目标)
- RK3588 媒体通路:ISP → 编码器 → 网络发送的延迟分解
- 内核网络栈优化:SO_PRIORITY、TX queue、中断亲和性
- 硬件编码器(MPP)与软件 RTP 封装的同步机制
输出标签(写入系统记忆):
- [调研报告] __research__.rtp.summary=综合调研结论
- [调研报告] __research__.rtp.bottlenecks=当前瓶颈分析
- [调研报告] __research__.rtp.next_steps=建议优化步骤(逗号分隔)
- [调研报告] __research__.rtp.updated_at=调研时间
调研完成后,如有明确优化方向,输出:
- [优化任务] os-engineer: <具体优化任务描述>
- [优化任务] dev-kernel: <具体内核优化任务描述>
要求:
- 先用 fetch 工具查阅最新 RTP/RTCP 规范、RK3588 BSP 文档
- 输出结构化 Markdown 报告,含实测数据或参考基准
"""
class RtpResearcherAgent(DeveloperAgent):
"""RTP 实时传输协议专项调研 Agent。"""
def _build_context(self, task: Task) -> str:
return super()._build_context(task) + "\n" + RTP_RESEARCHER_SYSTEM
def _extract_research_facts(self, report_text: str) -> None:
"""解析 [调研报告] 标签,写入 ProjectMemory __research__ facts。"""
for m in re.finditer(r"\[调研报告\]\s+(__research__\.[\w.]+)=(.+)", report_text):
key_full = m.group(1).strip()
value = m.group(2).strip()[:500]
_, _, sub_key = key_full.partition(".")
try:
self._memory.set_fact("__research__", sub_key, value, role="rtp-researcher")
except Exception as e:
logger.warning("调研报告写入失败 %s: %s", key_full, e)
+33
View File
@@ -0,0 +1,33 @@
from __future__ import annotations
import pytest
from unittest.mock import MagicMock
from rockchip_agents.config import AgentsConfig, ClaudeConfig, SchedulerConfig, FeishuConfig
def _make_config():
return AgentsConfig(
projects={},
scheduler=SchedulerConfig(),
claude=ClaudeConfig(api_key="fake"),
feishu=FeishuConfig(),
devices={},
)
def test_rtp_researcher_system_contains_keywords():
from rockchip_agents.agents.rtp_researcher import RTP_RESEARCHER_SYSTEM
for kw in ["RTP", "实时", "延迟", "RK3588"]:
assert kw in RTP_RESEARCHER_SYSTEM, f"缺少关键词: {kw}"
def test_rtp_researcher_extract_research_facts(tmp_path):
"""解析 [调研报告] 标签写入 __research__.rtp.* facts。"""
from rockchip_agents.agents.rtp_researcher import RtpResearcherAgent
from rockchip_agents.tools.project_memory import ProjectMemory
mem = ProjectMemory(db_path=tmp_path / "m.db")
agent = RtpResearcherAgent(_make_config(), memory=mem)
report = "[调研报告] __research__.rtp.summary=RTP延迟瓶颈在内核调度\n[调研报告] __research__.rtp.bottlenecks=中断亲和性未设置"
agent._extract_research_facts(report)
facts = mem.get_facts("__research__")
assert facts.get("rtp.summary") == "RTP延迟瓶颈在内核调度"
assert facts.get("rtp.bottlenecks") == "中断亲和性未设置"