
目錄1日常助手提示詞里面基本要有什么2還有文案優(yōu)化助手3數(shù)據(jù)查詢助手4def和class的區(qū)別5使用Autogen時(shí)遇到的問(wèn)題?6異步程序的入口是什么7這注解staticmethod有什么用?8解釋下面代碼 9解釋這段代碼10async with MsgHub 這個(gè) with 是什么意思11**kwargs有什么用12Literal[user, assistant, system, tool]?13Agent基本框架14為什么調(diào)用工具返回結(jié)果后還要調(diào)用agent?15記憶系統(tǒng)的架構(gòu)設(shè)計(jì)?16RAG系統(tǒng)17有哪四種記憶類型?如何區(qū)分?18為什么要構(gòu)建上下文有什么用19剛才是 apppend怎么這里是 extend?20NoteTool的最佳實(shí)踐原則?21筆記類型有哪些22智能體通信協(xié)議學(xué)習(xí)框架?23MCP三層架構(gòu)對(duì)應(yīng)什么?24不是 A2AServer 嗎怎么來(lái)了個(gè) A2ATool?25智能體性能評(píng)估有哪三種方式?26旅游助手框架及實(shí)現(xiàn)27Agent回答超時(shí)怎么解決?(如何解決通義千問(wèn) qwen3.8-27b 大模型請(qǐng)求超時(shí)的問(wèn)題?)28實(shí)現(xiàn)了 pydantic, 也就是繼承 BasModel 后會(huì)自動(dòng)校驗(yàn)數(shù)據(jù)類型格式的正確與否嗎29思考模式怎么關(guān)閉?30reloadTrue作用?31為什么不直接調(diào)用API?而是使用多agent?32如果一個(gè)MCPTool需要多個(gè)agent使用該怎么辦?33重寫的流式 think 撞上空 choices 塊什么意思?34返回類型 - Configuration 為什么加引號(hào)?35yield fdata: {json.dumps (event,ensure_asciiFalse)}\n\n yield 是干嘛的36總結(jié)1日常助手提示詞里面基本要有什么1角色role2角色配置profile3技能skills4規(guī)則rules5工作流程workflow6初始化段Initialization2還有文案優(yōu)化助手3數(shù)據(jù)查詢助手124def和class的區(qū)別為什么調(diào)用def需要加(),調(diào)用類就不需要5使用Autogen時(shí)遇到的問(wèn)題?def create_openai_model_client(): 創(chuàng)建 OpenAI 模型客戶端用于測(cè)試 return OpenAIChatCompletionClient( modelos.getenv(LLM_MODEL_ID, gpt-4o), api_keyos.getenv(LLM_API_KEY), base_urlos.getenv(LLM_BASE_URL, https://api.openai.com/v1), # 使用非 OpenAI 官方模型如阿里云百煉 qwen時(shí)必須顯式提供 model_info # 否則會(huì)報(bào) model_info is required when model name is not a valid OpenAI model model_info{ vision: False, function_calling: True, json_output: True, family: ModelFamily.UNKNOWN, structured_output: True, multiple_system_messages: True, }, )注意model_info聲明出來(lái)6異步程序的入口是什么asyncio.run7這注解staticmethod有什么用?8解釋下面代碼 vote: Literal[tuple(_.name for _ in agents)] Field( description你要投票淘汰的玩家姓名, )9解釋這段代碼for i, (role, character) in enumerate(zip(roles, characters)):10async with MsgHub 這個(gè) with 是什么意思其實(shí)就是不用寫try-catch了11**kwargs有什么用def __init__( self, model: Optional[str] None, api_key: Optional[str] None, base_url: Optional[str] None, provider: Optional[str] auto, **kwargs ):12Literal[user, assistant, system, tool]?13Agent基本框架14為什么調(diào)用工具返回結(jié)果后還要調(diào)用agent?15記憶系統(tǒng)的架構(gòu)設(shè)計(jì)?16RAG系統(tǒng)框架17有哪四種記憶類型?如何區(qū)分?18為什么要構(gòu)建上下文有什么用19剛才是 apppend怎么這里是 extend?20NoteTool的最佳實(shí)踐原則?21筆記類型有哪些# 筆記類型: blocker(阻塞問(wèn)題)、action(行動(dòng)計(jì)劃)、task_state(任務(wù)狀態(tài))、conclusion(結(jié)論)22智能體通信協(xié)議學(xué)習(xí)框架?23MCP三層架構(gòu)對(duì)應(yīng)什么?24不是 A2AServer 嗎怎么來(lái)了個(gè) A2ATool?A2AServer智能體本身啟動(dòng) Web 服務(wù)提供能力服務(wù)提供者A2ATool封裝好的遠(yuǎn)程調(diào)用工具用來(lái)去調(diào)用 A2AServer客戶端代理25智能體性能評(píng)估有哪三種方式?26旅游助手框架及實(shí)現(xiàn)27Agent回答超時(shí)怎么解決?(如何解決通義千問(wèn) qwen3.8-27b 大模型請(qǐng)求超時(shí)的問(wèn)題?)28實(shí)現(xiàn)了 pydantic, 也就是繼承 BasModel 后會(huì)自動(dòng)校驗(yàn)數(shù)據(jù)類型格式的正確與否嗎29思考模式怎么關(guān)閉?class NoThinkingLLM(HelloAgentsLLM): 關(guān)閉思考模式的LLM子類 Qwen3系列模型默認(rèn)開啟思考(thinking)模式會(huì)先產(chǎn)生大量推理token 顯著拖慢響應(yīng)行程規(guī)劃這類重調(diào)用容易超時(shí)。這里在每次非流式調(diào)用時(shí) 自動(dòng)附加 extra_body{enable_thinking: False} 以關(guān)閉思考。 def invoke(self, messages, **kwargs): extra_body kwargs.pop(extra_body, None) or {} extra_body.setdefault(enable_thinking, False) kwargs[extra_body] extra_body return super().invoke(messages, **kwargs) def get_llm() - HelloAgentsLLM: 獲取LLM實(shí)例(單例模式) Returns: HelloAgentsLLM實(shí)例 global _llm_instance if _llm_instance is None: settings get_settings() # HelloAgentsLLM會(huì)自動(dòng)從環(huán)境變量讀取配置 # 包括OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL等 # 使用NoThinkingLLM關(guān)閉Qwen3的思考模式加快響應(yīng) _llm_instance NoThinkingLLM() print(f? LLM服務(wù)初始化成功) print(f 提供商: {_llm_instance.provider}) print(f 模型: {_llm_instance.model}) return _llm_instance30reloadTrue作用?31為什么不直接調(diào)用API?而是使用多agent?32如果一個(gè)MCPTool需要多個(gè)agent使用該怎么辦?# 創(chuàng)建共享的MCP工具(只創(chuàng)建一次) print( - 創(chuàng)建共享MCP工具...) self.amap_tool MCPTool( nameamap, description高德地圖服務(wù), server_command[uvx, amap-mcp-server], env{AMAP_MAPS_API_KEY: settings.amap_api_key}, auto_expandTrue ) self.amap_tool.expandableTrue # 創(chuàng)建景點(diǎn)搜索Agent print( - 創(chuàng)建景點(diǎn)搜索Agent...) self.attraction_agent SimpleAgent( name景點(diǎn)搜索專家, llmself.llm, system_promptATTRACTION_AGENT_PROMPT ) self.attraction_agent.add_tool(self.amap_tool) # 創(chuàng)建天氣查詢Agent print( - 創(chuàng)建天氣查詢Agent...) self.weather_agent SimpleAgent( name天氣查詢專家, llmself.llm, system_promptWEATHER_AGENT_PROMPT ) self.weather_agent.add_tool(self.amap_tool) # 創(chuàng)建酒店推薦Agent print( - 創(chuàng)建酒店推薦Agent...) self.hotel_agent SimpleAgent( name酒店推薦專家, llmself.llm, system_promptHOTEL_AGENT_PROMPT ) self.hotel_agent.add_tool(self.amap_tool)33重寫的流式 think 撞上空 choices 塊什么意思?class NoThinkingLLM(HelloAgentsLLM): 關(guān)閉思考模式的 LLM 子類。 Qwen3 等模型默認(rèn)開啟思考(thinking)模式會(huì)先產(chǎn)生大量推理 token 顯著拖慢響應(yīng)、增加超時(shí)風(fēng)險(xiǎn)。這里在真正發(fā)起請(qǐng)求時(shí)注入 extra_body{enable_thinking: False} 關(guān)閉思考。 注意hello_agents 的 invoke 只透?jìng)鳌罢{(diào)用時(shí)”的 kwargs不合并構(gòu)造函數(shù) kwargs而流式 think() 內(nèi)部寫死 create(...) 不接受 extra_body 因此必須同時(shí)重寫 invoke 與 think 才能覆蓋非流式與流式兩條路徑。 本地 provider(ollama/lmstudio) 不注入避免非 Qwen 服務(wù)報(bào)錯(cuò)。 _SKIP_PROVIDERS {ollama, lmstudio} def _should_disable_thinking(self) - bool: return getattr(self, provider, None) not in self._SKIP_PROVIDERS def invoke(self, messages: list[dict[str, str]], **kwargs) - str: if self._should_disable_thinking(): extra_body kwargs.pop(extra_body, None) or {} extra_body.setdefault(enable_thinking, False) kwargs[extra_body] extra_body return super().invoke(messages, **kwargs) def think(self, messages: list[dict[str, str]], temperature: float | None None): extra: dict[str, Any] {} if self._should_disable_thinking(): extra[extra_body] {enable_thinking: False} response self._client.chat.completions.create( modelself.model, messagesmessages, temperaturetemperature if temperature is not None else self.temperature, max_tokensself.max_tokens, streamTrue, **extra, ) for chunk in response: # DashScope/Qwen 流式響應(yīng)中會(huì)出現(xiàn) choices 為空列表的控制塊首/尾或 usage 塊 # 直接取 [0] 會(huì) IndexError需跳過(guò)delta 也可能為 None。 if not getattr(chunk, choices, None): continue delta chunk.choices[0].delta content (delta.content or ) if delta else if content: yield content34返回類型 - Configuration 為什么加引號(hào)?35yield fdata: {json.dumps (event,ensure_asciiFalse)}\n\n yield 是干嘛的36總結(jié)日常助手提示詞應(yīng)包含角色Role、配置Profile、技能Skills、規(guī)則Rules、工作流程Workflow及初始化段Initialization。文案優(yōu)化與數(shù)據(jù)查詢助手需明確任務(wù)目標(biāo)與輸出格式。def定義函數(shù)需加括號(hào)調(diào)用而類實(shí)例化不加asyncio.run是異步程序入口。staticmethod使方法無(wú)需實(shí)例即可調(diào)用。Literal限定類型取值**kwargs接收任意關(guān)鍵字參數(shù)。async with MsgHub自動(dòng)管理資源避免手動(dòng)異常處理。