链载Ai
标题: 轻量级多模态代理框架 Agno 像搭乐高一样构建私有化AGI中台 [打印本页]
作者: 链载Ai 时间: 10 小时前
标题: 轻量级多模态代理框架 Agno 像搭乐高一样构建私有化AGI中台
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 1em 8px;letter-spacing: 0.1em;color: rgb(33, 37, 41);padding: 8px 12px;background: rgba(237, 242, 255, 0.8);border-radius: 8px;">Agno 是一个开源框架, 旨在创建具有记忆、知识保留、工具集成和复杂推理等功能的高级 AI 代理。 它使开发人员能够无缝集成任何大型语言模型 (LLM), 管理代理的状态和内存,甚至协调多个协同工作的代理。 ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;margin: 1.5em 8px;color: rgb(63, 63, 63);"> ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 14px;border-radius: 8px;display: block;margin: 0.1em auto 0.5em;border-width: 0px;border-style: solid;border-color: initial;border-image-width: initial;border-image-outset: initial;border-image-repeat: initial;border-image-source: linear-gradient(to right, rgb(143, 65, 233), rgb(108, 89, 245), rgb(164, 102, 255), rgb(232, 111, 255), rgb(255, 132, 213), rgb(234, 160, 147), rgb(255, 173, 51));border-image-slice: 1;height: auto !important;" title="null" src="https://api.ibos.cn/v4/weapparticle/accesswximg?aid=105314&url=aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X3BuZy9hZzdaM2RDcTdMbFk5ZW5vUmN4cXpQc2hXYXk3clRHOXFTMThjWDUwR3p3UEFIUFg2U1FXeUh0QkNwUGRVMEJZcVNSR3ZmU0JEaWFNV1FRN3JpYnp2WDl3LzY0MD93eF9mbXQ9cG5nJmFtcA==;from=appmsg"/>
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 1em 8px;letter-spacing: 0.1em;color: rgb(33, 37, 41);padding: 8px 12px;background: rgba(237, 242, 255, 0.8);border-radius: 8px;">Agno 的真正力量在于它能够构建高性能、 特定领域的 AI 代理 ,并提供在生产中监控和优化它们的工具。 由于其足够简单 ,所以在你的业务场景中集成 Agno 几乎感受不到什么影响。
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 1em 8px;letter-spacing: 0.1em;color: rgb(33, 37, 41);padding: 8px 12px;background: rgba(237, 242, 255, 0.8);border-radius: 8px;">任何你能想到的场景,都可以方便使用 Agno 实现,比如:ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;margin-left: 8px;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1"> ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 20px;font-weight: bold;display: table;margin: 2em auto 1.5em;padding: 6px 0px 6px 16.75px;background: linear-gradient(135deg, rgb(113, 23, 234), rgba(113, 23, 234, 0.667), rgba(234, 96, 96, 0.533), rgba(217, 57, 205, 0.267), rgba(217, 57, 205, 0));color: rgb(255, 255, 255);border-radius: 8px;width: 318.25px;">人工智能工程就是软件工程
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 1em 8px;letter-spacing: 0.1em;color: rgb(33, 37, 41);padding: 8px 12px;background: rgba(237, 242, 255, 0.8);border-radius: 8px;">从官方的角度看,Agno 适用于哪些场景呢?
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;margin: 1em 8px;letter-spacing: 0.1em;color: rgb(33, 37, 41);padding: 8px 12px;background: rgba(237, 242, 255, 0.8);border-radius: 8px;">如果你在构建 AI 产品时,ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;margin-left: 8px;padding-left: 1em;list-style: circle;color: rgb(63, 63, 63);" class="list-paddingleft-1">•解决方案的 80% 将是标准的 Python 代码 , •其余 20% 将使用 Agents 实现自动化 。 • 说是 20%,我都觉得多了,我使用下来,知识在需要智能体的地方写一两行代码就可以了。 Agno 专为此类用例而设计。
当然,用 Agno 构建代理很简单, 只需要使用熟悉的编程结构(if、else、while、for)编写 AI 逻辑, 避免使用图形和链等复杂的抽象。
下面是一个可以搜索网络的简单代理(搜索工具框架里面已经提供了):
fromagno.agentimportAgent fromagno.models.openaiimportOpenAIChat fromagno.tools.duckduckgoimportDuckDuckGoTools agent = Agent( model=OpenAIChat(id="gpt-4o"), tools=[DuckDuckGoTools()], markdown=True ) agent.print_response("北京最近有什么新闻?", stream=True)更复杂的一个例子,你可以设置代理的description、instructions、expected_output:
agent = Agent( model=OpenAIChat(id="gpt-4o"), tools=[ExaTools(start_published_date=today,type="keyword")], description=dedent(""" """), instructions=dedent(""" """), expected_output=dedent(""" """), markdown=True, show_tool_calls=True, add_datetime_to_instructions=True, )• description 会加在系统提示词的前面; 结构化输出 另一个特别有用的功能是结构化输出,这比你手写 prompt 定义expected_output更方便。
classMovieScript(BaseModel): setting:str= Field(..., description="为一部大片提供一个精彩的场景设定。") ending:str= Field(..., description="电影的结局。如果没有特别要求,提供一个喜剧结局。") genre:str= Field( ..., description="电影的类型。如果没有特别要求,可以选择动作片、惊悚片或浪漫喜剧。" ) name:str= Field(..., description="为这部电影取一个名字") characters ist[str] = Field(..., description="电影中的角色名称。") storyline:str= Field(..., description="用3句话描述电影的故事情节。让它令人兴奋!") json_mode_agent = Agent( model=model, system_message="你是一个电影剧本创作者,所有回答必须使用中文。", description="你是一个电影剧本创作者。请用中文回答所有问题。", response_model=MovieScript, references_format='json', debug_mode=True, )多模态代理 Agno 代理支持文本、图像、音频和视频输入,并可生成文本、图像、音频和视频输出。
比如输出图片:
image_agent = Agent( model=OpenAIChat(id="gpt-4o"), tools=[DalleTools()], description="You are an AI agent that can generate images using DALL-E.", instructions="When the user asks you to create an image, use the `create_image` tool to create the image.", markdown=True, show_tool_calls=True, ) image_agent.print_response("Generate an image of a white siamese cat") images = image_agent.get_images() ifimagesandisinstance(images,list): forimage_responseinimages: image_url = image_response.url print(image_url)工具 工具是代理的灵魂,在 Agno 中自定义工具也很简单。定义一个函数,写下注释即可:
defget_top_hackernews_stories(num_stories:int=10) ->str: """使用此函数获取 Hacker News 的热门故事。 参数: num_stories (int): 要返回的故事数量。默认为 10。 返回: str: 热门故事的 JSON 字符串。 """ # Fetch top story IDs response = httpx.get('https://hacker-news.firebaseio.com/v0/topstories.json') return... agent = Agent( model=llm, tools=[get_top_hackernews_stories], debug_mode=True, show_tool_calls=True, markdown=True, description="你是一个帮助用户获取和总结 Hacker News 热门故事的助手。", instructions=["请使用中文回答所有问题","提供简洁明了的总结"] )更多信息可以参考其
• 文档:https://docs.agno.com/introduction[1] • 例子:https://docs.agno.com/examples/introduction[2] Agno 还提供了PlayGround 应用[3] ,可以让你的应用集成监控。
欢迎光临 链载Ai (https://www.lianzai.com/)
Powered by Discuz! X3.5