Adventure 8
Adventure 8
Adventure 8
Adventure 8
三个问题热热脑子,不要查任何东西 — 就靠预测。
Adventure 8
Adventure 8
Adventure 8
「我没法访问实时数据。」
「东京今天 18°C,多云。」
Adventure 8
是什么:模型生成了一个「看起来像真的、但其实是假的」值(一个日期、一个事实、一个 ID),因为它其实没有真实数据。
好比:一个新员工不敢承认自己不知道你的订单号 — 干脆自信地编了一个。
为什么重要:这是 agent 造成数据损坏的 #1 元凶。永远在执行前验证模型的输出。
Adventure 8
Adventure 8
{
"name": "get_weather",
"description": "Get the current weather in a given city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, e.g. 'Tokyo'"
}
},
"required": ["city"]
}
}Adventure 8
{ "tool": "get_weather", "args": { "city": "Tokyo" } }get_weather() 函数Adventure 8
是什么:一份函数描述(名字 + 参数 + docstring),模型可以请求调用它。
好比:员工手册里的一条。「这是get_weather— 需要时就调用。」模型决定 什么时候调用,你的代码决定 实际发生什么.
为什么重要:Tools 永远不在模型内部,它们是模型外面的插件式模块。
Adventure 8
{"tool": "delete_file", "args": {"path": "/etc/passwd"}}Adventure 8
messages = [system_prompt, user_question]
while True:
response = model.generate(
messages, tools=available_tools)
if response.is_tool_call:
result = execute_tool(
response.tool_name, response.args)
messages.append(response)
messages.append(result)
continue
else:
return response.textAdventure 8
list_files(directory="Downloads")read_file(name="essay1.txt")。检查里面有没有「rocket」→ 没有 → 试下一个文件space_essay.txt"Adventure 8
Adventure 8
是什么:一个 while 循环,让模型调用 tools、看到结果、决定下一步。
好比:一个人在做调研。你查一个来源,它给你一条线索,你再查下一个 — 不可能一开始就把每一步都规划好。
为什么重要:这个循环是 chatbot 和「真正能干活的工人」之间唯一的差别。agent 世界里的一切都建立在它之上。
Adventure 8
Chain | Agent | ||
步骤 | 预先定义好 | 边走边决定 | |
顺序 | 固定 | 动态 | |
举例 | 翻译 → 总结 → 发邮件 | 「搞清楚用户想要什么,然后用一切办法把它做到」 | |
最适合 | 可重复的流程 | 开放式任务 | |
如果某一步失败 | Chain 直接断掉 | Agent 会试点别的办法 |
Adventure 8
*.py)Adventure 8
Read(file_path="app.py")Edit(old_string=..., new_string=...)Bash("python app.py") — 如果报错,就修一下再试Adventure 8
rm -rf,未经允许不要 commitAdventure 8
「Tools 给 agent 能力。
System prompt 给它人格。」
Adventure 8
Bash tool 权限,Claude Code 也会:rm -rf、force-push,或者跳过 pre-commit hooks,除非你明确说可以Adventure 8
你要给这个任务造一个 agent: 「帮我策划朋友的生日 party。」
Adventure 8
Adventure 8
Adventure 8
Adventure 8
Bash, Read,还有 WebFetch.Bash("curl https://...") 而不是 WebFetch。两个都能用 — 但 Bash 更慢、更贵、更难做 sandbox。Adventure 8
delete_user(id="usr_123")usr_123 并不存在。这个 ID 是它编的。list_users),再把它们传给会执行动作的 tools。Adventure 8
foo.py 改名成 bar.py 在这个文件夹里」)).Adventure 8
Adventure 8
get_weather, post_tweet, get_current_city?)Adventure 8
对每一个 tool call,全班一起预测 下一个 call 是什么,然后再点 Allow。
Adventure 8
Adventure 8
Adventure 8
Tool | 一份函数描述(名字 + 参数 + 文档),模型可以请求调用它 | |
Tool call | 结构化输出,模型说「请用参数 Y 跑一下 tool X」 | |
Agent loop | 一个 while 循环,让模型调用 tools 并决定下一步 | |
Agent | LLM + tools + 把它们串起来的循环 | |
Chain | 预先定义好的 LLM/tool 步骤序列;比 agent 灵活度低 | |
Context window | 模型一次能看到的最大 token 数(system + 历史 + 新内容) | |
Hallucination | 模型不承认自己没有,直接编一个值(ID、URL、文件名) |
Adventure 8
Adventure 8