把這個架構升級成完整可運行的「Devin-級 Autonomous AI Engineer 系統設計」。
這是前面 5000 行專案藍圖基礎上升級的完整版本,包含:
- LangGraph workflow(20+ nodes)
- Autonomous coding loop
- multi-repo builder
- agent communication protocol
- LLM fine-tuning pipeline
- Devin
- OpenDevin
- AutoGPT
- LangGraph
整體目標:
AI 可以像工程團隊一樣自動建 SaaS。
一、系統架構
USER GOAL
│
▼
Meta Controller
│
┌───────────────┼───────────────┐
▼ ▼
LangGraph Workflow Memory System
│ │
▼ ▼
Agent Society (12 agents) Vector + Graph
│
▼
Autonomous Coding Loop
│
▼
Multi-Repo Builder
│
▼
Docker Sandbox
│
▼
Terminal + Browser
│
▼
CI / Testing / Deploy
│
▼
Learning Pipeline
二、升級後 Repo 結構
devin_engine/
│
├── core/
│ ├── controller.py
│ ├── agent_protocol.py
│ ├── state.py
│
├── workflow/
│ ├── langgraph_flow.py
│
├── agents/
│ ├── ceo_agent.py
│ ├── architect_agent.py
│ ├── planner_agent.py
│ ├── research_agent.py
│ ├── coding_agent.py
│ ├── testing_agent.py
│ ├── debug_agent.py
│ ├── devops_agent.py
│ ├── critic_agent.py
│ ├── git_agent.py
│ ├── tool_engineer_agent.py
│
├── repos/
│ ├── multi_repo_builder.py
│
├── tools/
│ ├── browser_tool.py
│ ├── terminal_tool.py
│ ├── code_runner.py
│ ├── docker_tool.py
│
├── memory/
│ ├── vector_db.py
│ ├── graph_memory.py
│
├── training/
│ ├── dataset_builder.py
│ ├── finetune_pipeline.py
│
└── ui/
├── dashboard.py
三、LangGraph Workflow(20+ nodes)
Devin 系統核心就是 Agent workflow graph。
workflow/langgraph_flow.py
</>Python
from langgraph.graph import StateGraph
class AgentState(dict):
pass
def build_workflow():
graph = StateGraph(AgentState)
# strategy
graph.add_node("ceo", ceo_agent)
graph.add_node("architect", architect_agent)
# planning
graph.add_node("planner", planner_agent)
# research
graph.add_node("research", research_agent)
# coding loop
graph.add_node("coding", coding_agent)
graph.add_node("testing", testing_agent)
graph.add_node("debug", debug_agent)
# repo management
graph.add_node("repo_builder", repo_builder)
# deployment
graph.add_node("devops", devops_agent)
# quality
graph.add_node("critic", critic_agent)
# learning
graph.add_node("tool_engineer", tool_engineer_agent)
graph.set_entry_point("ceo")
graph.add_edge("ceo","architect")
graph.add_edge("architect","planner")
graph.add_edge("planner","research")
graph.add_edge("research","coding")
graph.add_edge("coding","testing")
graph.add_edge("testing","debug")
graph.add_edge("debug","coding")
graph.add_edge("coding","repo_builder")
graph.add_edge("repo_builder","devops")
graph.add_edge("devops","critic")
graph.add_edge("critic","tool_engineer")
return graph.compile()
實際 production graph
通常 20-40 nodes。
四、Autonomous Coding Loop
AI 自動寫程式 → 測試 → debug。
</>Python
while True:
code = coding_agent.generate(task)
result = test_runner.run(code)
if "error" not in result:
break
fix = debug_agent.fix(result)
code = fix
流程:
</>Python
五、Multi-Repo Builder
Devin 可以 建立多 repo project。
repos/multi_repo_builder.py
</>Python
import os
class MultiRepoBuilder:
def create_project(self,name):
os.makedirs(name)
self.create_repo(name,"backend")
self.create_repo(name,"frontend")
self.create_repo(name,"infra")
def create_repo(self,root,repo):
path = f"{root}/{repo}"
os.makedirs(path)
os.makedirs(path+"/src")
os.makedirs(path+"/tests")
生成:
project/
├ backend
├ frontend
└ infra
六、Agent Communication Protocol
Agents 需要互相溝通。
core/agent_protocol.py
</>Python
class AgentMessage:
def __init__(self,sender,receiver,task,data):
self.sender = sender
self.receiver = receiver
self.task = task
self.data = data
Example:
</>Python
msg = AgentMessage(
"planner",
"coding",
"implement API",
{"language":"python"}
)
Agent message bus:
</>Python
class MessageBus:
def __init__(self):
self.queue = []
def send(self,msg):
self.queue.append(msg)
七、Docker Sandbox
AI 需要安全執行程式。
tools/docker_tool.py
</>Python
import docker
class DockerSandbox:
def __init__(self):
self.client = docker.from_env()
def run(self,image,cmd):
container = self.client.containers.run(
image,
cmd,
detach=True
)
return container.logs()
八、Browser + Terminal Tools
Browser research:
</>Python
from playwright.sync_api import sync_playwright
Terminal:
</>Python
import subprocess
AI 可以:
pip install
pytest
docker
buildgit
clone
九、Memory 系統
Vector memory:
SentenceTransformer
FAISS
Graph memory:
networkx存:
code
errors
solutions
libraries
十、LLM Fine-Tuning Pipeline
系統會 持續訓練模型。
training/dataset_builder.py
</>Python
def build_dataset(tasks,solutions):
data = []
for t,s in zip(tasks,solutions):
data.append({
"instruction":t,
"output":s
})
return data
QLoRA Fine-tuning
training/finetune_pipeline.py
</>Python
from transformers import AutoModelForCausalLM
from peft import LoraConfig
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-7B",
load_in_4bit=True
)
lora = LoraConfig(
r=16,
lora_alpha=32
)
Pipeline:
execution logs
↓
successful fixes
↓
dataset
↓
fine-tune model
↓
better coding agent
十一、Continuous Self-Improvement Loop
整個系統會 持續進化。
task execution
↓
collect logs
↓
extract successful solutions
↓
create dataset
↓
fine-tune model
↓
deploy improved agent
Pseudo code:
</>Python
while True:
result = agent.run(task)
memory.store(task,result)
dataset = build_dataset(memory)
train_model(dataset)
十二、完整 Autonomous AI Company Loop
User idea
↓
CEO agent
↓
Architecture
↓
Task planning
↓
Research
↓
Coding
↓
Testing
↓
Debugging
↓
Repo builder
↓
Git commit
↓
Docker deploy
↓
Critic review
↓
Learning
↓
Next feature
十三、本地硬體配置
RTX 4090:
LLM:
Qwen2.5 14
BDeepSeek-Coder 33B (4bit)
Embedding:
bge-m3
Agent orchestration:
LangGraph
十四、完成後能力
系統可以:
自動建立 SaaS自動寫 API自動寫 frontend自動 debug自動寫 tests自動 dockerize自動 deploy
接近:
- Devin

















