功能特性: - 实现系统监控和性能分析智能体 - 提供完整的模块结构:agent.py、prompt.py、response_model.py - 支持监控数据收集和分析功能 - 集成到AIM智能体系统框架 模块组成: - agent.py: Monitor智能体核心实现 - prompt.py: 监控分析相关提示模板 - response_model.py: 监控数据响应模型定义 - __init__.py: 模块初始化配置 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
from typing import Optional
|
||
from agent_system.base import BaseAgent
|
||
from agent_system.monitor.prompt import MonitorPrompt
|
||
from agent_system.monitor.response_model import MonitorResult
|
||
|
||
class Monitor(BaseAgent):
|
||
"""
|
||
Monitor智能体
|
||
监控和评估现病史、既往史和主诉的质量,提供完成度评分
|
||
"""
|
||
def __init__(self, model_type: str = "gpt-oss:latest", llm_config: dict = {}):
|
||
super().__init__(
|
||
model_type=model_type,
|
||
description=MonitorPrompt.description,
|
||
instructions=MonitorPrompt.instructions,
|
||
response_model=MonitorResult,
|
||
llm_config=llm_config,
|
||
structured_outputs=True,
|
||
markdown=False,
|
||
use_cache=False
|
||
)
|
||
|
||
def run(self, hpi_content: str, ph_content: str, chief_complaint: str) -> MonitorResult:
|
||
"""
|
||
监控病史质量
|
||
|
||
Args:
|
||
hpi_content: 现病史内容
|
||
ph_content: 既往史内容
|
||
chief_complaint: 主诉
|
||
|
||
Returns:
|
||
MonitorResult: 包含完成度评分和评分理由
|
||
"""
|
||
# 构建评估提示
|
||
prompt = self.build_prompt(hpi_content, ph_content, chief_complaint)
|
||
|
||
# 调用LLM进行评估
|
||
result = super().run(prompt)
|
||
|
||
# 确保返回正确的类型
|
||
if isinstance(result, MonitorResult):
|
||
return result
|
||
elif isinstance(result, dict):
|
||
return MonitorResult(**result)
|
||
else:
|
||
# 解析失败,返回默认结果
|
||
return MonitorResult(
|
||
completion_score=0.0,
|
||
reason="监控评估失败:无法解析LLM响应"
|
||
)
|
||
|
||
def build_prompt(self, hpi_content: str, ph_content: str, chief_complaint: str) -> str:
|
||
"""
|
||
构建监控评估的提示语
|
||
|
||
Args:
|
||
hpi_content: 现病史内容
|
||
ph_content: 既往史内容
|
||
chief_complaint: 主诉
|
||
|
||
Returns:
|
||
str: 构建好的提示语
|
||
"""
|
||
prompt = f"""请对以下病史信息进行质量监控和评估:
|
||
|
||
**主诉**:
|
||
{chief_complaint}
|
||
|
||
**现病史**:
|
||
{hpi_content}
|
||
|
||
**既往史**:
|
||
{ph_content}
|
||
|
||
**评估要求**:
|
||
1. 综合评估现病史、既往史和主诉的信息完整性
|
||
2. 考虑信息之间的逻辑一致性和相互关联性
|
||
3. 基于医学标准评估信息的临床价值
|
||
4. **必须先给出详细的评分理由,再基于理由给出0.0-1.0范围内的完成度评分**
|
||
5. 评分必须与理由保持逻辑一致
|
||
|
||
**输出格式**:
|
||
严格按照以下JSON格式输出:
|
||
{{
|
||
"completion_score": 浮点数(0.0-1.0),
|
||
"reason": "详细的评分理由"
|
||
}}
|
||
|
||
**评分指导**:
|
||
- 0.9-1.0: 信息非常完整,逻辑清晰,临床价值高
|
||
- 0.8-0.9: 信息较完整,有少量缺失,整体质量良好
|
||
- 0.7-0.8: 信息基本完整,存在一些不足
|
||
- 0.6-0.7: 信息不够完整,有明显缺失
|
||
- 0.5-0.6: 信息缺失较多,质量有待提高
|
||
- 0.0-0.5: 信息严重不足,需要大幅改善
|
||
|
||
请基于上述标准进行客观评估。"""
|
||
|
||
return prompt |