
文心一言寫代碼:代碼生成力的探索
"action": $TOOL_NAME,
"action_input": $INPUT
}
Follow this format:
Question: input question to answer
Thought: consider previous and subsequent steps
Action:
$JSON_BLOB
Observation: action result
... (repeat Thought/Action/Observation N times)
Thought: I know what to respond
Action:
{
"action": "Final Answer",
"action_input": "Final response to human"
}
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:$JSON_BLOB
then Observation
================================= Messages Placeholder ==============================
{chat_history}
================================ Human Message =================================
{input}
{agent_scratchpad}
(reminder to respond in a JSON blob no matter what)
## 開發(fā) Agent 執(zhí)行器
Agent 執(zhí)行器是 Agent 的運行時對象,負責(zé)調(diào)用 Agent 智能體,執(zhí)行它選擇的操作,并將結(jié)果傳回 Agent。以下是創(chuàng)建 Agent 執(zhí)行器的代碼。
```python
from langchain.agents import AgentExecutor
agent_executor = AgentExecutor(agent=agent, tools=tools, handle_parsing_errors=True, verbose=True)
@tool
裝飾器,將其注冊為 LangChain 的工具。通過以上步驟,您可以成功開發(fā)出一個功能強大的 GLM-4 Agent,實現(xiàn)智能任務(wù)處理和復(fù)雜決策。