
使用 ASP.NET Web API 構建 RESTful API
圖片來源:https://www.dailydoseofds.com/16-techniques-to-supercharge-and-build-real-world-rag-systems-part-1/
通常,需要將資料通過嵌入模型生成服務轉化為向量,然后存儲到向量數據庫中。
當用戶提問時,將用戶的問題向量化從向量數據庫中進行相似度匹配出 TOP N 個片段,拼接成新的提示詞發送給大模型,大模型就可以結合你的資料更好地回答問題了。
當然, RAG 還有很多變種,如 Agentic RAG 、Modular RAG、Graph RAG 等多種高級形式,這里就不展了。
Function Calling (函數調用) 是一種允許大型語言模型(LLM)根據用戶輸入識別它需要的工具并決定何時調用該工具的機制。
圖片來源:ailydoseofds
基本工作原理如下:LLM 接收用戶的提示詞,LLM 決定它需要的工具,執行方法調用,后端服務執行實際的請求給出處理結果,大語言模型根據處理結果生成最終給用戶的回答。
不同的 API 需要封裝成不同的方法,通常需要編寫代碼,很難在不同的平臺靈活復用。
參見百煉函數調用文檔:https://help.aliyun.com/zh/model-studio/tool-calling-overview/
模型上下文協議(Model Context Protocol,簡稱MCP)是一個由 Anthropic 在 2024 年 11 月 25 日開源的新標準。MCP 是一個開放標準,旨在連接AI助手與數據所在的系統,包括內容存儲庫、業務工具和開發環境。其目標是幫助前沿模型產生更好、更相關的響應。
圖片來源:https://zhuanlan.zhihu.com/p/598749792
MCP 可以看作是 AI 應用程序的 “USB-C端口”。就像 USB-C 為連接設備與各種外設提供了標準化方式,MCP為 AI 模型連接不同數據源和工具提供了標準化方法。
圖片來源:ailydoseofds
從技術角度看,MCP 遵循客戶端-服務器架構,其中主機應用可以連接到多個服務器。
MCP 有三個關鍵組件:
傳統 API :
圖片來源:ailydoseofds
圖片來源:ailydoseofds
MCP 的設計解決了這個問題:
圖片來源:ailydoseofds
圖片來源:ailydoseofds
圖源:https://www.latent.space/p/why-mcp-won
其實,MCP 也是用了 “中間層”的思想,讓大模型使用工具標準化,讓大模型調用工具更方便,煥發出新的生機。
圖片來源:ailydoseofds
首先需要在主機上自動或手動配置 MCP 服務,當用戶輸入問題時, MCP 客戶端讓 大語言模型選擇 MCP 工具,大模型選擇好 MCP 工具以后, MCP 客戶端尋求用戶同意(很多產品支持配置自動同意),MCP 客戶端請求 MCP 服務器, MCP 服務調用工具并將工具的結果返回給 MCP 客戶端, MCP 客戶端將模型調用結果和用戶的查詢發送給大語言模型,大語言模型組織答案給用戶。
其實 RAG 、Function Call 和 MCP 本質上都是一樣,都是為了借助外部工具幫助大模型完成更復雜的事情。
我們來到魔搭的 MCP 市場:https://modelscope.cn/mcp,這里只是為了演示,其他的 MCP 廣場也是一樣的。
登錄以后,我們選擇一個 MCP 服務,點擊右側的“連接”按鈕,就可以 獲取 MCP服務的 SSE URL。
Cherry Studio 官網: https://cherry-ai.com/
在右上角點擊開啟,就可以看到該 MCP 服務提供的工具、提示和資源。
可以單獨開啟和關閉每個可用的工具。
每個 MCP 服務手動配置太麻煩,大家也可以點擊“同步服務器”,配置 ModelScope 的 API 令牌,配置之后就可以一鍵同步 ModelScope 上開啟的 MCP 服務了。
輸入想要問的問題,開啟需要的 MCP 服務。
為了看見 MCP 的執行過程,我們還需要通過 Ctrl+Shift+I(Mac端:Command+Option+I)打開開發者模式。
第一次請求,發送系統提示詞,包括大模型可以選擇的工具和要求等,然后給出用戶的問題。
可以看到第二次調用,模型選擇使用 infoq 工具獲得資訊后組織語言展示給用戶。
index =0 的系統提示詞的內容:
{
"role": "system",
"content": "In this environment you have access to a set of tools you can use to answer the user's question. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.\n\n## Tool Use Formatting\n\nTool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:\n\n<tool_use>\n <name>{tool_name}</name>\n <arguments>{json_arguments}</arguments>\n</tool_use>\n\nThe tool name should be the exact name of the tool you are using, and the arguments should be a JSON object containing the parameters required by that tool. For example:\n<tool_use>\n <name>python_interpreter</name>\n <arguments>{\"code\": \"5 + 3 + 1294.678\"}</arguments>\n</tool_use>\n\nThe user will respond with the result of the tool use, which should be formatted as follows:\n\n<tool_use_result>\n <name>{tool_name}</name>\n <result>{result}</result>\n</tool_use_result>\n\nThe result should be a string, which can represent a file or any other output type. You can use this result as input for the next action.\nFor example, if the result of the tool use is an image file, you can use it in the next action like this:\n\n<tool_use>\n <name>image_transformer</name>\n <arguments>{\"image\": \"image_1.jpg\"}</arguments>\n</tool_use>\n\nAlways adhere to this format for the tool use to ensure proper parsing and execution.\n\n## Tool Use Examples\n\nHere are a few examples using notional tools:\n---\nUser: Generate an image of the oldest person in this document.\n\nAssistant: I can use the document_qa tool to find out who the oldest person is in the document.\n<tool_use>\n <name>document_qa</name>\n <arguments>{\"document\": \"document.pdf\", \"question\": \"Who is the oldest person mentioned?\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>document_qa</name>\n <result>John Doe, a 55 year old lumberjack living in Newfoundland.</result>\n</tool_use_result>\n\nAssistant: I can use the image_generator tool to create a portrait of John Doe.\n<tool_use>\n <name>image_generator</name>\n <arguments>{\"prompt\": \"A portrait of John Doe, a 55-year-old man living in Canada.\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>image_generator</name>\n <result>image.png</result>\n</tool_use_result>\n\nAssistant: the image is generated as image.png\n\n---\nUser: \"What is the result of the following operation: 5 + 3 + 1294.678?\"\n\nAssistant: I can use the python_interpreter tool to calculate the result of the operation.\n<tool_use>\n <name>python_interpreter</name>\n <arguments>{\"code\": \"5 + 3 + 1294.678\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>python_interpreter</name>\n <result>1302.678</result>\n</tool_use_result>\n\nAssistant: The result of the operation is 1302.678.\n\n---\nUser: \"Which city has the highest population , Guangzhou or Shanghai?\"\n\nAssistant: I can use the search tool to find the population of Guangzhou.\n<tool_use>\n <name>search</name>\n <arguments>{\"query\": \"Population Guangzhou\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>search</name>\n <result>Guangzhou has a population of 15 million inhabitants as of 2021.</result>\n</tool_use_result>\n\nAssistant: I can use the search tool to find the population of Shanghai.\n<tool_use>\n <name>search</name>\n <arguments>{\"query\": \"Population Shanghai\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>search</name>\n <result>26 million (2019)</result>\n</tool_use_result>\nAssistant: The population of Shanghai is 26 million, while Guangzhou has a population of 15 million. Therefore, Shanghai has the highest population.\n\n\n## Tool Use Available Tools\nAbove example were using notional tools that might not exist for you. You only have access to these tools:\n<tools>\n\n<tool>\n <name>f_u-LsDUyQWsNFAUjL-_Vi</name>\n <description>獲取 36 氪熱榜,提供創業、商業、科技領域的熱門資訊,包含投融資動態、新興產業分析和商業模式創新信息</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"type\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"hot\",\"description\":\"人氣榜\"},{\"type\":\"string\",\"const\":\"video\",\"description\":\"視頻榜\"},{\"type\":\"string\",\"const\":\"comment\",\"description\":\"熱議榜\"},{\"type\":\"string\",\"const\":\"collect\",\"description\":\"收藏榜\"}],\"default\":\"hot\",\"description\":\"分類\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fyQ3DOUpLJDGPLCjslT6P1</name>\n <description>獲取 9to5Mac 蘋果相關新聞,包含蘋果產品發布、iOS 更新、Mac 硬件、應用推薦及蘋果公司動態的英文資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fBOukVLVbqIh69earzcYca</name>\n <description>獲取 BBC 新聞,提供全球新聞、英國新聞、商業、政治、健康、教育、科技、娛樂等資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"category\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"\",\"description\":\"熱門新聞\"},{\"type\":\"string\",\"const\":\"world\",\"description\":\"國際\"},{\"type\":\"string\",\"const\":\"uk\",\"description\":\"英國\"},{\"type\":\"string\",\"const\":\"business\",\"description\":\"商業\"},{\"type\":\"string\",\"const\":\"politics\",\"description\":\"政治\"},{\"type\":\"string\",\"const\":\"health\",\"description\":\"健康\"},{\"type\":\"string\",\"const\":\"education\",\"description\":\"教育\"},{\"type\":\"string\",\"const\":\"science_and_environment\",\"description\":\"科學與環境\"},{\"type\":\"string\",\"const\":\"technology\",\"description\":\"科技\"},{\"type\":\"string\",\"const\":\"entertainment_and_arts\",\"description\":\"娛樂與藝術\"}],\"default\":\"\"},\"edition\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"\"},{\"type\":\"string\",\"const\":\"uk\",\"description\":\"UK\"},{\"type\":\"string\",\"const\":\"us\",\"description\":\"US & Canada\"},{\"type\":\"string\",\"const\":\"int\",\"description\":\"Rest of the world\"}],\"default\":\"\",\"description\":\"版本,僅對 category
為空有效\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fTU2iCLtmsEWljy_HbEhCa</name>\n <description>獲取嗶哩嗶哩視頻排行榜,包含全站、動畫、音樂、游戲等多個分區的熱門視頻,反映當下年輕人的內容消費趨勢</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"type\":{\"anyOf\":[{\"type\":\"number\",\"const\":0,\"description\":\"全站\"},{\"type\":\"number\",\"const\":1,\"description\":\"動畫\"},{\"type\":\"number\",\"const\":3,\"description\":\"音樂\"},{\"type\":\"number\",\"const\":4,\"description\":\"游戲\"},{\"type\":\"number\",\"const\":5,\"description\":\"娛樂\"},{\"type\":\"number\",\"const\":188,\"description\":\"科技\"},{\"type\":\"number\",\"const\":119,\"description\":\"鬼畜\"},{\"type\":\"number\",\"const\":129,\"description\":\"舞蹈\"},{\"type\":\"number\",\"const\":155,\"description\":\"時尚\"},{\"type\":\"number\",\"const\":160,\"description\":\"生活\"},{\"type\":\"number\",\"const\":168,\"description\":\"國創相關\"},{\"type\":\"number\",\"const\":181,\"description\":\"影視\"}],\"default\":0,\"description\":\"排行榜分區\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>f_OULD1Qnu5wPblKHFTzYw</name>\n <description>獲取豆瓣實時熱門榜單,提供當前熱門的圖書、電影、電視劇、綜藝等作品信息,包含評分和熱度數據</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"type\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"subject\",\"description\":\"圖書、電影、電視劇、綜藝等\"},{\"type\":\"string\",\"const\":\"movie\",\"description\":\"電影\"},{\"type\":\"string\",\"const\":\"tv\",\"description\":\"電視劇\"}],\"default\":\"subject\"},\"start\":{\"type\":\"integer\",\"default\":0},\"count\":{\"type\":\"integer\",\"default\":10}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fL5c-CwZ3bUckaatY_MC8Z</name>\n <description>獲取抖音熱搜榜單,展示當下最熱門的社會話題、娛樂事件、網絡熱點和流行趨勢</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>flPxhdB8Wyw8DDuban0pMa</name>\n <description>獲取機核網游戲相關資訊,包含電子游戲評測、玩家文化、游戲開發和游戲周邊產品的深度內容</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fdj1bDLATGns6ZdclA68UF</name>\n <description>獲取愛范兒科技快訊,包含最新的科技產品、數碼設備、互聯網動態等前沿科技資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"limit\":{\"type\":\"integer\",\"default\":20},\"offset\":{\"type\":\"integer\",\"default\":0}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>f0Uk75Pbfsx0rfdD725CYI</name>\n <description>獲取 InfoQ 技術資訊,包含軟件開發、架構設計、云計算、AI等企業級技術內容和前沿開發者動態</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"region\":{\"type\":\"string\",\"enum\":[\"cn\",\"global\"],\"default\":\"cn\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fu70DSpIpWTVlq11tEKJZd</name>\n <description>獲取掘金文章榜,包含前端開發、后端技術、人工智能、移動開發及技術架構等領域的高質量中文技術文章和教程</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"category_id\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"6809637769959178254\",\"description\":\"后端\"},{\"type\":\"string\",\"const\":\"6809637767543259144\",\"description\":\"前端\"},{\"type\":\"string\",\"const\":\"6809635626879549454\",\"description\":\"Android\"},{\"type\":\"string\",\"const\":\"6809635626661445640\",\"description\":\"iOS\"},{\"type\":\"string\",\"const\":\"6809637773935378440\",\"description\":\"人工智能\"},{\"type\":\"string\",\"const\":\"6809637771511070734\",\"description\":\"開發工具\"},{\"type\":\"string\",\"const\":\"6809637776263217160\",\"description\":\"代碼人生\"},{\"type\":\"string\",\"const\":\"6809637772874219534\",\"description\":\"閱讀\"}],\"default\":\"6809637769959178254\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fZMjSXkog94GRA7VoZpJtw</name>\n <description>獲取網易新聞熱點榜,包含時政要聞、社會事件、財經資訊、科技動態及娛樂體育的全方位中文新聞資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>f5s3U6zXATp3L6wpAwNcn4</name>\n <description>獲取紐約時報新聞,包含國際政治、經濟金融、社會文化、科學技術及藝術評論的高質量英文或中文國際新聞資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"region\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"cn\",\"description\":\"中文\"},{\"type\":\"string\",\"const\":\"global\",\"description\":\"全球\"}],\"default\":\"cn\"},\"section\":{\"type\":\"string\",\"default\":\"HomePage\",\"description\":\"分類,當 region
為 cn
時無效。可選值: Africa, Americas, ArtandDesign, Arts, AsiaPacific, Automobiles, Baseball, Books/Review, Business, Climate, CollegeBasketball, CollegeFootball, Dance, Dealbook, DiningandWine, Economy, Education, EnergyEnvironment, Europe, FashionandStyle, Golf, Health, Hockey, HomePage, Jobs, Lens, MediaandAdvertising, MiddleEast, MostEmailed, MostShared, MostViewed, Movies, Music, NYRegion, Obituaries, PersonalTech, Politics, ProBasketball, ProFootball, RealEstate, Science, SmallBusiness, Soccer, Space, Sports, SundayBookReview, Sunday-Review, Technology, Television, Tennis, Theater, TMagazine, Travel, Upshot, US, Weddings, Well, World, YourMoney\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fSodMRu-GB5-mpBxBvxc2D</name>\n <description>獲取什么值得買熱門,包含商品推薦、優惠信息、購物攻略、產品評測及消費經驗分享的實用中文消費類資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"unit\":{\"anyOf\":[{\"type\":\"number\",\"const\":1,\"description\":\"今日熱門\"},{\"type\":\"number\",\"const\":7,\"description\":\"周熱門\"},{\"type\":\"number\",\"const\":30,\"description\":\"月熱門\"}],\"default\":1}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fnY78eScFYQ-6xtUUQg8fB</name>\n <description>獲取少數派熱榜,包含數碼產品評測、軟件應用推薦、生活方式指南及效率工作技巧的優質中文科技生活類內容</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"tag\":{\"type\":\"string\",\"enum\":[\"熱門文章\",\"應用推薦\",\"生活方式\",\"效率技巧\",\"少數派播客\"],\"default\":\"熱門文章\",\"description\":\"分類\"},\"limit\":{\"type\":\"integer\",\"default\":40}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fFlnyuBJfPLifqYRkW94Lh</name>\n <description>獲取騰訊新聞熱點榜,包含國內外時事、社會熱點、財經資訊、娛樂動態及體育賽事的綜合性中文新聞資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"page_size\":{\"type\":\"integer\",\"default\":20}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>f0YfISsRrFbNGGwO3XVCFY</name>\n <description>獲取澎湃新聞熱榜,包含時政要聞、財經動態、社會事件、文化教育及深度報道的高質量中文新聞資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fIKw7RiYt2oAptPSBtelf-</name>\n <description>獲取 The Verge 新聞,包含科技創新、數碼產品評測、互聯網趨勢及科技公司動態的英文科技資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fH1Xj1bmY_qWxS6b8BoSCK</name>\n <description>獲取今日頭條熱榜,包含時政要聞、社會事件、國際新聞、科技發展及娛樂八卦等多領域的熱門中文資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fIoNHXnzDif1o8sJSRpVBu</name>\n <description>獲取微博熱搜榜,包含時事熱點、社會現象、娛樂新聞、明星動態及網絡熱議話題的實時熱門中文資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fX_nTem-9mBD-9Th_ZVRdA</name>\n <description>獲取微信讀書排行榜,包含熱門小說、暢銷書籍、新書推薦及各類文學作品的閱讀數據和排名信息</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"category\":{\"anyOf\":[{\"type\":\"string\",\"const\":\"rising\",\"description\":\"飆升榜\"},{\"type\":\"string\",\"const\":\"hot_search\",\"description\":\"熱搜榜\"},{\"type\":\"string\",\"const\":\"newbook\",\"description\":\"新書榜\"},{\"type\":\"string\",\"const\":\"general_novel_rising\",\"description\":\"小說榜\"},{\"type\":\"string\",\"const\":\"all\",\"description\":\"總榜\"}],\"default\":\"rising\",\"description\":\"排行榜分區\"}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n\n<tool>\n <name>fzIq8ORLIZHJLRU6pJt3O5</name>\n <description>獲取知乎熱榜,包含時事熱點、社會話題、科技動態、娛樂八卦等多領域的熱門問答和討論的中文資訊</description>\n <arguments>\n {\"type\":\"object\",\"properties\":{\"limit\":{\"type\":\"number\",\"default\":50}},\"additionalProperties\":false,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n </arguments>\n</tool>\n\n</tools>\n\n## Tool Use Rules\nHere are the rules you should always follow to solve your task:\n1. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.\n2. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\n3. If no tool call is needed, just answer the question directly.\n4. Never re-do a tool call that you previously did with the exact same parameters.\n5. For tool use, MARK SURE use XML tag format as shown in the examples above. Do not use any other format.\n\n# User Instructions\n\n\nNow Begin! If you solve the task correctly, you will receive a reward of $1,000,000.\n"
}
主要包括:
index =1 的用戶的內容
{
"role": "user",
"content": "幫我搜索 模型上下文協議 MCP 相關的最新技術文章"
}
index =2 的助手的內容
{
"role": "assistant",
"content": "為了找到關于模型上下文協議(MCP)的最新技術文章,我將使用一些可用的工具來搜索相關資訊。首先,我可以從InfoQ開始,因為它經常發布企業級技術內容和前沿開發者動態。\n\n<tool_use>\n <name>f0Uk75Pbfsx0rfdD725CYI</name>\n <arguments>{\"region\":\"global\"}</arguments>\n</tool_use>"
}
index =3 的 用戶的內容
{
"role": "user",
"content": [
{
"type": "text",
"text": "Here is the result of tool call f0Uk75Pbfsx0rfdD725CYI:"
},
{
"type": "text",
"text": "[{\"type\":\"text\",\"text\":\"<title>Docker Desktop 4.40 Introduces Model Runner to Run LLMs Locally Expanding its AI Capabilities</title>\\n<description> 省略其他}]"
}
]
}
第三次調用主要是為了給話題起標題。
大家,可以多開啟幾個工具或者多問幾次,結合理論部分的講解,會對 MCP 的過程會有更深刻的體會。
MCP 市場有很多,國內常見的有 ModelScope 和 阿里云百煉。
ModelScope:https://modelscope.cn/mcp
百煉 MCP 市場:https://bailian.console.aliyun.com/?tab=mcp#/mcp-market
大家還可以使用 Qwen (https://chat.qwen.ai)深入研究功能來系統學習 MCP。
我們感興趣可以 Clone Cherry Studio 的源碼,使用通義靈碼、 Cursor 等 AI 編程工具,打開倉庫:https://github.com/CherryHQ/cherry-studio 直接對你關心的問題進行提問,學習效果更好。
大家還可以通過我們之前分享的“通俗講解專家智能體”,先用生活化的例子快速 GET 到意思,然后專業講解,再給出易記的方法,最后通過 SVG 圖解的方式幫助我們更直觀理解知識。
問題1:MCP 服務的配置、開關通常需要手動操作,使用方式還不夠智能。這有點和 ChatGPT 的插件功能很相似,用戶需要手動選擇想要開啟的插件,AI 還不能自動選擇。在大模型上下文和能力沒有完全解決之前, MCP 下一步應該需要支持場景化(劇本式)開啟和關閉,而不是全局的手動開啟和關閉,開啟太多 Tokens消耗大,開啟太少可能影響功能的使用,某個場景在特定環節能夠用到的 MCP 是相對確定的,需要類似工作流編排的形式來解決。
問題2:如果開啟大量的 MCP 服務,客戶端如果第一次將所有工具信息都發給大模型讓大模型來抉擇,會浪費大量 Tokens。未來這部分可能需要用本地模型來實現。
問題3:MCP 只是解決了協議的問題,工具的穩定性很重要,調用工具時服務不可用非常影響用戶體驗。應該有個工具可用性檢測機制,不可用時及時下線。
問題4:現在 MCP 服務的封裝主流還是前端框架和 Python,Java 來封裝 MCP 似乎不太方便或者說上手門檻略高,未來可能需要再增加一個中間層來吃掉這個復雜度。
問題5:現在很多模型使用 MCP 的能力還不太強,有些場景哪怕適合調用某個 MCP 服務,有些模型也只會在需要明確告知使用 MCP 才會選擇使用 MCP。
很多人認為 MCP 只是一個過渡,因為目前 MCP 設計存在一些局限性,而且,盡管 MCP 獲得了 OpenAI、Google 等大廠的支持,但其成為永久行業標準仍存在不確定性。
我認為,MCP 確實存在一些缺點,但,MCP 確實為大模型更好地調用工具提供了一個非常好的協議。大模型想要做更復雜發揮出更大價值必然要學會使用工具,模型上下文協議非常有必要,只是未必一定是 Anthropic 這個版本。
MCP 可能是一個過渡,但這不是問題。其實 RAG 也存在諸多問題,可能也是一個過渡。其實,從更大尺度來看,我們以前用的電話、功能機、現在用的這些傳統軟件都是一種過渡。人,總是有時代局限性,比如我們手動擋的汽車和現在的自動駕駛沒法比,也是一種過渡,但不妨礙它能夠真正幫助到我們。
當前,大模型現在還很難通過 MCP 實現人類一樣的操作。比如 PPT 制作、視頻剪輯,大模型還不能通過 MCP 實現類似真正和人類一樣的智能的 “RPA”操作。
隨著越來越多的服務支持 MCP,隨著模型的服務不斷增強,面向 MCP 的業務流程編排會或許成為主流。隨著 AI 使用工具的能力不斷增強,未來,能夠帶來的幫助也會更大。
圖源:https://www.dailydoseofds.com/p/a-visual-guide-to-agent2agent-a2a-protocol/
MCP 試圖在解決模型使用工具的問題(就像人可以使用扳手、可以開車、可以使用的電腦等)。但是,想要完成非常復雜的事情,智能體之間必然需要協同(就像上下級之間的管理和執行,同事之間分工合作),智能體之間的標準協議非常重要。谷歌最近發布的 A2A 協議則試圖解決智能體之間通信的協議問題。正如上圖所示,兩者可以結合使用,MCP 用戶服務的注冊和發現, A2A 用戶智能體之間的通信。
AI 技術的發展比想象地要更快,正如 ChatGPT 剛出來時,很多人說它永遠不會取代我們,它的知識不會更新,現在 AI 搜索、RAG 已經成為常態。
現在,模型雖然存在速度慢的問題,存在上下文長度限制問題,存在幻覺的問題,存在好用模型價格高的問題等,這些都將逐漸得到解決。 AI 將會更好地使用工具,Agent 也將更加智能, Agent 之間的協同也將更加通暢。
文章轉載自: 一文帶你 “看見” MCP 的過程,徹底理解 MCP 的概念