Refine course progression and runtime safety

This commit is contained in:
Haoran
2026-08-11 15:13:13 +08:00
parent b36dbcd84f
commit ab35e59672
83 changed files with 5291 additions and 2267 deletions

View File

@@ -107,7 +107,7 @@ def agent_loop(messages):
messages.append({"role": "user", "content": results})
```
30 行未満 — これが最小実行可能な agent harness のカーネルだ。これは知能そのものではなく、モデルが継続的に行動できるための最小ランタイムフレームワーク。モデルが決定しツールを呼ぶか、どれを呼ぶか、harness が実行する(呼ばれたら実行し、結果を戻す)。次の 18 章はすべてこのループの上に仕組みを積み重ねていく。ループ自体は永遠に変わらない。
30 行未満 — これが最小実行可能な agent harness のカーネルだ。これは知能そのものではなく、モデルが継続的に行動できるための最小ランタイムフレームワーク。モデルが決定しツールを呼ぶか、どれを呼ぶか、harness が実行を担う(ツールを呼び出し、結果を新しいメッセージとして追加する)。次の 19 章はすべてこのループの上に仕組みを積み重ねていく。ループ自体は永遠に変わらない。
---

View File

@@ -107,7 +107,7 @@ def agent_loop(messages):
messages.append({"role": "user", "content": results})
```
Under 30 lines — that's the minimal runnable agent harness kernel. It's not intelligence itself, but the smallest runtime framework that lets the model keep acting. The model decides (whether to call a tool, which one), the harness executes (if called, run it, feed the result back). The next 18 chapters all add mechanisms on top of this loop. The loop itself never changes.
Under 30 lines — that's the minimal runnable agent harness kernel. It's not intelligence itself, but the smallest runtime framework that lets the model keep acting. The model decides (whether to call a tool, which one), the harness executes (calls the tool and appends the result as a new message). The next 19 chapters all add mechanisms on top of this loop. The loop itself never changes.
---

View File

@@ -107,7 +107,7 @@ def agent_loop(messages):
messages.append({"role": "user", "content": results})
```
不到 30 行,这就是最小可运行的 agent harness 内核。它为模型提供持续行动的最小运行框架模型负责决策要不要调工具、调哪个harness 负责执行(调了就跑、结果喂回去)。后面 20 个章节都在这个循环上叠加机制,循环本身始终不变。
不到 30 行,这就是最小可运行的 agent harness 内核。它为模型提供持续行动的最小运行框架模型负责决策要不要调工具、调哪个harness 负责执行(调用工具,把结果作为新消息追加)。后面 19 个章节都在这个循环上叠加机制,循环本身始终不变。
---

View File

@@ -32,7 +32,7 @@ import subprocess
try:
import readline
# macOS libedit 在处理中文输入时有退格问题,这四行修复它
# #143 UTF-8 backspace fix for macOS libedit
readline.parse_and_bind('set bind-tty-special-chars off')
readline.parse_and_bind('set input-meta on')
readline.parse_and_bind('set output-meta on')
@@ -53,7 +53,7 @@ MODEL = os.environ["MODEL_ID"]
SYSTEM = f"You are a coding agent at {os.getcwd()}. Use bash to solve tasks. Act, don't explain."
# ── Tool definition: just bash ────────────────────────────
# -- Tool definition: just bash --
TOOLS = [{
"name": "bash",
"description": "Run a shell command.",
@@ -65,7 +65,7 @@ TOOLS = [{
}]
# ── Tool execution ────────────────────────────────────────
# -- Tool execution --
def run_bash(command: str) -> str:
dangerous = ["rm -rf /", "sudo", "shutdown", "reboot", "> /dev/"]
if any(d in command for d in dangerous):
@@ -81,7 +81,7 @@ def run_bash(command: str) -> str:
return f"Error: {e}"
# ── The core pattern: a while loop that calls tools until the model stops ──
# -- The core pattern: a while loop that calls tools until the model stops --
def agent_loop(messages: list):
while True:
response = client.messages.create(
@@ -113,10 +113,10 @@ def agent_loop(messages: list):
messages.append({"role": "user", "content": results})
# ── Entry point ──────────────────────────────────────────
# -- Entry point --
if __name__ == "__main__":
print("s01: Agent Loop")
print("输入问题,回车发送。输入 q 退出。\n")
print("Enter a question, press Enter to send. Type q to quit.\n")
history = []
while True: