設計一個 Devin 架構版本(一):
包含:- Tree-of-Thought Planning(思考樹規劃)
- Multi-agent society
- Code interpreter
- Autonomous repo builder(自主倉庫建構器)
- Self-training tool generation
- Browser + terminal automation(瀏覽器+終端自動化)
整體能力接近:
- AutoGPT
- OpenDevin
- Devika
而且可以 本地 4090 GPU 運行。
一、整體系統架構(Devin級)
</>Plain text
USER GOAL
│
▼
Meta Controller
│
┌─────────────────┼──────────────────┐
▼ ▼ ▼
Planning Engine Multi-Agent Hub Memory System
│ │ │
▼ ▼ ▼
Tree-of-Thought Agent Society Vector + Graph
│ │
▼ ▼
Task Execution Layer ────── Tool Ecosystem
│
▼
Workspace Sandbox (Docker)
│
▼
Terminal + Browser
│
▼
Code Execution + Repo Builder
│
▼
Reflection + Self Learning
這是 真正 Devin 類系統的核心架構。
二、完整專案架構
</>Plain text
devin_ai_system/
│
├── core/
│ ├── meta_controller.py
│ ├── agent_orchestrator.py
│
├── planning/
│ ├── tree_of_thought.py
│ ├── planner_agent.py
│
├── agents/
│ ├── research_agent.py
│ ├── coding_agent.py
│ ├── testing_agent.py
│ ├── critic_agent.py
│
├── tools/
│ ├── browser_agent.py
│ ├── terminal_agent.py
│ ├── code_interpreter.py
│
├── repo_builder/
│ ├── repo_generator.py
│ ├── file_writer.py
│
├── memory/
│ ├── vector_memory.py
│ ├── graph_memory.py
│
├── learning/
│ ├── tool_generator.py
│ ├── self_training.py
│
├── sandbox/
│ ├── docker_manager.py
│
└── ui/
├── chat_interface.py
三、Tree-of-Thought Planning
Tree-of-Thought 是比 Chain-of-Thought 更高級的推理方法。
planning/tree_of_thought.py
</>Python
class ThoughtNode:
def __init__(self, thought):
self.thought = thought
self.children = []
self.score = 0
class TreeOfThought:
def __init__(self):
self.root = None
def expand(self, node, thoughts):
for t in thoughts:
node.children.append(ThoughtNode(t))
def best_path(self):
best = None
score = -999
stack = [self.root]
while stack:
node = stack.pop()
if node.score > score:
best = node
score = node.score
stack.extend(node.children)
return best
return best
用途:
</>Plain text
Goal
├─ plan A
│ ├─ step1
│ └─ step2
└─ plan B
├─ step1
└─ step2
AI 會 探索多條解法路徑。
四、Multi-Agent Society
AI 不是一個 agent,而是一個 agent 社會。
Agents
</>Plain text
Planner Agent
Research Agent
Coding Agent
Testing Agent
Critic Agent
Agent Orchestrator
core/agent_orchestrator.py
</>Python
class AgentOrchestrator:
def __init__(self):
self.agents = {}
def register(self,name,agent):
self.agents[name] = agent
def run(self,task):
planner = self.agents["planner"]
plan = planner.plan(task)
result = None
for step in plan:
agent = self.agents.get(step["agent"])
result = agent.execute(step["task"])
return result
五、Code Interpreter
類似 ChatGPT Code Interpreter。
tools/code_interpreter.py
</>Python
import subprocess
import tempfile
class CodeInterpreter:
def run_python(self,code):
with tempfile.NamedTemporaryFile(
suffix=".py",delete=False
) as f:
f.write(code.encode())
path = f.name
result = subprocess.run(
["python",path],
capture_output=True,
text=True
)
return result.stdout
可執行:
</>Plain text
data analysis
script
testing
debugging
六、Autonomous Repo Builder
Devin 可以 自動建立整個 repo。
repo_builder/repo_generator.py
</>Python
import os
class RepoBuilder:
def __init__(self,path):
self.path = path
def create_project(self,name):
root = os.path.join(self.path,name)
os.makedirs(root,exist_ok=True)
os.makedirs(root+"/src",exist_ok=True)
os.makedirs(root+"/tests",exist_ok=True)
return root
File Writer
</>Python
from playwright.sync_api import sync_playwright
def search_web(url):
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto(url)
text = page.inner_text("body")
browser.close()
return text[:2000]
七、Browser Automation
使用
Playwright
tools/browser_agent.py
</>Python
from playwright.sync_api import sync_playwright
def search_web(url):
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto(url)
text = page.inner_text("body")
browser.close()
return text[:2000]
八、Terminal Automation
tools/terminal_agent.py
</>Python
import subprocess
def run_terminal(cmd):
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True
)
return result.stdout
AI 可以:
git clone
pip install
pytest
docker build
九、Memory 系統
Vector Memory
RAG。
Sentence Transformers
FAISS
Graph Memory
存:
tasks
files
functions
dependencies
十、Self-Training Tool Generation
AI 可以 自動寫新工具。
learning/tool_generator.py
</>Python
class ToolGenerator:
def __init__(self):
self.tools = {}
def add_tool(self,name,code):
self.tools[name] = code
def list_tools(self):
return self.tools
流程:
problem
↓
LLM寫tool
↓
測試tool
↓
加入tool registry
十一、Workspace Sandbox
Devin 類 AI 必須 安全執行程式。
使用 Docker。
sandbox/docker_manager.py
</>Python
import docker
class Sandbox:
def __init__(self):
self.client = docker.from_env()
def run_container(self,image):
return self.client.containers.run(
image,
detach=True
)
十二、完整 Autonomous Loop
核心邏輯:
User Goal
│
▼
Tree-of-Thought Planning
│
▼
Multi-Agent Execution
│
▼
Browser Research
│
▼
Code Writing
│
▼
Terminal Testing
│
▼
Reflection Agent
│
▼
Fix Code
│
▼
Loop until success
十三、本地模型推薦
4090:
LLM
Qwen2.5 14B
Coding model
DeepSeek-Coder 33B (4bit)
Embedding
bge-m3
Agent framework:
LangGraph
十四、能力會接近
完成後能力接近:
- AutoGPT
- OpenDevin
- Devika
- Devin
可以做到:
自動寫程式
自動debug
自動測試
自動部署
自動建立repo
十五、如果做到「真正接近 Devin」
還需要再加:
1️⃣ Long-horizon planning
任務 > 100 steps。
2️⃣ Code diff patch engine
AI 修改 repo。
3️⃣ Git agent
自動 commit。
4️⃣ CI/CD agent
自動 deploy。




















