feat(ai_agent): 新增openclaw_hermes混合AI适配器 新增OpenClawHermesAdapter适配器,结合Hermes记忆功能和OpenClaw执行能力, 实现AI问答流程中的记忆召回、执行操作和记忆存储的完整闭环。 同时更新NoopAdapter提示信息,添加新的模型提供商选项。 feat(business): 新增考勤、工作报告和风险事件业务模型 新增AttendanceRecord、WorkReport、RiskEvent和LegacySyncRun四个业务模型, 扩展业务领域注册表,支持考勤管理、工作报告生成和风险事件跟踪等核心业务功能。 feat(reports): 实现考勤汇总和工作日报周报生成功能 新增attendance_summary方法用于统计每日考勤情况, 新增generate_work_report方法用于生成日/周经营报告, 包含任务完成情况、待处理事项和风险指标等综合信息。 feat(risk): 扩展风险管理API端点和供应商风险检测 新增供应商风险查询端点和风险事件管理端点, 提供风险事件列表查询和自动生成功能, 增强供应商风险评估能力。 feat(feishu): 添加考勤查询命令和风险摘要增强 集成考勤汇总查询功能到飞书命令系统, 在风险摘要中添加供应商风险和开放风险事件统计, 丰富日常经营管理信息展示。 refactor(service): 优化业务服务数据验证和类型转换 重构_model_payload函数实现数据验证和类型转换, 添加列值类型强制转换逻辑,提高API数据处理的准确性和安全性。 build(deps): 添加postgresql数据库驱动依赖 在Dockerfile中添加psycopg[binary]==3.2.3依赖包, 支持PostgreSQL数据库连接和操作。 chore(config): 更新.gitignore文件排除备份和迁移目录 在.gitignore中添加AGENTS.md.bak-*和migration/目录排除规则, 避免备份文件和本地迁移工作区被提交到版本控制系统。 ```
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from typing import Any
|
|
|
|
from app.core.config import Settings
|
|
from app.modules.ai_agent import adapters
|
|
|
|
|
|
class DummyResponse:
|
|
def __init__(self, data: dict[str, Any], status_code: int = 200):
|
|
self._data = data
|
|
self.status_code = status_code
|
|
self.text = str(data)
|
|
|
|
def json(self) -> dict[str, Any]:
|
|
return self._data
|
|
|
|
|
|
class DummyClient:
|
|
calls: list[dict[str, Any]] = []
|
|
|
|
def __init__(self, timeout: int):
|
|
self.timeout = timeout
|
|
|
|
def __enter__(self) -> "DummyClient":
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, traceback) -> None:
|
|
return None
|
|
|
|
def post(
|
|
self,
|
|
url: str,
|
|
json: dict[str, Any],
|
|
headers: dict[str, str],
|
|
) -> DummyResponse:
|
|
self.calls.append({"url": url, "json": json, "headers": headers})
|
|
if url.endswith("/api/v1/agent/ask"):
|
|
assert json["context"]["hermes_memory"] == "remembered project preference"
|
|
return DummyResponse({"answer": "openclaw final answer", "tool_calls": 1})
|
|
mode = json["context"]["mode"]
|
|
if mode == "memory_recall":
|
|
return DummyResponse({"answer": "remembered project preference"})
|
|
if mode == "memory_write":
|
|
return DummyResponse({"answer": "stored"})
|
|
raise AssertionError(f"unexpected Hermes mode: {mode}")
|
|
|
|
|
|
def test_openclaw_hermes_adapter_runs_recall_answer_and_remember(monkeypatch) -> None:
|
|
DummyClient.calls = []
|
|
monkeypatch.setattr(adapters.httpx, "Client", DummyClient)
|
|
settings = Settings(
|
|
model_provider="openclaw_hermes",
|
|
openclaw_base_url="http://openclaw.local",
|
|
openclaw_api_key="openclaw-key",
|
|
hermes_base_url="http://hermes.local",
|
|
hermes_api_key="hermes-key",
|
|
)
|
|
|
|
result = adapters.OpenClawHermesAdapter(settings).ask(
|
|
"summarize project risk",
|
|
{"project_code": "P-001"},
|
|
)
|
|
|
|
assert result["answer"] == "openclaw final answer"
|
|
assert result["raw"]["pipeline"] == "hermes_recall -> openclaw_answer -> hermes_remember"
|
|
assert [call["url"] for call in DummyClient.calls] == [
|
|
"http://hermes.local/api/v1/ask",
|
|
"http://openclaw.local/api/v1/agent/ask",
|
|
"http://hermes.local/api/v1/ask",
|
|
]
|
|
assert DummyClient.calls[0]["headers"]["Authorization"] == "Bearer hermes-key"
|
|
assert DummyClient.calls[1]["headers"]["Authorization"] == "Bearer openclaw-key"
|
|
assert DummyClient.calls[1]["json"]["context"]["agent_pipeline"] == "openclaw_hermes"
|