新增:添加Monitor智能体模块
功能特性: - 实现系统监控和性能分析智能体 - 提供完整的模块结构: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>
This commit is contained in:
parent
ba0e04362a
commit
083d35e02c
5
agent_system/monitor/__init__.py
Normal file
5
agent_system/monitor/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .agent import Monitor
|
||||||
|
from .response_model import MonitorResult
|
||||||
|
from .prompt import MonitorPrompt
|
||||||
|
|
||||||
|
__all__ = ["Monitor", "MonitorResult", "MonitorPrompt"]
|
||||||
100
agent_system/monitor/agent.py
Normal file
100
agent_system/monitor/agent.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
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
|
||||||
28
agent_system/monitor/prompt.py
Normal file
28
agent_system/monitor/prompt.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from agent_system.base import BasePrompt
|
||||||
|
|
||||||
|
class MonitorPrompt(BasePrompt):
|
||||||
|
description = (
|
||||||
|
"Monitor智能体负责监控和评估病史收集质量。"
|
||||||
|
"基于现病史、既往史和主诉,对病史信息的完整性和质量进行综合评分。"
|
||||||
|
"为医疗数据质量控制提供智能化监控支持。"
|
||||||
|
)
|
||||||
|
|
||||||
|
instructions = [
|
||||||
|
"1. 评估目标:",
|
||||||
|
" - 基于现病史、既往史和主诉进行综合质量评估",
|
||||||
|
" - 评估病史信息的完整性、准确性和临床价值",
|
||||||
|
" - 提供客观的完成度评分和详细的评分理由",
|
||||||
|
"2. 评估原则:",
|
||||||
|
" - 重点关注病史信息的医学完整性和临床意义",
|
||||||
|
" - 考虑信息的逻辑一致性和相互关联性",
|
||||||
|
" - 基于医学标准和临床实践进行评估",
|
||||||
|
"3. 输出要求:",
|
||||||
|
" - 严格按照JSON格式输出结构化结果",
|
||||||
|
" - completion_score: 0.0-1.0的浮点数,表示总体完成度",
|
||||||
|
" - reason: 详细的评分理由,说明评分依据",
|
||||||
|
"4. 示例输出:",
|
||||||
|
' {',
|
||||||
|
' "reason": "现病史描述详细,包含起病情况、症状特征和病情发展过程。既往史涵盖主要疾病史和过敏史。主诉简洁明确。但缺少部分伴随症状和治疗效果的描述,影响整体完整性。"',
|
||||||
|
' "completion_score": 0.85,',
|
||||||
|
' }'
|
||||||
|
]
|
||||||
17
agent_system/monitor/response_model.py
Normal file
17
agent_system/monitor/response_model.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from pydantic import Field
|
||||||
|
from agent_system.base import BaseResponseModel
|
||||||
|
|
||||||
|
class MonitorResult(BaseResponseModel):
|
||||||
|
"""
|
||||||
|
Monitor监控结果模型
|
||||||
|
"""
|
||||||
|
completion_score: float = Field(
|
||||||
|
...,
|
||||||
|
description="完成度评分(0.0-1.0)",
|
||||||
|
ge=0.0,
|
||||||
|
le=1.0
|
||||||
|
)
|
||||||
|
reason: str = Field(
|
||||||
|
...,
|
||||||
|
description="评分理由,详细说明为什么给出这个评分"
|
||||||
|
)
|
||||||
Loading…
x
Reference in New Issue
Block a user