尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

AI智能体插件开发实战:从设计到集成的完整指南

AI智能体插件开发实战:从设计到集成的完整指南 如果你最近在关注AI智能体Agent开发特别是想让你的AI助手具备调用外部工具、处理复杂任务的能力那么“插件Plugin”这个概念你一定不陌生。从ChatGPT的Plugin商店到各类AI框架插件化设计正成为构建强大AI应用的关键。但你是否遇到过这样的困扰网上教程要么过于零散只讲某个框架的单一用法要么过于理论看完还是不知道如何从零开始把一个具体的业务逻辑比如查询天气、发送邮件、调用数据库封装成一个可被AI智能体稳定、安全调用的插件本文要解决的正是这个从“知道概念”到“能跑通流程”的最后一公里问题。我们不空谈“插件生态”的未来而是聚焦于一个更实际的目标手把手教你如何设计、开发、测试并集成一个符合主流AI Agent框架规范的插件Plugin。无论你是想为AutoGPT、LangChain、ChatGPT Plugin或是国内的大模型平台开发插件其核心思想和工程实践都是相通的。你会发现开发一个“好用”的插件远不止写几行API调用代码那么简单。它涉及到清晰的接口契约、严谨的输入验证、安全的权限控制、友好的错误处理以及规范的元数据描述。本文将用一个完整的“天气查询插件”作为贯穿始终的案例带你走通全流程。你将学到插件Plugin与工具Tool的核心区别与设计哲学为什么插件更强调“可插拔”与“自描述”一个工业级插件的完整代码结构从manifest.json到主逻辑再到错误处理。两种主流集成模式的实战如何让你的插件被LangChain Agent和OpenAI ChatGPT Plugin格式的框架所调用。开发中的核心陷阱与最佳实践包括安全风险规避、异步处理、配置化管理等。读完本文你将获得一套可复用的插件开发模板和清晰的实现路径能够独立将任何业务能力封装为AI智能体的可靠“手脚”。1. 插件Plugin到底是什么从“工具”到“生态”的跨越在深入代码之前我们必须先统一认知。很多人容易混淆“工具Tool”和“插件Plugin”在AI智能体的语境下它们有联系但更有本质区别。工具Tool通常是一个具体的函数或方法它接受输入执行特定操作并返回输出。例如一个get_weather(city: str)函数就是一个工具。在LangChain等框架中工具是Agent可直接调用的最小单元。插件Plugin则是一个封装了一个或多个相关工具并附带完整元数据描述和标准化接口的软件包。你可以把它想象成一个“瑞士军刀模块”它不仅提供了刀、剪子、螺丝刀工具还附带了一份详细的说明书API文档、认证方式、使用条款和一个标准的卡扣接口统一的API规范确保它能被正确、安全地安装到不同的“刀柄”AI平台或框架上。它们的关键差异如下表所示特性工具 (Tool)插件 (Plugin)粒度细粒度单一功能粗粒度包含一组相关功能描述通常只有函数名和简单注释必须提供结构化的清单文件如ai-plugin.json包含详细描述、认证、输入输出schema可发现性依赖代码导入难以动态发现通过清单文件可被平台自动扫描和发现标准化框架自定义格式不一遵循特定平台标准如OpenAI Plugin标准跨平台兼容性更好目标让Agent能执行某个动作构建可插拔、可扩展的生态系统那么为什么我们要费心开发插件而不只是定义工具核心价值在于“解耦”与“生态”。对于开发者插件模式允许你将核心业务逻辑如天气服务、数据库操作打包成一个独立的、标准化的组件。这个组件可以在不同的AI项目、甚至不同的AI框架中复用无需重复编写集成代码。对于AI平台/框架提供统一的插件规范可以吸引大量第三方开发者丰富其能力从而快速构建起自己的应用生态。ChatGPT Plugin商店就是最典型的例子。对于最终用户可以通过自然语言让AI智能体安全、可靠地调用五花八门的第三方服务体验“一句话搞定一切”的便捷。接下来我们将以开发一个“智能天气查询插件”为目标贯穿设计、开发、测试、集成的全流程。2. 环境准备与项目初始化我们将使用Python作为开发语言这是目前AI领域最主流的语言。确保你的环境满足以下要求Python版本: 3.8 或更高版本推荐3.9。包管理工具: 使用pip或poetry。本文使用pip和venv虚拟环境。主要依赖库:fastapi: 用于构建插件的API服务器遵循OpenAI Plugin标准需要。uvicorn: ASGI服务器用于运行FastAPI应用。pydantic: 用于数据验证和设置管理确保接口健壮性。requests: 用于调用外部天气API。langchain: 用于演示如何将插件集成到LangChain Agent中。openai: 可选如果你需要对接OpenAI模型。2.1 创建项目目录结构一个清晰的项目结构是良好工程的开始。我们的插件项目weather_plugin将如下组织weather_plugin/ ├── .env # 环境变量配置文件如API密钥 ├── .gitignore ├── pyproject.toml # 项目依赖和配置或使用requirements.txt ├── README.md ├── src/ # 源代码目录 │ └── weather_plugin/ │ ├── __init__.py │ ├── core/ # 核心业务逻辑 │ │ ├── __init__.py │ │ ├── weather_client.py # 天气API客户端 │ │ └── models.py # 数据模型Pydantic │ ├── api/ # API层 │ │ ├── __init__.py │ │ ├── routes.py # FastAPI路由 │ │ └── dependencies.py # 依赖注入如认证 │ ├── plugin/ # 插件描述文件 │ │ └── manifest.py # 动态生成ai-plugin.json │ └── config.py # 配置加载 └── tests/ # 单元测试 ├── __init__.py ├── test_core.py └── test_api.py2.2 初始化虚拟环境与安装依赖在项目根目录下执行以下命令# 创建并激活虚拟环境Linux/macOS python -m venv venv source venv/bin/activate # 创建并激活虚拟环境Windows python -m venv venv venv\Scripts\activate # 升级pip pip install --upgrade pip # 安装核心依赖 pip install fastapi uvicorn pydantic requests # 安装开发与集成测试依赖 pip install langchain openai pytest httpx python-dotenv2.3 编写项目配置文件创建pyproject.toml来管理项目元数据和依赖。# pyproject.toml [project] name weather-plugin version 0.1.0 description A plugin for AI agents to fetch weather information. authors [{name Your Name, email your.emailexample.com}] readme README.md requires-python 3.8 dependencies [ fastapi0.104.0, uvicorn[standard]0.24.0, pydantic2.0.0, requests2.31.0, python-dotenv1.0.0, ] [project.optional-dependencies] dev [pytest7.4.0, httpx0.25.0, black, isort] langchain [langchain0.0.340, openai1.0.0] [build-system] requires [setuptools61.0, wheel] build-backend setuptools.build_meta同时创建.env文件来存储敏感信息切勿提交至版本库# .env WEATHER_API_KEYyour_actual_weather_api_key_here WEATHER_API_BASE_URLhttps://api.weatherapi.com/v1 PLUGIN_HOSThttp://localhost:80003. 核心业务逻辑与数据模型开发插件的核心是提供价值对我们来说就是获取天气信息。我们使用一个假设的天气API。3.1 定义数据模型Pydantic使用Pydantic定义清晰、可验证的输入输出模型这是保证API健壮性的第一步。# src/weather_plugin/core/models.py from pydantic import BaseModel, Field from typing import Optional from enum import Enum class TemperatureUnit(str, Enum): 温度单位枚举 CELSIUS celsius FAHRENHEIT fahrenheit class WeatherRequest(BaseModel): 查询天气的请求模型 city: str Field(..., description城市名称例如Beijing, Shanghai, min_length1, max_length100) country_code: Optional[str] Field(CN, description国家代码ISO 3166-1 alpha-2默认CN) unit: TemperatureUnit Field(TemperatureUnit.CELSIUS, description温度单位) class Config: schema_extra { example: { city: Beijing, country_code: CN, unit: celsius } } class WeatherInfo(BaseModel): 天气信息响应模型 city: str country: str local_time: str temperature: float unit: str condition: str Field(..., description天气状况如Sunny, Rainy) humidity: int Field(..., ge0, le100, description湿度百分比) wind_speed: float Field(..., ge0, description风速公里/小时) last_updated: str class Config: schema_extra { example: { city: Beijing, country: China, local_time: 2023-10-27 14:30, temperature: 22.5, unit: celsius, condition: Sunny, humidity: 45, wind_speed: 12.3, last_updated: 2023-10-27 14:00:00 } }3.2 实现天气客户端这里我们实现一个客户端它封装了对第三方天气API的调用。注意加入错误处理和日志。# src/weather_plugin/core/weather_client.py import logging from typing import Optional import requests from pydantic import ValidationError from .models import WeatherRequest, WeatherInfo, TemperatureUnit logger logging.getLogger(__name__) class WeatherClient: 天气API客户端 def __init__(self, api_key: str, base_url: str): self.api_key api_key self.base_url base_url.rstrip(/) self.session requests.Session() # 可以在这里配置重试、超时等策略 # self.session.mount(https://, requests.adapters.HTTPAdapter(max_retries3)) def get_current_weather(self, request: WeatherRequest) - Optional[WeatherInfo]: 获取当前天气信息。 在实际项目中这里会调用真实的天气API。 此处为模拟实现。 try: # 模拟API调用和响应解析 # 真实调用可能类似 # params {key: self.api_key, q: f{request.city},{request.country_code}} # response self.session.get(f{self.base_url}/current.json, paramsparams, timeout10) # response.raise_for_status() # data response.json() # 模拟数据 mock_data { city: request.city, country: China if request.country_code CN else Unknown, local_time: 2023-10-27 14:30, temperature: 25.3 if request.unit TemperatureUnit.CELSIUS else 77.5, unit: request.unit, condition: Partly Cloudy, humidity: 60, wind_speed: 15.2, last_updated: 2023-10-27 14:00:00 } # 使用Pydantic模型验证并返回 return WeatherInfo(**mock_data) except ValidationError as e: logger.error(f天气数据验证失败: {e}) return None except requests.exceptions.RequestException as e: logger.error(f调用天气API失败: {e}) # 在这里可以定义更精细的错误类型如APINetworkError return None except Exception as e: logger.exception(f获取天气信息时发生未知错误: {e}) return None def __del__(self): 清理会话资源 if hasattr(self, session): self.session.close()4. 构建插件API服务器为了让插件能被AI平台发现和调用我们需要提供一个标准的HTTP API。OpenAI Plugin规范要求插件提供三个端点/.well-known/ai-plugin.json: 插件清单文件描述插件元数据。/openapi.json或/openapi.yaml: OpenAPI规范文档描述API细节。插件实际的功能端点如我们的/weather/current。4.1 加载配置首先创建一个配置管理模块。# src/weather_plugin/config.py import os from pydantic_settings import BaseSettings from typing import Optional class Settings(BaseSettings): 应用配置 weather_api_key: str weather_api_base_url: str https://api.weatherapi.com/v1 plugin_host: str http://localhost:8000 # 插件运行的主机地址 plugin_name: str WeatherPlugin plugin_description: str Get current weather information for cities around the world. plugin_version: str 0.1.0 class Config: env_file .env case_sensitive False # 创建全局配置实例 settings Settings()4.2 生成插件清单文件这是插件能被发现的关键。清单文件必须位于/.well-known/ai-plugin.json。# src/weather_plugin/plugin/manifest.py import json from typing import Dict, Any from ..config import settings def generate_manifest() - Dict[str, Any]: 动态生成 ai-plugin.json 内容 return { schema_version: v1, name_for_human: settings.plugin_name, name_for_model: settings.plugin_name, description_for_human: settings.plugin_description, description_for_model: A plugin to get current weather conditions for a given city. Use it when user asks about weather, temperature, or climate., auth: { type: none # 根据需求可改为 oauth, service_http, user_http }, api: { type: openapi, url: f{settings.plugin_host}/openapi.json, is_user_authenticated: False }, logo_url: f{settings.plugin_host}/logo.png, # 可选需要提供logo contact_email: supportexample.com, # 可选 legal_info_url: f{settings.plugin_host}/legal # 可选 } # 可以将此字典保存为JSON文件或直接在API中返回4.3 实现FastAPI应用与路由现在创建主要的FastAPI应用并设置路由。# src/weather_plugin/api/routes.py from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import JSONResponse import logging from ..core.weather_client import WeatherClient from ..core.models import WeatherRequest, WeatherInfo from ..config import settings from .dependencies import get_weather_client router APIRouter() logger logging.getLogger(__name__) router.get(/.well-known/ai-plugin.json) async def get_ai_plugin_json(): 提供OpenAI Plugin标准的清单文件 from ..plugin.manifest import generate_manifest return JSONResponse(contentgenerate_manifest()) router.post(/weather/current, response_modelWeatherInfo) async def get_current_weather( request: WeatherRequest, weather_client: WeatherClient Depends(get_weather_client) ): 获取指定城市的当前天气。 这是插件的主要功能端点。 logger.info(f收到天气查询请求: city{request.city}, country{request.country_code}) weather_info weather_client.get_current_weather(request) if weather_info is None: # 这里可以定义更具体的错误信息 raise HTTPException( status_code503, detailUnable to fetch weather information at the moment. Please try again later. ) return weather_info router.get(/health) async def health_check(): 健康检查端点 return {status: healthy}# src/weather_plugin/api/dependencies.py from fastapi import Depends from ..core.weather_client import WeatherClient from ..config import settings # 依赖注入创建并管理WeatherClient实例 def get_weather_client() - WeatherClient: 获取天气客户端依赖项 # 在实际应用中这里可能涉及更复杂的生命周期管理如使用lru_cache client WeatherClient( api_keysettings.weather_api_key, base_urlsettings.weather_api_base_url ) return client4.4 创建主应用入口# src/weather_plugin/__init__.py from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware import logging from .api.routes import router from .config import settings logging.basicConfig(levellogging.INFO) logger logging.getLogger(__name__) def create_application() - FastAPI: 创建并配置FastAPI应用实例 app FastAPI( titlesettings.plugin_name, descriptionsettings.plugin_description, versionsettings.plugin_version, openapi_url/openapi.json, # 提供OpenAPI文档 docs_url/docs, # 自动生成的API文档 redoc_url/redoc, ) # 配置CORS重要如果从浏览器或不同端口的客户端调用 app.add_middleware( CORSMiddleware, allow_origins[*], # 生产环境应限制为具体域名 allow_credentialsTrue, allow_methods[*], allow_headers[*], ) # 包含路由 app.include_router(router, prefix) # 前缀为空路由定义在router中 app.on_event(startup) async def startup_event(): logger.info(f{settings.plugin_name} v{settings.plugin_version} 正在启动...) logger.info(f插件清单地址: {settings.plugin_host}/.well-known/ai-plugin.json) logger.info(fAPI文档地址: {settings.plugin_host}/docs) app.on_event(shutdown) async def shutdown_event(): logger.info(f{settings.plugin_name} 正在关闭...) return app # 创建应用实例 app create_application()5. 运行与测试插件API5.1 启动插件服务器在项目根目录创建一个main.py作为启动入口。# main.py import uvicorn from src.weather_plugin import app if __name__ __main__: uvicorn.run( main:app, host0.0.0.0, # 允许外部访问方便测试 port8000, reloadTrue, # 开发模式代码修改自动重启 log_levelinfo )现在在终端运行python main.py你应该看到类似以下的输出INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRLC to quit) INFO: Started reloader process [12345] using StatReload INFO: Started server process [12346] INFO: Waiting for application startup. INFO: WeatherPlugin v0.1.0 正在启动... INFO: 插件清单地址: http://localhost:8000/.well-known/ai-plugin.json INFO: API文档地址: http://localhost:8000/docs INFO: Application startup complete.5.2 验证核心端点打开浏览器或使用curl/httpie进行测试访问插件清单http://localhost:8000/.well-known/ai-plugin.json。你应该能看到一个完整的JSON描述。访问OpenAPI文档http://localhost:8000/docs。这是一个交互式的Swagger UI你可以在这里直接测试API。测试天气查询接口# 使用curl测试 curl -X POST http://localhost:8000/weather/current \ -H Content-Type: application/json \ -d {city: Shanghai, country_code: CN, unit: celsius}预期返回{ city: Shanghai, country: China, local_time: 2023-10-27 14:30, temperature: 25.3, unit: celsius, condition: Partly Cloudy, humidity: 60, wind_speed: 15.2, last_updated: 2023-10-27 14:00:00 }健康检查http://localhost:8000/health应返回{status: healthy}。至此一个符合OpenAI Plugin规范的独立插件服务已经搭建完成。但这只是第一步接下来我们要看如何让AI智能体Agent真正“使用”这个插件。6. 集成到AI智能体两种主流模式插件开发好后需要被AI智能体框架集成才能发挥作用。这里介绍两种最典型的集成方式。6.1 模式一集成到LangChain AgentLangChain通过Tool抽象来扩展Agent的能力。我们需要将我们的插件API包装成一个LangChain Tool。首先确保安装了LangChain和OpenAI或其他LLM的包。# 文件integrate_with_langchain.py import os from langchain.agents import initialize_agent, AgentType from langchain.tools import Tool from langchain.llms import OpenAI # 或使用ChatOpenAI from langchain.chat_models import ChatOpenAI from langchain.schema import SystemMessage import requests from pydantic import BaseModel, Field from typing import Type, Optional # 1. 定义一个与插件API交互的简单函数 def get_weather_from_plugin(city: str, country_code: Optional[str] CN) - str: 调用我们刚开发的天气插件API try: response requests.post( http://localhost:8000/weather/current, json{city: city, country_code: country_code, unit: celsius}, timeout10 ) response.raise_for_status() data response.json() # 将结果格式化为自然语言 return (fThe current weather in {data[city]}, {data[country]} is {data[condition]}. fTemperature is {data[temperature]}°{data[unit]}. fHumidity is {data[humidity]}% and wind speed is {data[wind_speed]} km/h.) except requests.exceptions.RequestException as e: return fFailed to get weather: {e} # 2. 将函数包装成LangChain Tool weather_tool Tool( nameGetCurrentWeather, funcget_weather_from_plugin, descriptionUseful for when you need to answer questions about the current weather in a city. Input should be a city name. Optionally, you can provide a country code (like CN for China). ) # 3. 初始化LLM和Agent # 设置你的OpenAI API Key os.environ[OPENAI_API_KEY] your-openai-api-key llm ChatOpenAI(temperature0, modelgpt-3.5-turbo) # 使用Chat模型 # 或者使用 text-davinci-003 # llm OpenAI(temperature0) # 定义系统消息引导Agent使用工具 system_message SystemMessage(contentYou are a helpful assistant that can use tools to get weather information.) # 初始化Agent agent initialize_agent( tools[weather_tool], llmllm, agentAgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, # 适合聊天且使用工具的Agent类型 verboseTrue, # 打印思考过程便于调试 agent_kwargs{ system_message: system_message } ) # 4. 运行测试 if __name__ __main__: query Whats the weather like in Shanghai today? result agent.run(query) print(f\n用户问题: {query}) print(fAgent回答: {result})运行这个脚本你会看到LangChain Agent的思考链ReAct模式它决定调用GetCurrentWeather工具并成功获取了天气信息。6.2 模式二遵循OpenAI Plugin标准用于ChatGPT等如果你的插件严格遵循了OpenAI Plugin规范提供了/.well-known/ai-plugin.json和/openapi.json那么它理论上可以被任何支持该标准的平台发现和调用例如ChatGPT的插件系统。在ChatGPT中手动安装测试模拟流程在ChatGPT Web界面或App中进入插件商店。选择“Develop your own plugin”。输入你的插件运行地址http://localhost:8000注意ChatGPT要求插件服务必须通过HTTPS在公网可访问本地开发需使用隧道工具如ngrok或localhost.run暴露服务。ChatGPT会访问/.well-known/ai-plugin.json来获取插件信息。安装成功后你就可以在对话中让ChatGPT使用你的天气插件了。使用本地开发服务器与隧道# 安装ngrok需要注册账号获取token # 启动隧道将本地8000端口暴露到公网 ngrok http 8000ngrok会生成一个https://xxxxxx.ngrok.io的地址。将这个地址填入ChatGPT插件开发配置中。7. 常见问题与排查思路在开发和集成插件的过程中你可能会遇到以下问题问题现象可能原因排查方式解决方案访问/.well-known/ai-plugin.json404路由未正确注册或前缀冲突。1. 检查FastAPI应用的router是否被正确包含。2. 检查路由路径拼写是否正确注意.well-known是目录。确保router中包含该路由且应用运行在正确的主机和端口。OpenAI/ChatGPT 无法发现插件1. 服务未公网可访问。2. 清单文件格式不符合规范。3. CORS未配置。1. 使用curl或浏览器直接访问公网URL的清单文件。2. 使用JSON校验工具检查ai-plugin.json。3. 检查浏览器控制台CORS错误。1. 使用ngrok等隧道工具。2. 严格对照OpenAI Plugin规范修改清单。3. 在FastAPI中正确配置CORS中间件。LangChain Agent 不调用工具1. Tool的描述(description)不清晰。2. Agent类型选择不当。3. LLM温度(temperature)太高导致输出随机。1. 查看Agent的verbose日志看它是否在“思考”使用工具。2. 尝试更明确的用户问题。1. 优化Tool的description明确使用场景和输入格式。2. 尝试AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION或AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION。3. 将LLM的temperature设为0。插件API调用返回错误1. 输入数据不符合Pydantic模型。2. 外部API密钥无效或超限。3. 网络问题。1. 查看FastAPI的日志输出。2. 直接使用curl或Postman测试API端点。3. 检查.env文件中的API_KEY。1. 在代码中添加更详细的错误日志和验证。2. 实现重试机制和友好的错误信息返回。3. 使用try...except捕获异常返回标准化的错误响应。性能瓶颈1. 同步阻塞调用外部API。2. 未使用连接池。3. 每次请求都新建客户端。1. 使用异步HTTP客户端如httpx。2. 监控API响应时间。1. 将weather_client中的requests替换为httpx.AsyncClient并将路由标记为async。2. 使用依赖注入缓存客户端实例。8. 最佳实践与工程建议将插件投入生产环境或团队协作时以下实践能帮你避免很多坑安全性是第一要务输入验证坚决使用Pydantic等库进行严格的输入验证和清理防止注入攻击。输出净化对返回给AI模型的数据进行审查避免意外泄露敏感信息。认证与授权如果插件涉及用户数据或敏感操作务必实现认证如OAuth、API Key。在ai-plugin.json的auth字段中正确声明。速率限制在API层面实现速率限制如使用slowapi防止滥用。环境变量所有密钥、配置必须通过环境变量或安全的配置中心管理绝不要硬编码。提升可靠性与可观测性异步与非阻塞对于可能耗时的操作如网络请求、数据库查询使用异步模式async/await避免阻塞整个应用。重试与超时调用外部服务时必须设置合理的超时和重试策略。结构化日志使用structlog或json-logging记录关键操作、请求ID、错误详情便于排查问题。健康检查与监控提供/health端点并集成到你的监控系统如Prometheus, Grafana。设计清晰的接口与文档完整的OpenAPI文档FastAPI会自动生成确保每个端点的描述、参数、响应模型都清晰。准确的description_for_model这是AI模型理解插件用途的关键。用自然语言清晰描述插件的功能、适用场景和输入要求。例如“Use this plugin when the user asks about current weather, temperature, humidity, or wind conditions for a specific city.”版本化API考虑在API路径中加入版本号如/v1/weather/current为未来升级留有余地。代码组织与可维护性依赖注入如本文所示使用FastAPI的Depends管理依赖数据库连接、客户端等使代码更可测试。配置集中管理使用pydantic-settings等库统一管理配置。单元测试与集成测试为核心逻辑如weather_client和API端点编写测试。错误处理标准化定义统一的错误响应格式让调用方无论是人还是AI都能理解错误原因。开发一个成熟的AI插件本质上是开发一个微服务。你需要用构建生产级服务的标准来要求它安全、稳定、可观测、易维护。本文提供的模板和流程为你打下了这样一个基础。从理解插件与工具的区别开始我们一步步构建了一个具备完整描述、清晰接口、健壮逻辑的天气查询插件并演示了如何将其集成到LangChain和符合OpenAI标准的平台中。这套方法论可以平移到任何你想赋予AI的能力上查数据库、发邮件、操作日历、控制智能家居……真正的挑战往往在细节之中如何设计让AI更好理解的描述如何处理插件调用失败时的用户体验如何管理插件的生命周期和版本这些问题的答案需要你在具体的业务场景中不断探索和优化。建议你以本文的代码为起点尝试将一个自己项目中的功能插件化那将是理解这一切最好的方式。
返回列表