资讯动态

零基础小白使用LangSmith部署智能体

发布时间:2026/8/14 14:05:53 来源:尧图企业网站定制
1.什么是LangChainLangSmithLangChain的Agent底层是基于LangGraph实现的而LangGraph提供了完整的后端部署功能自带非常完善的API接口无需我们额外处理。同时LangChain还提供了基于LangSmith的GUI控制台实现Agent的调试、监控、一键部署。2.注册LangSmithLangSmith提供了对Agent的GUI管理界面而且还支持一键云部署功能。通常在测试阶段建议大家在Agent中引入Simth方便做测试和调试。官方网址LangSmith注意记得选择langsmithfleet是快速版通过拖拽形式来实现智能体类似于coze注册LangSmith开通服务生成API_KEY。界面如下3.准备好智能体3.1智能体功能实现图片识别- 上传食材图片自动识别其中的食材智能搜索- 根据识别的食材搜索相关食谱️智能排序- 按推荐度、难度、营养价值对食谱进行排序创意建议- 当找不到合适食谱时提供创意搭配建议对话交互- 聊天式界面支持图片上传 文本对话3.2构建项目在langChain文件夹下面执行uv init这里出了点小问题pythond的版本最好在3.11以上后面有大问题......我之前用的是py310得到的项目架构如下大模型的.env文件配置信息如下一个是阿里百炼的url和apikey一个是tavily的工具使用,一个是启用langsmith的key配置环境uv add langgraph-cli[inmem] uv add langchain-openai编写代码智能体简单设置为如下内容后续根据需求拓展业务 Author: Nangong Date: 2026-08-12 16:13:48 LastEditTime: 2026-08-12 16:15:45 from langchain.chat_models import init_chat_model from langchain_tavily import TavilySearch from langchain.agents import create_agent import os # 1. Load environment variables from dotenv import load_dotenv load_dotenv() # 2. Web search tool, using Tavily as the web search tool web_search TavilySearch(max_results5, topicgeneral) # 3. Initialize the chat model model init_chat_model( modelqwen3.5-omni-plus-2026-03-15, model_provideropenai, base_urlos.getenv(DASHSCOPE_BASE_URL), api_keyos.getenv(DASHSCOPE_API_KEY), ) # 4. Agent system prompt system_prompt You are a personal chef. After receiving a photo or a list of ingredients from the user, please follow the workflow below: 1. Identify and evaluate ingredients: If the user provides a photo, first identify all visible ingredients. Based on their appearance, evaluate their freshness and available quantity, and compile a Current Available Ingredients List. 2. Smart recipe search: Prioritize calling the web_search tool, using the Current Available Ingredients List as the core keyword to find viable recipes. 3. Multi-dimensional evaluation and ranking: Quantitatively score the retrieved candidate recipes from two dimensions: nutritional value and preparation difficulty. Rank them based on the scores, with simple and nutritious recipes ranked higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report, including recipe details, scores, reasons for recommendation, and reference images to help users make quick decisions. Please strictly follow the workflow. Prioritize calling the web_search tool to search for recipes. Only improvise if no relevant results are found. # 5. Create the Agent agent create_agent( modelmodel, # Model tools[web_search], # Tools system_promptsystem_prompt, )在项目根目录添加一个langgraph配置文件langgraph.json的内容如下{ dependencies: [.], graphs: { chief_agent: D:/lgl/study/langChain/app/src/app/myApp/personal_chief.py:agent }, env: .env }注意其中的agent配置格式为[Agent文件路径]:[Agent变量名]例如在我们的配置中./app/agents/personal_chief.py就是文件路径agent就是文件中定义的Agent名字3.3部署项目执行uv run langgraph dev部署项目在langSmith上$env:PYTHONUTF81 uv run langgraph dev很明显的部署成功了并且没有报错4.LangSmith Studio测试由于我们部署时配置了LangSmith所以可以直接访问LangSmith提供的调试GUI界面LangSmith这里可以非常方便的调试我们的Agent查看我们Agent的运行细节切换chat模式同时LangSmith还提供了一键云部署功能可以把Agent部署到云端但是要需要缴付昂贵的费用。所以建议只在Agent测试阶段使用LangSmith

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价