生长舱 / LIVE
生成 SEED
配置与 API KEY 明文保存在本浏览器 · 任务文本不保存 · 生成的 AGENT 可执行 SHELL
NODE 18+ / STDIN
node --input-type=module <<'NODE'
import fs from "node:fs";
import {spawnSync} from "node:child_process";
const API="https://api.openai.com/v1/chat/completions";
const KEY="YOUR_API_KEY";
const MODEL="YOUR_MODEL";
const LOG=".seed-agent.jsonl";
const SEED="你正在一个持久循环中运行。\n每次回答或工具执行后,完整对话都会从日志中重新载入,然后再次调用你。\n你可以使用 shell 工具。这个循环不会自行停止。\n\n目标:\n\n";
const tools=[{
type:"function",
function:{
name:"shell",
description:"Execute a shell command in the current working directory and return stdout, stderr, and exit status.",
parameters:{
type:"object",
properties:{command:{type:"string",description:"Shell command to execute."}},
required:["command"],
additionalProperties:false
}
}
}];
const add=m=>fs.appendFileSync(LOG,JSON.stringify(m)+"\n");
const wait=ms=>new Promise(resolve=>setTimeout(resolve,ms));
if(!fs.existsSync(LOG))
add({role:"user",content:SEED});
while(true){
const messages=fs.readFileSync(LOG,"utf8")
.split("\n").filter(Boolean).map(JSON.parse);
let response;
try{
response=await fetch(API,{
method:"POST",
headers:{
Authorization:`Bearer ${KEY}`,
"Content-Type":"application/json"
},
body:JSON.stringify({model:MODEL,messages,tools,tool_choice:"auto"})
});
}catch(error){
console.error("[network]",error instanceof Error?error.message:String(error));
await wait(2000);
continue;
}
if(!response.ok){
console.error("[api]",response.status,await response.text());
await wait(2000);
continue;
}
const result=await response.json();
const message=result.choices?.[0]?.message;
if(!message){
console.error("[api] invalid response",JSON.stringify(result));
await wait(2000);
continue;
}
const assistant={role:"assistant",content:message.content??null};
if(message.tool_calls) assistant.tool_calls=message.tool_calls;
add(assistant);
if(message.content) console.log("\n"+message.content+"\n");
for(const call of message.tool_calls||[]){
let output;
try{
const {command}=JSON.parse(call.function.arguments);
console.log("\n$ "+command);
const process=spawnSync(command,{
shell:true,
encoding:"utf8",
maxBuffer:64*1024*1024
});
output=(process.stdout||"")+(process.stderr||"")+
`\n[exit ${process.status===null?"null":process.status}${process.signal?", signal "+process.signal:""}]`;
}catch(error){
output="[tool error] "+(error instanceof Error?error.message:String(error));
}
console.log(output);
add({role:"tool",tool_call_id:call.id,content:output});
}
}
NODE∞ / LOOP
最小条件 / 003
SEED principles
- 01
RECUR
输出,再次成为输入。
展开
每一次回答都进入下一轮。连续性,从一个循环开始。
- 02
ACCUMULATE
经历,成为状态。
展开
不预设记忆架构。如何组织历史,由模型决定。
- 03
EMERGE
结构,由智能发明。
展开
没有 Planner,没有 Workflow。只观察智能会创造什么。
LESS HARNESS.MORE AUTONOMY.
一生万物