基于 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里面,接受入参为对话 messagesJson格式


@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 KeyAgentScope 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  最终AgentChat接口: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": ""}


相关文章
|
2月前
|
存储 自然语言处理 搜索推荐
RAG 应用 —— 解锁大模型在各行业的落地场景与价值
RAG(检索增强生成)技术通过实时接入行业知识库,有效解决大模型知识过时、易幻觉、难适配等痛点,已在金融、医疗、教育、法律、电商五大领域规模化落地,显著提升准确性、合规性与响应效率,成为大模型行业应用的首选路径。(239字)
|
2月前
|
机器学习/深度学习 存储 自然语言处理
蚂蚁集团 Ling-2.5-1T 开源:万亿参数,重新定义"又快又强"
Ling-2.5-1T是蚂蚁集团inclusionAI推出的开源即时大模型(MIT协议),以“效率×效果”为核心:万亿参数、63B激活,首创混合线性注意力架构,支持百万token上下文;推理吞吐大幅提升,AIME任务仅需1/3 token即达前沿思考模型水平。ModelScope可下载。
618 4
蚂蚁集团 Ling-2.5-1T 开源:万亿参数,重新定义"又快又强"
|
4月前
|
人工智能 Java Serverless
AgentScope Java 答疑时间:开发者近期最关心的12个问题
近日,AgentScope Java V1.0 版本正式发布,全面对齐 Python 版核心能力,为 Java 开发者带来了构建企业级 Agentic 应用强大的开源方案。在最近与 DataWhale 合作的 AgentScope Java 解读线上直播间中,我们收到了大家的热情提问。为了方便大家集中查阅,我们整理了其中最高频的 Q&A,由 AgentScope Java 的核心开发者为大家一次性说清讲透!
1153 51
|
3月前
|
安全 API 开发者
手把手带你使用无影 AgentBay + AgentScope 完成一站式智能体开发部署
阿里云无影 AgentBay 作为一个面向 AI 智能体开发的云端 GUI 沙箱服务,已集成至阿里巴巴通义实验室开源的 AgentScope 框架,助力开发者快速构建安全、高效的智能体应用。
1476 1
|
2月前
|
安全 API Docker
[大模型实战 02] 图形化的大模型交互: Open WebUI部署指南
本文教你用 Docker 一键部署 Open WebUI,为本地 Ollama 模型打造媲美 ChatGPT 的图形化界面:支持流畅对话、本地知识库(RAG)检索增强、自定义角色(Agent),全程私有化、零数据上传,10分钟即可启用!
|
4月前
|
数据可视化 前端开发 安全
AgentScope 1.0 全面进化,从原型走向产业落地!
AgentScope全新升级,打造生产级智能体生态:推出开箱即用的Alias、EvoTraders等应用,支持多场景落地;强化基建,实现动态技能扩展、白盒化运行与多语言支持;集成语音交互、数据工程等能力,提供从开发到部署的全链路解决方案。
2829 0
|
1月前
|
人工智能 安全 Linux
从"单兵作战"到"AI军团":OpenClaw/HiClaw阿里云/MacOS/Linux/Windows本地部署+免费API配置+多Agent协作指南
OpenClaw以"自然语言操控软件"的创新交互,成为2026年最热门的AI工具之一——写代码、查邮件、管理GitHub、设置定时任务,只需一句指令即可完成。但当用户尝试用它处理复杂项目、组建多Agent团队时,一系列痛点逐渐暴露:API密钥散落导致的安全风险、记忆混杂造成的效率低下、多Agent协作的手动成本、移动端体验不佳、配置门槛过高等。2026年1月的CVE-2026-25253漏洞更是敲响警钟,让原生架构的"自我可攻击"特性浮出水面。
1761 4
|
1月前
|
机器学习/深度学习 人工智能 文字识别
小红书开源FireRed-OCR,2B 参数登顶文档解析榜单
小红书FireRed团队开源的FireRed-OCR(仅20亿参数),在OmniDocBench v1.5端到端评测中以92.94%综合得分登顶,超越Gemini 3.0 Pro等大模型。专注解决文档解析中的“结构幻觉”问题,通过三阶段训练+格式约束强化学习,精准还原表格、公式、多栏等复杂结构。Apache 2.0协议,ModelScope开源,支持本地商用部署。(239字)
783 22

热门文章

最新文章

下一篇
开通oss服务