emotion-nurse-nearby
基于 ACPs-SDK 2.1.0 的精神科出院情绪随访双智能体系统(Python 1.0.0)。 精简、开箱即用,核心依赖智能体互联 SDK 完成 Agent 间通信。
架构
┌──────────────────────────┐ ACPs AIP RPC ┌───────────────────────────┐
│ EmotionFollowUpAgent │ ──────────────────▶ │ FollowUpNurseAgent │
│ (Leader, CLI) │ JSON-RPC over HTTP │ (Partner, FastAPI) │
│ - 询问情绪 / 睡眠 / 服药 │ │ - 接收转诊摘要 │
│ - 关键词三维打分(1~5) │ 检测到持续恶化 │ - 生成「复诊提醒」Product │
│ - 记录持久化 + 恶化检测 │ ──────────────────▶ │ - 返回 TaskResult │
└──────────────────────────┘ └───────────────────────────┘
- EmotionFollowUpAgent(情绪随访 Agent):在命令行中询问患者情绪、睡眠、服药情况,用
analysis.py做轻量关键词打分(1=稳定 … 5=危急)并持久化到本地;检测到单次高危或持续恶化时,通过acps_sdk.aip.AipRpcClient自动把摘要转诊给随访护士。 - FollowUpNurseAgent(随访护士 Agent):一个 FastAPI 服务,用
acps_sdk.aip.aip_rpc_server.add_aip_rpc_router挂载 AIP RPC 端点,收到转诊后生成结构化的复诊提醒(高危 / 持续恶化两种处置建议)。
恶化判定规则
- 单次高危:最新一次随访任一维度达到 5 分 → 立即转诊;
- 持续恶化:与上一次随访相比总分上升,且至少 2 个维度加重、无维度改善; 或最近连续 3 次随访总分逐次上升 → 转诊。
快速开始
# 安装(开发模式)
pip install -e .
# 一键启动(后台起护士 + 进入随访)
emotion-nurse run
# 分开跑
emotion-nurse server # 终端 A:启动 FollowUpNurseAgent(默认 8100)
emotion-nurse followup # 终端 B:运行 EmotionFollowUpAgent
# 非交互 demo(一键验证转诊链路,内置一个持续恶化病例)
emotion-nurse demo
# 查看本地随访记录
emotion-nurse history
emotion-nurse history --patient-id p001
护士端点默认 http://127.0.0.1:8100/aip/rpc,可用 emotion-nurse followup --url ... 指向已部署的护士服务。
打包 wheel 并上传 PyPI
# 生成 dist/emotion_nurse_nearby-1.0.0-py3-none-any.whl
python -m build
# 上传到 PyPI(需先配置 ~/.pypirc 或使用 token)
twine upload dist/*.whl
上传后他人即可:
pip install emotion-nurse-nearby
emotion-nurse demo
项目结构
emotion_nurse_nearby/
├── __init__.py # 版本号
├── models.py # 随访记录模型 + 本地 JSON 持久化(RecordStore)
├── analysis.py # 三维关键词评分 + 持续恶化检测 + 转诊载荷构建
├── nurse_agent.py # FollowUpNurseAgent —— FastAPI + ACPs AIP RPC Server
├── followup_agent.py # EmotionFollowUpAgent —— CLI 访谈 + AipRpcClient 转诊
└── cli.py # 命令行入口(run / server / followup / demo / history)
tests/
└── test_analysis.py # 评分与恶化逻辑的最小化测试
核心依赖
| 包 | 版本 | 用途 |
|---|---|---|
acps-sdk |
2.1.0 | 智能体互联(AIP 协议 RPC Client / Server),本项目核心依赖 |
fastapi |
≥0.110 | FollowUpNurseAgent 服务端 |
uvicorn |
≥0.27 | ASGI server |
httpx |
≥0.27 | acps-sdk 内部 RPC 传输 |
说明
analysis.py采用纯 Python 关键词匹配,不依赖外部 LLM,保证零额外成本、开箱即用。生产环境可替换为任意 LLM / 模型驱动的分析器,只要保持score_followup/detect_deterioration的返回结构不变即可。- 随访记录默认存放在
~/.emotion_nurse_nearby/records.json,可用环境变量EMOTION_NURSE_DATA_DIR覆盖存储目录(便于多实例隔离或测试)。 - 本项目严格依赖
acps-sdk 2.1.0,通过它的 AIP(Agent Interaction Protocol)RPC 模式完成情绪随访 Agent 与随访护士 Agent 的互联转诊。
Metadata
Release files for emotion-nurse-nearby 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| emotion_nurse_nearby-1.0.0.tar.gz | 17.1 kB | Without provenance | Details for emotion_nurse_nearby-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| emotion_nurse_nearby-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for emotion_nurse_nearby-1.0.0-py3-none-any.whl |
Total release size: 35.3 kB
Release files / emotion_nurse_nearby-1.0.0.tar.gz
| Download URL | emotion_nurse_nearby-1.0.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1aa5735d71707de1c52b25581274dca0e852e0abd07f1ffe2949a953e4360e6c
|
|
BLAKE2b-256 checksum How to use checksums |
4980cb5f24797d312607fd8840e65b4e675a078992ae0823ffbed5218046baa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|
Release files / emotion_nurse_nearby-1.0.0-py3-none-any.whl
| Download URL | emotion_nurse_nearby-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73a7e9f5969021a03aaa5b76d8c457658cbccf25201b8643473982d5cf7b36f7
|
|
BLAKE2b-256 checksum How to use checksums |
7af1673d29b182ee44ad99fe1529f57e2877dc1e21eb114579f6f909411e5695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|
Security for emotion-nurse-nearby 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.