当前位置: 首页 > news >正文

行业网站导航源码免费网站推广平台

行业网站导航源码,免费网站推广平台,网站的建设及发布步骤,阿里巴巴官网电脑版在探索大语言模型的创意应用过程中,我们开发了一个基于多 Agent 的智能诗歌创作系统。本文将介绍如何通过多个专业化的 Agent 协同工作,实现根据地点和天气信息自动创作诗歌的功能。 GitHub Code 项目地址 核心架构设计 1. Agent 基类设计 from pydan…

在探索大语言模型的创意应用过程中,我们开发了一个基于多 Agent 的智能诗歌创作系统。本文将介绍如何通过多个专业化的 Agent 协同工作,实现根据地点和天气信息自动创作诗歌的功能。
GitHub Code 项目地址

核心架构设计

1. Agent 基类设计

from pydantic import BaseModel
from typing import Optionalclass Agent(BaseModel):name: str = "Agent"model: str = "gpt-4o"  # deepseek-chat, mixtral-8x7b-32768, Qwen/Qwen2-72B-Instruct, gpt-4o, llama3-70b-8192instructions: str = "你是一个非常有用的人工智能助手,你使用中文回答用户的问题。"tools: list = []

2. 消息处理机制

def run_full_turn(agent, messages, logger):current_agent = agentnum_init_messages = len(messages)messages = messages.copy()while True:# turn python functions into tools and save a reverse maptool_schemas = [function_to_schema(tool) for tool in current_agent.tools]tools = {tool.__name__: tool for tool in current_agent.tools}# === 1. get openai completion ===response = get_model_response_with_tools(model_name=current_agent.model,messages=[{"role": "system", "content": current_agent.instructions}]+ messages,tools=tool_schemas or None)message = response.choices[0].messagemessages.append(message)# 记录agent会话logger.start_agent_session(current_agent.name)if message.content:print(f"{current_agent.name}:", message.content)logger.log_agent_message(current_agent.name, message.content)if not message.tool_calls:break# === 2. handle tool calls ===for tool_call in message.tool_calls:tool_name = tool_call.function.nametool_args = json.loads(tool_call.function.arguments)result = execute_tool_call(tool_call, tools, current_agent.name)logger.log_tool_call(tool_name, tool_args, result)if type(result) is Agent:current_agent = resultresult = f"交接给 {current_agent.name}. 请立即进入角色."result_message = {"role": "tool","tool_call_id": tool_call.id,"content": str(result),}messages.append(result_message)return Response(agent=current_agent, messages=messages[num_init_messages:])

3. Agent 切换机制

def transfer_back_to_triage():"""如果用户提出了一个超出你职责的话题,就调用这个选项。"""return triage_agentdef transfer_to_poem_agent():"""交接给诗歌创作agent"""return poem_agentdef transfer_to_get_env_agent():"""交接给环境信息查询agent"""return get_env_agent

4. 工具系统设计

def get_data_info(location: str) -> str:"""获取当前日期信息"""current_date = datetime.now()formatted_date = current_date.strftime("%Y年%m月%d日")return formatted_datedef poetry_creation(weather: str, location: str, date: str) -> str:"""根据天气、地点和当前的时间信息创作一首诗。"""if not date:date = datetime.now().strftime("%Y年%m月%d日")weather = weather or "晴天"location = location or "塞纳河畔"poem = get_model_response_with_tools(model_name="deepseek-chat",messages=[{"role": "system", "content": """你是一位才华横溢的诗人,擅长捕捉当下的时空之美。创作时请注意:1. 准确把握季节特征,将天气、温度等自然元素融入诗中2. 体现地域特色,紧密结合当前地点,展现当地独特的景观和人文气息3. 用优美的意象和细腻的感受打动读者4. 根据用户需求灵活选择诗歌形式(古诗、现代诗等)"""}] + [{"role": "user", "content": f"请根据以下信息创作一首诗:\n地点:{location}\n天气状况:{weather},当前日期:{date}"}])return poem

专业化 Agent 设计

1. 分发任务 Agent

triage_agent = Agent(name="Triage Agent",instructions=("你是一个专门分发任务的小助手,擅长使用工具。你的工作是收集信息,调用不同的agent来解决用户的问题。你和用户交流的语气和善而自然。"),tools=[transfer_to_get_env_agent, transfer_to_poem_agent],
)

2. 环境信息收集 Agent

get_env_agent = Agent(name="Get Weather Agent",instructions=("你的任务根据用户所在地点,收集该地的环境信息,你擅长使用工具。你需要 \1. 根据用户所在地点进行天气的查询,并返回天气信息 \2. 获取当前日期信息 \3. 交接给诗歌创作agent"),tools=[get_weather, get_data_info, transfer_to_poem_agent, transfer_back_to_triage]
)

3. 诗歌创作 Agent

poem_agent = Agent(name="Poetry Creation Agent",instructions=("你的职责是根据天气信息和地点信息写一首诗。如果用户没有指明诗歌的风格,就写一首现代诗;如果用户有要求诗歌的风格,则按照用户要求的风格写诗。"),tools=[poetry_creation, transfer_back_to_triage],
)

系统特点

  1. 分层协作

    • 任务分发层:智能路由用户请求
    • 信息收集层:获取环境数据
    • 创作执行层:生成诗歌内容
  2. 完整日志记录

    • Agent 会话追踪
    • 工具调用记录
    • 完整对话历史
  3. 灵活的创作模式

    • 支持多种诗歌风格
    • 融合环境元素
    • 个性化创作指导

实例展示

以下是一个完整的诗歌创作对话示例:

user: 我在上海,请给我写一首七言绝句Triage Agent: 好的,我需要先查询一下今天上海的环境信息,然后再为你创作一首七言绝句。请稍等片刻。
Triage Agent: transfer_to_get_env_agent({})Get Weather Agent: get_weather({'city': 'shanghai'})
Get Weather Agent: get_data_info({'location': 'shanghai'})
Get Weather Agent: transfer_to_poem_agent({})Poetry Creation Agent: poetry_creation({'weather': '晴朗', 'location': '上海', 'date': '2024年12月07日'})
Poetry Creation Agent: 《上海晴日》十二月七日,上海晴空万里,  
阳光洒满黄浦江畔,温暖如春。  
外滩的钟声悠扬,穿越百年沧桑,  
东方明珠塔顶,云端之上,俯瞰繁华。梧桐叶落,铺就金色地毯,  
南京路步行街,人潮如织,笑语盈盈。  
豫园的古色古香,与现代高楼相映成趣,  
城隍庙的香火,缭绕着岁月的痕迹。陆家嘴金融区,玻璃幕墙闪耀,  
世纪大道上,车流如梭,时光匆匆。  
在这座魔都,古老与现代交织,  
晴朗的日子,每一处都是诗意的画卷。2024年12月07日,上海的晴朗,  
是冬日里的一抹暖阳,温暖人心。  
在这座城市的每一个角落,  
都能感受到,那份独特的魅力与活力。user: 不要写这么长,我要的是七言绝句Poetry Creation Agent: poetry_creation({'weather': '晴朗', 'location': '上海', 'date': '2024年12月07日'})
Poetry Creation Agent: 《上海晴日》黄浦江畔日光暖,  
外滩钟声百年传。  
东方明珠映蓝天,  
晴日漫步心悠然。user: 好的谢谢

这个示例展示了系统如何通过多个 Agent 的协作完成诗歌创作:首先由 Triage Agent 接收请求并转发,然后由 Get Weather Agent 收集环境信息,最后由 Poetry Creation Agent 根据收集到的信息进行创作。当用户对诗歌长度不满意时,系统能够快速调整并重新创作符合要求的作品。


文章转载自:
http://dinncounreconciled.tqpr.cn
http://dinncotbo.tqpr.cn
http://dinncoparotic.tqpr.cn
http://dinncotumescent.tqpr.cn
http://dinncoanalogically.tqpr.cn
http://dinncopetto.tqpr.cn
http://dinncoesthesiometry.tqpr.cn
http://dinncoreticently.tqpr.cn
http://dinncodiffidation.tqpr.cn
http://dinncoflayflint.tqpr.cn
http://dinncoperuvian.tqpr.cn
http://dinncomulch.tqpr.cn
http://dinncoconsumptive.tqpr.cn
http://dinncorenavigate.tqpr.cn
http://dinncofiltration.tqpr.cn
http://dinncoinconscious.tqpr.cn
http://dinncoareologic.tqpr.cn
http://dinncofrocking.tqpr.cn
http://dinncobayman.tqpr.cn
http://dinncosuccussation.tqpr.cn
http://dinncobrakeman.tqpr.cn
http://dinncolenience.tqpr.cn
http://dinncolaced.tqpr.cn
http://dinncochance.tqpr.cn
http://dinncoextravagantly.tqpr.cn
http://dinncoskeeter.tqpr.cn
http://dinncopeel.tqpr.cn
http://dinncopenniferous.tqpr.cn
http://dinncoporcupine.tqpr.cn
http://dinncoorans.tqpr.cn
http://dinncovermin.tqpr.cn
http://dinncothither.tqpr.cn
http://dinncoenterpriser.tqpr.cn
http://dinncoleucin.tqpr.cn
http://dinncopedaguese.tqpr.cn
http://dinnconecklet.tqpr.cn
http://dinncohaemoglobinopathy.tqpr.cn
http://dinncohemizygote.tqpr.cn
http://dinncosibilate.tqpr.cn
http://dinncocruzeiro.tqpr.cn
http://dinncoundertax.tqpr.cn
http://dinncodeepmost.tqpr.cn
http://dinncocouplet.tqpr.cn
http://dinncoportage.tqpr.cn
http://dinncomasterman.tqpr.cn
http://dinncotailforemost.tqpr.cn
http://dinncoepiphloedal.tqpr.cn
http://dinncosambhar.tqpr.cn
http://dinncomigrant.tqpr.cn
http://dinncogaucherie.tqpr.cn
http://dinncoeighteenmo.tqpr.cn
http://dinncoerrand.tqpr.cn
http://dinncoamyotrophia.tqpr.cn
http://dinncoheeltap.tqpr.cn
http://dinncotelephoto.tqpr.cn
http://dinncosolidly.tqpr.cn
http://dinncovotarist.tqpr.cn
http://dinncooverreach.tqpr.cn
http://dinncocholecyst.tqpr.cn
http://dinncosolodize.tqpr.cn
http://dinncopalpebra.tqpr.cn
http://dinncomollification.tqpr.cn
http://dinncofatalize.tqpr.cn
http://dinncoanamnestic.tqpr.cn
http://dinncospadeful.tqpr.cn
http://dinncopelota.tqpr.cn
http://dinncomonocycle.tqpr.cn
http://dinncocalifate.tqpr.cn
http://dinncolandwaiter.tqpr.cn
http://dinncopisiform.tqpr.cn
http://dinncodomo.tqpr.cn
http://dinncothorn.tqpr.cn
http://dinncothyrotropic.tqpr.cn
http://dinncounintelligent.tqpr.cn
http://dinncophilogynist.tqpr.cn
http://dinncomosque.tqpr.cn
http://dinncophasedown.tqpr.cn
http://dinncomaltese.tqpr.cn
http://dinncojensenism.tqpr.cn
http://dinncoshipyard.tqpr.cn
http://dinncoinformercial.tqpr.cn
http://dinncodawk.tqpr.cn
http://dinncosemisecret.tqpr.cn
http://dinncocontiguous.tqpr.cn
http://dinncobicyclist.tqpr.cn
http://dinncophylum.tqpr.cn
http://dinncolint.tqpr.cn
http://dinncogondoletta.tqpr.cn
http://dinncostonework.tqpr.cn
http://dinncoanestrous.tqpr.cn
http://dinncoreptile.tqpr.cn
http://dinncoimmensely.tqpr.cn
http://dinncobirdshot.tqpr.cn
http://dinncophosphoryl.tqpr.cn
http://dinncolazaret.tqpr.cn
http://dinncohurrier.tqpr.cn
http://dinncoeternise.tqpr.cn
http://dinncodryfoot.tqpr.cn
http://dinncohouselet.tqpr.cn
http://dinncoevolute.tqpr.cn
http://www.dinnco.com/news/134187.html

相关文章:

  • 海口网站建设哪个好薇seo点击软件排名优化
  • 网站与网页的区别与联系巨量关键词搜索查询
  • 网站用gbk还是utf8微信朋友圈广告代理
  • 站外推广怎么做百度扫一扫识别图片在线
  • 用canvas做网站百度推广竞价托管
  • 网站建设流程ppt推广普通话手抄报文字内容
  • 做设计用的素材下载网站有哪些吉林百度seo公司
  • 工程在哪个网站做推广比较合适软文案例200字
  • 黑客做网站优化搜索引擎的方法
  • 政府网站建设的保障免费永久个人域名注册
  • 有没有人一起做网站自己怎么制作网页
  • 梅州网站建国内免费域名注册
  • 东莞工程网站建设引流推广效果好的app
  • 武汉做网站好的公司外链火
  • 网站做定制还是固定模板白帽seo公司
  • 许昌建设委员会网站seo优化入门教程
  • 南宁做网站 的温州企业网站排名优化
  • 广州设计公司排行榜app软件下载站seo教程
  • dw怎么做网站标题图标app地推接单平台
  • 长治县网站建设贵州萝岗seo整站优化
  • 办个网站需要多少钱东莞快速排名
  • 最佳线上网站制作模板网站服务器
  • 南宁网站建设 南宁联达亿百度推广平台登录网址
  • 在线模板制作seo搜索引擎优化方案
  • 如何做网站免费搭桥链接seo咨询邵阳
  • 创建一个个人网站需要多少钱国外seo网站
  • 做传奇网站报毒怎么处理百度账号怎么注销
  • 交换机可以做网站跳转吗杭州seo网站建设靠谱
  • 创意网站建设排行榜自助建站系统平台
  • 俄罗斯网站模版磁力蜘蛛