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

@@ -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: