基于 AgentScope x AI Agent A2Z部署平台的生产级别Agent上线Live实战分享

简介: 本文分享如何用AgentScope框架+AI Agent A2Z平台,一键完成AI Agent生产级部署:解决“开发易、上线难”痛点,快速生成标准/chat接口(如https://agentscope.aiagenta2z.com/deep_research_agent/chat),支持高并发、实时监控与冷启动。

1. 简介

在 AI Agent 开发领域,我们除了面临Agent框架选择(LangChain/LangGraph/AgentScope)等, 我们经常面临“开发容易,上线难”的尴尬:
本地运行 AgentScope 脚本非常顺滑,但一旦要转化为支撑高并发、具备标准接口、且能实时监控的生产级服务,往往涉及复杂的环境配置、网络穿透和接口封装。

本文将分享如何利用 AI Agent A2Z 部署和平台,结合 AgentScope 框架,快速实现 Agent 的生产级部署与冷启动,可以1键丝滑上线,得到/chat接口 endpoint


image.png



2. 实战分享


2.1 项目选型:AgentScope x AI Agent A2Z


AgentScope:由阿里团队开源,擅长多智能体协作(Multi-Agent)和灵活的消息机制,是构建复杂业务逻辑的首选。

AI Agent A2Z:一个专注于“高代码(High-Code)”的 Agent 部署与 Router 分发平台。它解决了 Agent 上线部署的最后一步——将 Python/NodeJs 等Agent代码转化为可以提供服务Agent,提供启动脚本权限(uvicorn/npm)等, 支持具备独立域名(.aiagenta2z.com/{project}/chat 等) 的 标准 API,可以直接通过Agent Router Web界面入口完成上线和给用户使用,流量冷启动阶段。


2.2 准备工作


2.3 完整案例

第一步:准备代码模板

我们以AgentScope代码库中 deep research agent (https://github.com/agentscope-ai/agentscope/tree/main/examples/agent/deep_research_agent) 为例,

经过把本地agent 改造为 FastAPI的服务之后提供一个/chat 接口出来,完成Agent的部署。


这里原先案例入口是 main.py文件,转化为 FastAPI服务的接口为 main_server.py 文件

https://github.com/aiagenta2z/agent-mcp-deployment-templates/blob/main/agentscope_examples/deep_research_agent/main_server.py

核心的 FastAPI入口在这里,

初始化:startup_event中新建了agent 类,完成了 tavily等工具mcp的注册和连接。

stream_generator 定义了一个异步生成器,里面 agent.reply 返回接口 (原先的agent返回实现是耗时比较久,我们这边先不做改造 )


`
    response_msg = await agent.reply(msg)
    print (f"Agent Reply: response {response_msg}")
    response_content = response_msg.content
    print (f"Agent Reply: response response_content {response_content}")


FastAPI应用暴露Agent的接口到/chat里面,接受入参为对话 messages的Json格式


@app.post("/chat")
async def chat(request: ChatRequest) -> StreamingResponse:
    """ Convert the DeepResearch Agent to Live Service."""
    global tavily_search_client, agent
    if agent is None:
        raise HTTPException(status_code=503, detail="Agent not initialized")

    try:
        messages = request.messages
        user_query = ""
        try:
            user_query = messages[-1]["content"] if len(messages) > 0 else "hello"
        except Exception as e1:
            print (f"Failed to process input messages: {e1}")
        print (f"DEBUG: user: {user_query}")
        user_name = "USER_"
        ## set to 1 iteration for example
        msg = Msg(
            user_name,
            content=user_query,
            role="user"
        )

        return StreamingResponse(
            stream_generator(agent, msg),
            media_type="application/json",
        )

    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Failed to chat: {str(e)}") from e
  
async def stream_generator(agent, msg):
    """
    Generator for Chat Messages Assemble AgentScope Response

    message_type: "user", "assistant"
    output_format: "text", "html"
    content_type: "text/markdown", mime-type

    SECTION_THINK = "think"
    SECTION_ANSWER = "answer"
    SECTION_TOOL = "tool"
    SECTION_SYSTEM_MSG = "system_msg"
    SECTION_CONTEXT = "context"

    TEMPLATE_REASONING_HTML = "reason_html"
    TEMPLATE_STREAMING_CONTENT_TYPE = "streaming_content_type"
    """
    message_type = "assistant"
    output_format = "text"
    content_type = "text/markdown"
    section = "answer"
    streaming_separator = "\n"
    TEMPLATE_STREAMING_CONTENT_TYPE = "streaming_content_type"

    ## Initial Chunk
    initial_chunk = json.dumps(assembly_message(message_type, output_format, "DeepResearch Task Starting...", content_type=content_type, section=section, message_id= str(uuid.uuid4()), template=TEMPLATE_STREAMING_CONTENT_TYPE) )
    yield initial_chunk + streaming_separator

    ## result is a message class Msg
    response_msg = await agent.reply(msg)
    print (f"Agent Reply: response {response_msg}")
    response_content = response_msg.content
    print (f"Agent Reply: response response_content {response_content}")

    output_message_id = response_msg.id
    content_type_chunk = json.dumps(assembly_message(message_type, output_format, response_content, content_type=content_type, section=section, message_id=output_message_id, template=TEMPLATE_STREAMING_CONTENT_TYPE) )

    print (f"stream_generator response Result: {response_msg}")
    yield content_type_chunk + streaming_separator


第三步:在平台创建部署

登录 AI Agent A2Z 部署平台。


1. 首先创建一个Agent (owner/repo) 作为部署的unique_id项目,
2. 进入部署平台DeepNLP Workspace -> Deployment,选择好之前创建项目 (owner/repo) , 上传你的 Agent 代码包或关联 GitHub 仓库。

这里我们直接从github模板部署:

选择: GitHub,输入Public URL 选择: https://github.com/aiagenta2z/agent-mcp-deployment-templates
Entry Point启动命令行:uvicorn agentscope.deep_research_agent.main_server:app

注意:这里是从以 module方式启动的,项目根目录是 github下载后的目录,相当于你 cd aiagenta2z/agent-mcp-deployment-templates进入了,

启动命令行从 github的项目root开始,所以是 agentscope.xxxx

3. 设置配置环境变量(如 LLM API Key、AgentScope Config 等)。

可以从 Dashscope官网和Tavily 官网下载,这里用dummy 的 设置不影响部署流程。

export DASHSCOPE_API_KEY="your_dashscope_api_key_here"
export TAVILY_API_KEY="your_tavily_api_key_here"


4. 点击Deploy 查看日志


INFO:     Started server process [1]
INFO:     Waiting for application startup.
Application startup...
Tavily MCP server running on stdio
2026-02-11 04:00:19,324 | INFO    | _stateful_client_base:connect:66 - MCP client connected.
Lifecycle closed at the end...
INFO:     Application startup complete.
> SUCCESS: ✅ Deployment Complete!


最终交付:

上线Agent  最终Agent的Chat接口:agentscope.aiagenta2z.com/deep_research_agent/chat
上线Agent Playground:


第四步、验证


我们可以通过 curl POST 请求来访问到你部署的Agent应用,


比如我们让Deep Research agent调研 prompt: 1+1等于?

curl -X POST "https://agentscope.aiagenta2z.com/deep_research_agent/chat" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Calculate 1+1 result"}]}'


最终返回的Streaming Chunk的结果


{"type": "assistant", "format": "text", "content": "DeepResearch Task Starting...", "section": "answer", "message_id": "202d21fd-c71b-4a11-ba35-e2cb3c7d5947", "content_type": "text/markdown", "template": "streaming_content_type", "task_ids": "", "tab_message_ids": "", "tab_id": ""}
{"type": "assistant", "format": "text", "content": "{\n  \"type\": \"text\",\n  \"text\": \"Overwrite /app/agentscope_examples/deep_research_agent/deepresearch_agent_demo_env/Friday260211040019_detailed_report.md successfully.\\n# Calculation of 1 + 1: A Foundational Arithmetic Operation\\n\\n## Step 1: Confirming the Context of the Operation\\n\\nThe expression \\\"1 + 1\\\" is interpreted within the standard framework of elementary arithmetic unless otherwise specified. In this context:\\n\\n- The numerals \\\"1\\\" represent the natural number one, which is the first positive integer in the set \u2115 = {1, 2, 3, ...} (or sometimes defined to include 0, depending on convention).\\n- The symbol \\\"+\\\" denotes the binary operation of addition as defined in the Peano axioms for natural numbers or as commonly taught in primary education.\\n- The numeral system assumed is base-10 (decimal), which is the standard positional numeral system used globally for everyday arithmetic.\\n\\nNo alternative interpretations\u2014such as those from Boolean logic, modular arithmetic, or abstract algebra\u2014are indicated in the subtask, so we proceed under the assumption of classical arithmetic in the natural numbers.\\n\\n## Step 2: Performing the Calculation\\n\\nUsing the definition of addition for natural numbers:\\n\\n- By the successor function in Peano arithmetic, the number 2 is defined as the successor of 1, denoted S(1).\\n- Addition is recursively defined such that:\\n  - \\\\( a + 0 = a \\\\)\\n  - \\\\( a + S(b) = S(a + b) \\\\)\\n\\nThus:\\n\\\\[\\n1 + 1 = 1 + S(0) = S(1 + 0) = S(1) = 2\\n\\\\]\\n\\nAlternatively, from empirical and educational foundations:\\n- Counting one object and then adding another yields a total of two objects.\\n- This is consistent across physical, symbolic, and computational representations.\\n\\nTherefore, **1 + 1 = 2**.\\n\\n## Step 3: Validation\\n\\nThis result is universally accepted in standard mathematics and has been formally verified in foundational logical systems. Notably:\\n\\n- In *Principia Mathematica* by Alfred North Whitehead and Bertrand Russell (1910\u20131913), the proposition \\\"1 + 1 = 2\\\" is rigorously derived from set-theoretic and logical axioms. It appears as Proposition \u221754.43 in Volume I, with the actual proof completed in Volume II after hundreds of pages of preliminary logic. While famously taking over 300 pages to reach, this underscores the depth of formal verification possible\u2014even for seemingly trivial statements.\\n\\n- Modern computational systems (e.g., calculators, programming languages like Python, MATLAB, or Wolfram Language) all return `2` when evaluating `1 + 1`.\\n\\n- Educational curricula worldwide introduce this as the first non-trivial addition fact, reinforcing its role as a cornerstone of numerical literacy.\\n\\n## Conclusion\\n\\nUnder standard arithmetic in the base-10 numeral system, using the conventional meaning of numerals and the addition operator, the expression **1 + 1 evaluates unequivocally to 2**. This result is mathematically sound, logically consistent, empirically verifiable, and computationally confirmed.\\n\\n**Final Answer: 2**\"\n}", "section": "answer", "message_id": "My5UpF5iRxcWbyooMHqogZ", "content_type": "text/markdown", "template": "streaming_content_type", "task_ids": "", "tab_message_ids": "", "tab_id": ""}


相关文章
|
10月前
|
人工智能 Java Serverless
AgentScope Java 答疑时间:开发者近期最关心的12个问题
近日,AgentScope Java V1.0 版本正式发布,全面对齐 Python 版核心能力,为 Java 开发者带来了构建企业级 Agentic 应用强大的开源方案。在最近与 DataWhale 合作的 AgentScope Java 解读线上直播间中,我们收到了大家的热情提问。为了方便大家集中查阅,我们整理了其中最高频的 Q&A,由 AgentScope Java 的核心开发者为大家一次性说清讲透!
2009 83
|
3月前
|
存储 前端开发 Java
AgentScope 2.0 生产可用,企业级 Harness 底座全解析!
AgentScope 2.0 GA 发布,打造企业级分布式智能体Harness底座。
3677 20
|
8月前
|
机器学习/深度学习 存储 自然语言处理
蚂蚁集团 Ling-2.5-1T 开源:万亿参数,重新定义"又快又强"
Ling-2.5-1T是蚂蚁集团inclusionAI推出的开源即时大模型(MIT协议),以“效率×效果”为核心:万亿参数、63B激活,首创混合线性注意力架构,支持百万token上下文;推理吞吐大幅提升,AIME任务仅需1/3 token即达前沿思考模型水平。ModelScope可下载。
1347 4
蚂蚁集团 Ling-2.5-1T 开源:万亿参数,重新定义"又快又强"
|
存储 人工智能 API
AgentScope:阿里开源多智能体低代码开发平台,支持一键导出源码、多种模型API和本地模型部署
AgentScope是阿里巴巴集团开源的多智能体开发平台,旨在帮助开发者轻松构建和部署多智能体应用。该平台提供分布式支持,内置多种模型API和本地模型部署选项,支持多模态数据处理。
17319 78
AgentScope:阿里开源多智能体低代码开发平台,支持一键导出源码、多种模型API和本地模型部署
|
人工智能 安全 Java
分布式 Multi Agent 安全高可用探索与实践
在人工智能加速发展的今天,AI Agent 正在成为推动“人工智能+”战略落地的核心引擎。无论是技术趋势还是政策导向,都预示着一场深刻的变革正在发生。如果你也在探索 Agent 的应用场景,欢迎关注 AgentScope 项目,或尝试使用阿里云 MSE + Higress + Nacos 构建属于你的 AI 原生应用。一起,走进智能体的新世界。
1982 106
|
7月前
|
SQL Java API
Agent 越用越聪明?AgentScope Java 在线训练插件来了!
使用AgentScope Java + Trinity-RFT 在线训练优化你的Agent,让你的Agent边运行边进化。
1656 53
|
4月前
|
存储 人工智能 Java
2026年AgentScope Java 2.0详解:架构升级、分布式企业级智能体底座全解析
在AI智能体规模化落地的当下,原型验证阶段的简单运行已经无法满足企业生产环境的严苛要求。多数企业在部署AI智能体时,普遍遭遇分布式扩展困难、多租户数据隔离缺失、长期运行稳定性差、权限管控薄弱、模型调用易中断等一系列工程化难题。2026年6月,阿里正式推出**AgentScope Java 2.0**版本,作为AgentScope多语言体系的重要升级产物,该版本面向JVM生态深度优化,聚焦企业级生产场景,将分布式部署、多租户隔离、安全权限、容错机制等能力内化为框架原生特性,真正实现了从原型Demo到工业级智能体底座的跨越。本文结合框架架构、核心组件、关键能力、部署模式、扩展机制以及落地场景展开全
2894 0
|
10月前
|
数据可视化 前端开发 安全
AgentScope 1.0 全面进化,从原型走向产业落地!
AgentScope全新升级,打造生产级智能体生态:推出开箱即用的Alias、EvoTraders等应用,支持多场景落地;强化基建,实现动态技能扩展、白盒化运行与多语言支持;集成语音交互、数据工程等能力,提供从开发到部署的全链路解决方案。
5375 0

热门文章

最新文章