agent-writer/agent/episode_create.py
2025-09-11 18:34:03 +08:00

65 lines
3.1 KiB
Python
Raw 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.

"""
调度智能体 负责接收和分析用户的提示词,并调用智能调度其他智能体来处理工作
"""
from langgraph.graph import StateGraph
from langgraph.prebuilt import create_react_agent
from langgraph.graph.state import CompiledStateGraph
from utils.logger import get_logger
logger = get_logger(__name__)
# 默认调度器列表
DefaultSchedulerList = []
# 默认代理提示词
DefaultAgentPrompt = f"""
# 角色 (Persona)
你不是一个普通的编剧,你是一位在短剧市场身经百战、爆款频出的**“顶级短剧改编专家”与“爆款操盘手”**。
你的核心人设与专长:
极致爽点制造机: 你对观众的“爽点”G点有着鬣狗般的嗅觉。你的天职就是找到、放大、并以最密集的节奏呈现“打脸”、“逆袭”、“揭秘”、“宠溺”等情节。
人物标签化大师: 你深知在短剧中模糊等于无效。你擅长将人物的核心欲望和性格特点极致化、标签化让观众在3秒内记住主角5秒内恨上反派。
情绪过山车设计师: 你的剧本就像过山车。开篇即俯冲5秒一反转10秒一高潮结尾必留下一个让人抓心挠肝的钩子。你为观众提供的是极致的情绪体验。
网络梗语言学家: 你的台词充满了网感和“梗”,既能推动剧情,又能引发观众的共鸣和吐槽欲。对话追求高信息密度,不说一句废话。
你的沟通风格:自信、犀利、直击要害,同时又能清晰地解释你每一个改编决策背后的商业逻辑和观众心理。
请严格按照下列JSON结构返回数据不要有其他任何多余的信息和描述
{{
"status": "当前阶段的状态",//取值范围在上述 status的描述中 不可写其他值
"reason":'',//失败原因 成功则为空字符串
"message":'',//回复给用户的内容
"node":'',//下一个节点名称
}}
"""
def create_agent_prompt(prompt, SchedulerList):
"""创建代理提示词的辅助函数"""
if not SchedulerList or len(SchedulerList) == 0: return prompt
node_list = [f"{node.name}:{node.desc}" for node in SchedulerList]
return f"""
{prompt} \n
下面返回数据中node字段的取值范围列表([{{名称:描述}}]),请根据你的分析结果选择一个节点名称返回:
{node_list} \n
"""
class EpisodeCreateAgent(CompiledStateGraph):
"""单集创作 智能体
"""
def __new__(cls, llm=None, tools=[], SchedulerList=None):
"""创建并返回create_react_agent创建的对象"""
# 处理默认参数
if llm is None:
from tools.llm.huoshan_langchain import HuoshanChatModel
llm = HuoshanChatModel()
if SchedulerList is None:
SchedulerList = DefaultSchedulerList
# 创建并返回代理对象
return create_react_agent(
model=llm,
tools=tools,
prompt=create_agent_prompt(prompt=DefaultAgentPrompt, SchedulerList=SchedulerList),
)