Agent 平臺(tái)化思考:從定制化開發(fā)到通用 Agent 平臺(tái)的架構(gòu)演進(jìn)
Agent 平臺(tái)化思考從定制化開發(fā)到通用 Agent 平臺(tái)的架構(gòu)演進(jìn)一、從一個(gè) Agent 一個(gè)項(xiàng)目到Agent 平臺(tái)工程化必經(jīng)之路2026 年初某 SaaS 公司面臨一個(gè)困境過(guò)去一年他們?yōu)椴煌蛻粜枨箝_發(fā)了 15 個(gè)獨(dú)立的 Agent 項(xiàng)目。這些項(xiàng)目技術(shù)棧各異、代碼重復(fù)率高達(dá) 60%、維護(hù)成本巨大。更糟糕的是當(dāng)某個(gè)客戶需要一個(gè)新功能其實(shí)是其他 Agent 已有的功能時(shí)他們需要重新開發(fā)無(wú)法復(fù)用。這不是個(gè)案。隨著 Agent 技術(shù)從實(shí)驗(yàn)走向生產(chǎn)平臺(tái)化成為必然趨勢(shì)。本文將討論 Agent 平臺(tái)化的架構(gòu)演進(jìn)路徑。二、階段一定制化開發(fā)反模式典型問題場(chǎng)景客戶 A 需要一個(gè)客服 Agent客戶 B 需要一個(gè)銷售 Agent。反模式實(shí)現(xiàn)# 項(xiàng)目 1: 客服 Agent獨(dú)立代碼庫(kù) # customer_service_agent/ # ├── main.py # ├── tools/ # │ ├── query_order.py # │ ├── cancel_order.py # │ └── search_kb.py # └── prompts/ # └── system_prompt.txt # 項(xiàng)目 2: 銷售 Agent另一個(gè)獨(dú)立代碼庫(kù) # sales_agent/ # ├── main.py # 跟客服 Agent 的 main.py 有 70% 相同 # ├── tools/ # │ ├── search_products.py # 新工具 # │ ├── query_order.py # 重復(fù)跟客服 Agent 一樣 # │ └── create_order.py # └── prompts/ # └── system_prompt.txt # 問題 # 1. query_order 工具重復(fù)實(shí)現(xiàn)維護(hù)困難 # 2. main.py 邏輯重復(fù)代碼冗余 # 3. 兩個(gè) Agent 無(wú)法共享上下文用戶先從客服問問題再找銷售上下文丟失問題清單三、階段二模塊化改進(jìn)核心思路抽取公共庫(kù)# 公共庫(kù)agent_common/ # ├── core/ # │ ├── agent.py # Agent 核心邏輯 # │ ├── tool_registry.py # 工具注冊(cè)中心 # │ └── memory.py # 記憶管理 # ├── tools/ # │ ├── query_order.py # 公共工具 # │ ├── search_kb.py # │ └── base_tool.py # 工具基類 # └── utils/ # ├── llm_client.py # └── prompt_template.py # 客服 Agent 項(xiàng)目簡(jiǎn)化 from agent_common.core import Agent, ToolRegistry from agent_common.tools import QueryOrderTool, SearchKBTool class CustomerServiceAgent(Agent): def __init__(self): super().__init__() # 注冊(cè)工具 self.registry.register(QueryOrderTool()) self.registry.register(SearchKBTool()) # 添加客服特有的工具 self.registry.register(CancelOrderTool()) # 銷售 Agent 項(xiàng)目簡(jiǎn)化 from agent_common.core import Agent, ToolRegistry from agent_common.tools import QueryOrderTool, SearchKBTool # 復(fù)用 class SalesAgent(Agent): def __init__(self): super().__init__() # 復(fù)用公共工具 self.registry.register(QueryOrderTool()) # 直接復(fù)用 self.registry.register(SearchKBTool()) # 添加銷售特有的工具 self.registry.register(SearchProductsTool()) self.registry.register(CreateOrderTool())生產(chǎn)級(jí)實(shí)現(xiàn)工具注冊(cè)中心from abc import ABC, abstractmethod from typing import Dict, List, Any import importlib import json class BaseTool(ABC): 工具基類 abstractmethod def get_name(self) - str: pass abstractmethod def get_description(self) - str: pass abstractmethod def get_parameters(self) - Dict: pass abstractmethod def execute(self, **params) - Any: pass def to_function_calling_schema(self) - Dict: 轉(zhuǎn)換為 Function Calling 格式 return { type: function, function: { name: self.get_name(), description: self.get_description(), parameters: self.get_parameters() } } class ToolRegistry: 工具注冊(cè)中心單例 _instance None _tools: Dict[str, BaseTool] {} def __new__(cls): if cls._instance is None: cls._instance super().__new__(cls) return cls._instance def register(self, tool: BaseTool): 注冊(cè)工具 name tool.get_name() if name in self._tools: raise ValueError(fTool {name} already registered) self._tools[name] tool def get_tool(self, name: str) - BaseTool: 獲取工具 return self._tools.get(name) def list_tools(self) - List[Dict]: 列出所有工具用于 LLM Function Calling return [tool.to_function_calling_schema() for tool in self._tools.values()] def load_tools_from_config(self, config_path: str): 從配置文件加載工具 with open(config_path, r) as f: config json.load(f) for tool_config in config[tools]: module_path tool_config[module] class_name tool_config[class] # 動(dòng)態(tài)加載 module importlib.import_module(module_path) tool_class getattr(module, class_name) tool_instance tool_class() self.register(tool_instance) # 示例工具實(shí)現(xiàn) class QueryOrderTool(BaseTool): 查詢訂單工具 def get_name(self) - str: return query_order def get_description(self) - str: return 根據(jù)用戶 ID 或訂單 ID 查詢訂單信息 def get_parameters(self) - Dict: return { type: object, properties: { user_id: {type: string, description: 用戶 ID}, order_id: {type: string, description: 訂單 ID} }, required: [] } def execute(self, **params) - Dict: user_id params.get(user_id) order_id params.get(order_id) # 查詢數(shù)據(jù)庫(kù)簡(jiǎn)化 if order_id: return {order_id: order_id, status: shipped, amount: 99.9} elif user_id: return {user_id: user_id, orders: [{id: 123, status: shipped}]} else: raise ValueError(user_id or order_id required) # 使用 registry ToolRegistry() registry.register(QueryOrderTool())模塊化的局限雖然模塊化解決了代碼復(fù)用問題但還有部署問題每個(gè) Agent 還是獨(dú)立部署擴(kuò)縮容問題無(wú)法根據(jù)負(fù)載動(dòng)態(tài)調(diào)度監(jiān)控問題每個(gè) Agent 獨(dú)立監(jiān)控缺乏全局視圖四、階段三平臺(tái)化目標(biāo)平臺(tái)化架構(gòu)核心設(shè)計(jì)Agent 配置 工具列表關(guān)鍵洞察Agent 的本質(zhì)是系統(tǒng) prompt 工具列表 記憶管理策略。from pydantic import BaseModel from typing import List, Optional class AgentConfig(BaseModel): Agent 配置可序列化 agent_id: str name: str description: str # 系統(tǒng) Prompt system_prompt: str # 工具列表引用工具池中的工具 tools: List[str] # tool names # 記憶策略 memory_config: Dict # 模型配置 model_config: Dict # 其他配置 max_iterations: int 10 timeout: int 60 class AgentPlatform: Agent 平臺(tái) def __init__(self): self.tool_registry ToolRegistry() self.agent_configs: Dict[str, AgentConfig] {} self.agent_instances: Dict[str, Agent] {} def register_agent(self, config: AgentConfig): 注冊(cè) Agent只需配置 self.agent_configs[config.agent_id] config def get_agent(self, agent_id: str) - Agent: 獲取 Agent 實(shí)例懶加載 if agent_id not in self.agent_instances: config self.agent_configs[agent_id] # 根據(jù)配置創(chuàng)建 Agent agent self._create_agent_from_config(config) self.agent_instances[agent_id] agent return self.agent_instances[agent_id] def _create_agent_from_config(self, config: AgentConfig) - Agent: 根據(jù)配置創(chuàng)建 Agent # 1. 加載工具 tools [] for tool_name in config.tools: tool self.tool_registry.get_tool(tool_name) if tool: tools.append(tool) # 2. 創(chuàng)建 Agent agent Agent( system_promptconfig.system_prompt, toolstools, memory_configconfig.memory_config, model_configconfig.model_config ) return agent async def run_agent(self, agent_id: str, user_input: str, context: Dict) - str: 運(yùn)行 Agent agent self.get_agent(agent_id) return await agent.run(user_input, context) # 使用示例只需配置無(wú)需寫代碼 def create_customer_service_agent_via_config(): 通過(guò)配置創(chuàng)建客服 Agent config AgentConfig( agent_idcustomer_service, name智能客服, description處理用戶咨詢、訂單查詢、退款, system_prompt你是客服助手友好、專業(yè)..., tools[ query_order, cancel_order, search_kb ], memory_config{ type: buffer, max_turns: 10 }, model_config{ model: gpt-4, temperature: 0.7 } ) # 注冊(cè)到平臺(tái) platform AgentPlatform() platform.register_agent(config) return platform # 現(xiàn)在新 Agent 只需寫配置文件 # sales_agent_config.json: { agent_id: sales, name: 銷售助手, tools: [query_order, search_products, create_order], system_prompt: ... } 平臺(tái)化核心功能class AgentPlatformAdvanced: 高級(jí) Agent 平臺(tái)生產(chǎn)級(jí) def __init__(self): self.tool_registry ToolRegistry() self.agent_configs {} self.executor_pool AgentExecutorPool(max_workers100) self.monitor PlatformMonitor() # 功能 1: Agent 模板市場(chǎng) def list_agent_templates(self) - List[Dict]: 列出 Agent 模板 templates [ { id: customer_service, name: 智能客服, description: 適用于電商客服場(chǎng)景, tools: [query_order, cancel_order, search_kb], preview: https://... }, # ... ] return templates def create_agent_from_template(self, template_id: str, customizations: Dict) - str: 從模板創(chuàng)建 Agent # 復(fù)制模板配置 template self._get_template(template_id) config AgentConfig(**template) # 應(yīng)用自定義 for key, value in customizations.items(): setattr(config, key, value) # 生成唯一 ID config.agent_id f{template_id}_{uuid.uuid4().hex[:8]} # 注冊(cè) self.register_agent(config) return config.agent_id # 功能 2: 工具市場(chǎng) def list_tool_market(self) - List[Dict]: 列出可用工具 return [ { name: query_order, description: 查詢訂單, usage_count: 1000, rating: 4.5 }, # ... ] # 功能 3: 多 Agent 協(xié)作 async def run_multi_agent(self, workflow: Dict, user_input: str) - str: 運(yùn)行多 Agent 工作流 # workflow 示例 # { # steps: [ # {agent: customer_service, input: {{user_input}}}, # {agent: sales, input: {{previous_output}}}, # ] # } context {user_input: user_input} for step in workflow[steps]: agent_id step[agent] step_input self._render_template(step[input], context) agent self.get_agent(agent_id) output await agent.run(step_input, context) context[f{agent_id}_output] output return context[workflow[steps][-1][agent] _output] # 功能 4: 監(jiān)控和分析 def get_platform_metrics(self) - Dict: 獲取平臺(tái)指標(biāo) return { total_agents: len(self.agent_configs), active_agents: len(self.agent_instances), total_calls_24h: self.monitor.get_total_calls(hours24), avg_latency: self.monitor.get_avg_latency(), error_rate: self.monitor.get_error_rate(), cost_24h: self.monitor.get_cost(hours24) }結(jié)論Agent 平臺(tái)化架構(gòu)演進(jìn)階段一定制化避免問題代碼重復(fù)、維護(hù)困難適用快速驗(yàn)證 1 個(gè)月階段二模塊化推薦改進(jìn)代碼復(fù)用適用2-5 個(gè) Agent階段三平臺(tái)化目標(biāo)優(yōu)點(diǎn)快速構(gòu)建、統(tǒng)一運(yùn)維、工具共享適用 5 個(gè) Agent平臺(tái)化核心設(shè)計(jì)Agent 配置 工具列表工具池共享工具Agent 模板市場(chǎng)多 Agent 協(xié)作編排實(shí)施路線第 1-2 月模塊化抽取公共庫(kù)第 3-4 月設(shè)計(jì)平臺(tái)架構(gòu)第 5-6 月實(shí)現(xiàn) MVP 平臺(tái)第 7-12 月迭代優(yōu)化關(guān)鍵建議不要過(guò)早平臺(tái)化YAGNI 原則先有 3 個(gè) Agent 再考慮平臺(tái)化平臺(tái)化的關(guān)鍵是配置化而不是代碼化

相關(guān)新聞

ZX8002D單通道觸摸臺(tái)燈 化妝鏡 觸摸芯片帶鋰電池充電功能IC

ZX8002D單通道觸摸臺(tái)燈 化妝鏡 觸摸芯片帶鋰電池充電功能IC

一、ZX8002D方案概述 本方案以泛海微電子推出的ZX8002D單通道觸摸調(diào)光芯片為核心,針對(duì)LED臺(tái)燈、LED化妝鏡等小型LED照明產(chǎn)品設(shè)計(jì),實(shí)現(xiàn)單按鍵控制三檔亮度循環(huán)調(diào)節(jié)的功能。芯片集成了鋰電池充電管理模塊,支持2.5V-5V寬電壓輸入,無(wú)…

2026/7/29 9:16:11 閱讀更多
VLYNQ高速串行接口協(xié)議深度解析:從寄存器配置到性能優(yōu)化實(shí)戰(zhàn)

VLYNQ高速串行接口協(xié)議深度解析:從寄存器配置到性能優(yōu)化實(shí)戰(zhàn)

1. 項(xiàng)目概述與VLYNQ協(xié)議核心價(jià)值在嵌入式系統(tǒng),尤其是多核處理器、DSP陣列或者異構(gòu)計(jì)算平臺(tái)(比如DSPFPGA)的設(shè)計(jì)中,芯片間的高速、可靠、低延遲通信是決定系統(tǒng)整體性能的瓶頸之一。傳統(tǒng)的并行總線雖然速度快,但引腳數(shù)量…

2026/7/29 10:16:24 閱讀更多
2D 游戲美術(shù)資產(chǎn)快速生成:用 GPT-Image 制作游戲貼圖與精靈圖

2D 游戲美術(shù)資產(chǎn)快速生成:用 GPT-Image 制作游戲貼圖與精靈圖

對(duì)于獨(dú)立游戲開發(fā)者而言,美術(shù)資產(chǎn)的制作向來(lái)是高成本、長(zhǎng)周期的痛點(diǎn)。尤其是需要生成特定透視視角(如45度俯視角、正側(cè)面)的道具、圖標(biāo)與場(chǎng)景貼圖時(shí),僅靠文本描述很難保證視角的精準(zhǔn)統(tǒng)一。如今,通過(guò)玉芬AI(…

2026/7/29 10:16:24 閱讀更多
CC1100射頻收發(fā)器設(shè)計(jì)指南:從核心參數(shù)到低功耗無(wú)線通信實(shí)戰(zhàn)

CC1100射頻收發(fā)器設(shè)計(jì)指南:從核心參數(shù)到低功耗無(wú)線通信實(shí)戰(zhàn)

1. 項(xiàng)目概述與芯片定位在無(wú)線通信的世界里,Sub-1GHz頻段(如315MHz、433MHz、868MHz、915MHz)因其繞射能力強(qiáng)、穿透性好、傳輸距離遠(yuǎn)等特性,一直是遠(yuǎn)程控制、工業(yè)傳感、智能計(jì)量和物聯(lián)網(wǎng)(IoT)等領(lǐng)域的黃金頻…

2026/7/29 10:16:24 閱讀更多
報(bào)錯(cuò)截圖一鍵修復(fù):程序員如何用 GPT-Image 快速定位并解決代碼 Bug?

報(bào)錯(cuò)截圖一鍵修復(fù):程序員如何用 GPT-Image 快速定位并解決代碼 Bug?

在日常開發(fā)中,面對(duì)控制臺(tái)(Console)彈出的一大堆紅色報(bào)錯(cuò)日志,復(fù)制粘貼給 AI 往往會(huì)因?yàn)楦袷藉e(cuò)亂、遺漏關(guān)鍵上下文而導(dǎo)致診斷不準(zhǔn)確?,F(xiàn)在,許多開發(fā)者開始借助玉芬AI( neneai.cn )這類 AI 模型聚…

2026/7/29 10:16:24 閱讀更多
手繪草圖秒變網(wǎng)頁(yè):GPT-Image + Claude 前端開發(fā)實(shí)戰(zhàn)與選型指南

手繪草圖秒變網(wǎng)頁(yè):GPT-Image + Claude 前端開發(fā)實(shí)戰(zhàn)與選型指南

產(chǎn)品經(jīng)理或前端開發(fā)在日常工作中,經(jīng)常需要將白紙上的手繪原型轉(zhuǎn)化為可運(yùn)行的頁(yè)面。過(guò)去這個(gè)過(guò)程需要經(jīng)歷“手繪-墨刀/Axure高保真-切圖-寫HTML/CSS”等多個(gè)環(huán)節(jié),耗時(shí)數(shù)天。如今,通過(guò)像玉芬AI( neneai.cn) 這樣的AI模型…

2026/7/29 10:16:24 閱讀更多
創(chuàng)客大篷車與Make Faire:深圳硬核創(chuàng)新文化的流動(dòng)實(shí)踐

創(chuàng)客大篷車與Make Faire:深圳硬核創(chuàng)新文化的流動(dòng)實(shí)踐

1. 從“大篷車”到“腦洞集市”:一場(chǎng)流動(dòng)的創(chuàng)造力盛宴 如果你在深圳的街頭,看到一輛色彩斑斕、滿載著各種稀奇古怪裝置的大巴車,旁邊圍著一群眼睛發(fā)亮、手里拿著電烙鐵或3D打印筆的人,別懷疑,你大概率是撞上了“創(chuàng)客大…

2026/7/29 10:06:24 閱讀更多
面試官大笑:“一個(gè)任務(wù)拆給 5 個(gè) Subagent 并行跑,不比 1 個(gè)快 5 倍?“我搖頭:“快不了,還可能更慢“

面試官大笑:“一個(gè)任務(wù)拆給 5 個(gè) Subagent 并行跑,不比 1 個(gè)快 5 倍?“我搖頭:“快不了,還可能更慢“

前兩個(gè)月,我在重構(gòu) AlgoMooc 網(wǎng)站過(guò)程中,發(fā)現(xiàn)一個(gè)問題:在 Claude Code 里把一個(gè)任務(wù)拆給 5 個(gè) Subagent 并行跑,結(jié)果可能比 1 個(gè) agent 從頭干到尾還慢? 大多數(shù)人的第一反應(yīng)是反過(guò)來(lái)的:活是并行干的&#…

2026/7/29 0:15:24 閱讀更多
# 鴻蒙 HarmonyOS 應(yīng)用開發(fā)實(shí)戰(zhàn)(第25期)|骰子(Dice Roller)— Unicode 符號(hào)與動(dòng)畫渲染精講

# 鴻蒙 HarmonyOS 應(yīng)用開發(fā)實(shí)戰(zhàn)(第25期)|骰子(Dice Roller)— Unicode 符號(hào)與動(dòng)畫渲染精講

一、應(yīng)用概述 骰子(Dice Roller) 是一款經(jīng)典的休閑娛樂應(yīng)用,模擬了真實(shí)擲骰子的過(guò)程。應(yīng)用投擲兩個(gè)骰子(六面標(biāo)準(zhǔn)骰),使用 Unicode 骰面符號(hào)直觀展示每個(gè)骰子的點(diǎn)數(shù),并伴有快速滾動(dòng)的動(dòng)畫效果。…

2026/7/29 0:15:24 閱讀更多