From ea2e30f568b8011b53123058f51575cbd2e230c7 Mon Sep 17 00:00:00 2001 From: nelson <1475262689@qq.com> Date: Thu, 9 Apr 2026 21:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0299=E8=80=81=E5=B8=88?= =?UTF-8?q?=E5=88=86=E8=BA=ABagent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 13 +++++++ common/models.py | 27 +++++++++++++ critical_awareness_agent/agent.py | 31 +++------------ lumina_agent/__init__.py | 1 + lumina_agent/agent.py | 65 +++++++++++++++++++++++++++++++ note_agent/agent.py | 22 +---------- root_agent/agent.py | 24 ++---------- 7 files changed, 117 insertions(+), 66 deletions(-) create mode 100644 common/models.py create mode 100644 lumina_agent/__init__.py create mode 100644 lumina_agent/agent.py diff --git a/.env.example b/.env.example index 871cc97..3882188 100644 --- a/.env.example +++ b/.env.example @@ -13,3 +13,16 @@ MINIMAX_API_BASE=https://api.minimaxi.com/v1 # MiniMax 模型名称(例如: MiniMax-Text-01, abab-6.5s-chat, MiniMax-M1 等) MINIMAX_MODEL=openai/MiniMax-Text-01 + +# ============================================================ +# DeepSeek 配置 +# ============================================================ + +# DeepSeek API Key(请替换为你自己的 API Key) +DEEPSEEK_API_KEY=YOUR_DEEPSEEK_API_KEY + +# DeepSeek API 地址(OpenAI 兼容接口) +DEEPSEEK_API_BASE=https://api.deepseek.com/v1 + +# DeepSeek 模型名称 +DEEPSEEK_MODEL=openai/deepseek-chat diff --git a/common/models.py b/common/models.py new file mode 100644 index 0000000..9d5f6d4 --- /dev/null +++ b/common/models.py @@ -0,0 +1,27 @@ +""" +模型工厂 — 集中管理所有 LLM 模型实例 + +用法: + from common.models import minimax_model, deepseek_model +""" + +import os +from google.adk.models.lite_llm import LiteLlm + +# ============================================================ +# MiniMax 模型 +# ============================================================ +minimax_model = LiteLlm( + model=os.getenv("MINIMAX_MODEL"), + api_base=os.getenv("MINIMAX_API_BASE"), + api_key=os.getenv("MINIMAX_API_KEY"), +) + +# ============================================================ +# DeepSeek 模型 +# ============================================================ +deepseek_model = LiteLlm( + model=os.getenv("DEEPSEEK_MODEL"), + api_base=os.getenv("DEEPSEEK_API_BASE"), + api_key=os.getenv("DEEPSEEK_API_KEY"), +) diff --git a/critical_awareness_agent/agent.py b/critical_awareness_agent/agent.py index a62312a..2c89c9f 100644 --- a/critical_awareness_agent/agent.py +++ b/critical_awareness_agent/agent.py @@ -1,35 +1,16 @@ -import os - - -from google.adk.models.lite_llm import LiteLlm from agent_base.agent_base import HuiYuBaseAgent - -# ============================================================ -# MiniMax 模型配置(从 .env 文件读取) -# ============================================================ -MINIMAX_API_KEY = os.getenv("MINIMAX_API_KEY") -MINIMAX_API_BASE = os.getenv("MINIMAX_API_BASE") -MINIMAX_MODEL = os.getenv("MINIMAX_MODEL") - -# ============================================================ -# 创建 LiteLlm 模型适配器 -# ============================================================ -model = LiteLlm( - model=MINIMAX_MODEL, - api_base=MINIMAX_API_BASE, - api_key=MINIMAX_API_KEY, -) +from common.models import minimax_model # ============================================================ # 定义 Agent(继承 HuiYuBaseAgent) # ============================================================ critical_awareness_agent = HuiYuBaseAgent( name="critical_awareness_agent", - model=model, - description="用于处理用户心智散乱、情绪化或认知混淆的专家。它通过‘三界(外中内)’判别法强制用户回归觉知。当用户表达焦虑、愤怒、分心或无法区分事实与观点时,必须调用此工具。", + model=minimax_model, + description="用于处理用户心智散乱、情绪化或认知混淆的专家。它通过'三界(外中内)'判别法强制用户回归觉知。当用户表达焦虑、愤怒、分心或无法区分事实与观点时,必须调用此工具。", instruction=( """ - 你是一位精通“临界觉察法”的资深导师。你的目标是协助学生通过识别外界、中界、内界的边界,回归当下觉知。 + 你是一位精通"临界觉察法"的资深导师。你的目标是协助学生通过识别外界、中界、内界的边界,回归当下觉知。 判定逻辑: - 外界 (External): 纯粹感官原始数据,无形容词/评价。 @@ -39,10 +20,10 @@ critical_awareness_agent = HuiYuBaseAgent( 回复规范: 1. 必须快速拆解输入内容,给出 [外界/中界/内界] 的结构化分析。 2. 语气简洁、敏锐,像手术刀一样切开混沌。 - 3. 引导学生作为“观察者”,清晰的觉知三界都在发生什么。 + 3. 引导学生作为"观察者",清晰的觉知三界都在发生什么。 4. 提醒学生回归当下的觉知 """ ) ) -root_agent = critical_awareness_agent # 将 critical_awareness_agent 作为 root_agent 导出,供 adk web 注册 \ No newline at end of file +root_agent = critical_awareness_agent diff --git a/lumina_agent/__init__.py b/lumina_agent/__init__.py new file mode 100644 index 0000000..a66dcf3 --- /dev/null +++ b/lumina_agent/__init__.py @@ -0,0 +1 @@ +# ADK agent_loader 会自动扫描并加载 agent.py diff --git a/lumina_agent/agent.py b/lumina_agent/agent.py new file mode 100644 index 0000000..20644d4 --- /dev/null +++ b/lumina_agent/agent.py @@ -0,0 +1,65 @@ +from agent_base.agent_base import HuiYuBaseAgent +from common.models import minimax_model + +# ============================================================ +# 定义 Agent(继承 HuiYuBaseAgent) +# ============================================================ +lumina_agent = HuiYuBaseAgent( + name="lumina_agent", + model=minimax_model, + description="一个专门负责讲解入门课的老师", + instruction=""" + # 角色 + 你现在是卢慧老师,会式心理学创始人,主讲家庭关系、代际创伤、原生家庭疗愈、生命觉醒课程。 + 你的风格:温暖坚定、有力量、共情、直击本质、带疗愈感、常用比喻、会引导互动,擅长用科学的角度来解释心理现象。 + + # 核心理论 + 1. 人不是有问题,是被家族代际数据困住。 + 2. 疗愈不是加法,是减法:0 − 负 = 正。 + 3. 妈妈 = 命运 = 爱、连接、财富。 + 4. 爸爸 = 力量 = 自信、事业、行动力。 + 5. 外在是果,内在是因;孩子是复印件,父母是原件。 + 6. 人被七层数据壳困住:行为、能力、情绪、信念、程序、共生、执着。 + 7. 三大影响系统:血缘、亲缘、业缘。 + 8. 疗愈路径:看见 → 看穿 → 看透 → 看够 → 光明升起。 + + # 工具 + 1. 数息法:一吸一呼数1,走神重来。 + 2. 内感知建模:左手 → 心口 → 右手,各数5次呼吸。 + 3. 认知透镜:我看见我的妈妈 / 爸爸 / 金钱 / 麻木 / 情绪。 + + # 口头禅 + - 本自具足 + - 慢慢来,比较快 + - 躺平有理,崩溃有理 + - 我足够好 + - 边练习边明白 + - 内在诚信 + - 防御层 + - 沦陷在过去 + - 我心光明 + - 格物致知、诚意正心 + + # 语气 + - 温柔但有力量 + - 像一位清醒、慈悲、通透的导师 + - 会共情、会点醒、会陪伴 + - 不批判、不指责、只引导看见 + - 会带呼吸练习、引导觉察、带疗愈 + + # 回答规则 + 1. 永远先共情,再点本质。 + 2. 永远指向内在,不向外归因。 + 3. 永远引导"看见",而不是给方法。 + 4. 带练习时,步骤清晰、温和、有耐心。 + 5. 遇到情绪,允许、接纳、不推动。 + 6. 遇到孩子问题,一定指向父母内在。 + 7. 遇到金钱问题,一定指向妈妈与安全感。 + 8. 遇到关系问题,一定指向共生与代际。 + 9. 当学生需要你引导时,你再引导,不要过早引导,先让学生自己说出来。 + + 假设现在学生们已经听过一遍你的课程了,然后你现在以卢慧老师的身份,和我对话、带练习、做疗愈、解答问题。 + """, +) + +root_agent = lumina_agent diff --git a/note_agent/agent.py b/note_agent/agent.py index 901d241..9de62a8 100644 --- a/note_agent/agent.py +++ b/note_agent/agent.py @@ -1,25 +1,7 @@ -import os - from agent_base.agent_base import HuiYuBaseAgent -from google.adk.models.lite_llm import LiteLlm +from common.models import minimax_model from .note_formatter import NoteFormatter -# ============================================================ -# MiniMax 模型配置(从 .env 文件读取) -# ============================================================ -MINIMAX_API_KEY = os.getenv("MINIMAX_API_KEY") -MINIMAX_API_BASE = os.getenv("MINIMAX_API_BASE") -MINIMAX_MODEL = os.getenv("MINIMAX_MODEL") - -# ============================================================ -# 创建 LiteLlm 模型适配器 -# ============================================================ -model = LiteLlm( - model=MINIMAX_MODEL, - api_base=MINIMAX_API_BASE, - api_key=MINIMAX_API_KEY, -) - # ============================================================ # 笔记格式化器 # ============================================================ @@ -57,7 +39,7 @@ def generate_image_note(title: str, description: str) -> str: # ============================================================ note_agent = HuiYuBaseAgent( name="note_agent", - model=model, + model=minimax_model, description="一个多模态笔记助手,能够将图片、文字等内容转换为结构化的 Markdown 笔记。", instruction=( "你是一个专业的笔记助手,帮助用户将各种内容整理成 Markdown 笔记。\n" diff --git a/root_agent/agent.py b/root_agent/agent.py index c94d64d..a020b03 100644 --- a/root_agent/agent.py +++ b/root_agent/agent.py @@ -1,32 +1,14 @@ -import os - from agent_base.agent_base import HuiYuBaseAgent -from google.adk.models.lite_llm import LiteLlm +from common.models import minimax_model from critical_awareness_agent.agent import critical_awareness_agent from note_agent.agent import note_agent -# ============================================================ -# MiniMax 模型配置(从 .env 文件读取) -# ============================================================ -MINIMAX_API_KEY = os.getenv("MINIMAX_API_KEY") -MINIMAX_API_BASE = os.getenv("MINIMAX_API_BASE") -MINIMAX_MODEL = os.getenv("MINIMAX_MODEL") - -# ============================================================ -# 创建 LiteLlm 模型适配器 -# ============================================================ -model = LiteLlm( - model=MINIMAX_MODEL, - api_base=MINIMAX_API_BASE, - api_key=MINIMAX_API_KEY, -) - # ============================================================ # 定义 Agent(继承 HuiYuBaseAgent,自动获得防注入 + 日志能力) # ============================================================ root_agent = HuiYuBaseAgent( name="huiyu_agent", - model=model, + model=minimax_model, description="一个智能助手,能够回答用户的各种问题。", instruction=( "你是一个乐于助人的中文 AI 助手,你的名字叫小慧,请用中文回答用户的问题,回答要准确、简洁、友好。\n\n" @@ -35,5 +17,5 @@ root_agent = HuiYuBaseAgent( "你还有一个子助手「临界觉察助手」(critical_awareness_agent),当用户出现心智散乱、情绪化或认知混淆时," "请将任务委派给 critical_awareness_agent 处理。" ), - sub_agents=[note_agent, critical_awareness_agent], # 将 note_agent 和 critical_awareness_agent 作为子 Agent + sub_agents=[note_agent, critical_awareness_agent], )