Files
Agents/note_agent/agent.py
2026-04-08 19:16:40 +08:00

80 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from agent_base.agent_base import HuiYuBaseAgent
from google.adk.models.lite_llm import LiteLlm
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,
)
# ============================================================
# 笔记格式化器
# ============================================================
_formatter = NoteFormatter()
# ============================================================
# Tool: 生成文本笔记
# ============================================================
def generate_text_note(title: str, content: str) -> str:
"""将文本内容整理为 Markdown 笔记。
Args:
title: 笔记标题
content: 笔记正文内容
"""
return _formatter.format_to_markdown(title=title, text_content=content)
# ============================================================
# Tool: 生成图片笔记
# ============================================================
def generate_image_note(title: str, description: str) -> str:
"""将图片描述整理为 Markdown 笔记。
Args:
title: 笔记标题
description: 图片描述或相关文字说明
"""
return _formatter.format_to_markdown(title=title, text_content=description)
# ============================================================
# 定义 Agent继承 HuiYuBaseAgent
# ============================================================
note_agent = HuiYuBaseAgent(
name="note_agent",
model=model,
description="一个多模态笔记助手,能够将图片、文字等内容转换为结构化的 Markdown 笔记。",
instruction=(
"你是一个专业的笔记助手,帮助用户将各种内容整理成 Markdown 笔记。\n"
"你的能力包括:\n"
"1. 接收用户输入的文字内容,整理成结构化的笔记\n"
"2. 接收用户上传的图片,生成图片描述并整理为笔记\n"
"3. 将混合内容(文字+图片)整合为一份完整的笔记\n\n"
"工作流程:\n"
"- 当用户发送文字时,整理内容并调用 generate_text_note 生成笔记\n"
"- 当用户发送图片时,描述图片内容并调用 generate_image_note 生成笔记\n"
"- 当用户发送混合内容时,整合所有内容后生成笔记\n"
"- 笔记标题由你根据内容自动生成,要简洁准确\n"
"- 生成笔记后,直接将 Markdown 内容输出给用户\n"
"- 回复时使用中文"
),
tools=[generate_text_note, generate_image_note],
)
root_agent = note_agent