「真正可實作的 5000 行 Devin 開源專案藍圖」,包含:
- 完整 repo 結構
- 每個 agent 的實際 prompt
- LangGraph workflow
- Docker sandbox
- Git 自動 commit agent
- 自動 SaaS 建立
目標是打造一個 Autonomous AI Software Engineer,
可以從需求 → 設計 → 寫程式 → 測試 → 部署 SaaS。
設計理念對齊:
- Devin
- OpenDevin
- AutoGPT
- LangGraph
一、完整 Repo 結構(5000 行級)
devin_autonomous_engineer/
│
├── core/
│ ├── config.py
│ ├── llm.py
│ ├── agent_registry.py
│ ├── event_bus.py
│
├── planning/
│ ├── hierarchical_planner.py
│ ├── task_tree.py
│ ├── tot_reasoner.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
│
├── tools/
│ ├── browser_tool.py
│ ├── terminal_tool.py
│ ├── code_interpreter.py
│ ├── file_editor.py
│
├── memory/
│ ├── vector_store.py
│ ├── graph_memory.py
│ ├── repo_indexer.py
│
├── repo_builder/
│ ├── project_generator.py
│ ├── saas_templates.py
│
├── sandbox/
│ ├── docker_manager.py
│
├── workflows/
│ ├── dev_workflow.py
│
├── api/
│ ├── server.py
│
└── ui/
├── dashboard.py
二、Agent Society(10+ agents)
AI 會模擬一個公司:
CEO Agent
CTO / Architect Agent
Planner Agent
Research Agent
Coding Agent
Testing Agent
Debug Agent
DevOps Agent
Critic Agent
Git Agent
三、每個 Agent 的 Prompt
CEO Agent(定義產品)
agents/ceo_agent.py
</>Python
CEO_PROMPT = """
You are the CEO of an AI software company.
Your job:
- understand the user goal
- convert it into a product specification
- define features
Output:
Product:
Features:
Success criteria:
"""
Architect Agent
</>Python
ARCHITECT_PROMPT = """
You are a senior software architect.
Design system architecture.
Output:
System architecture
Tech stack
Modules
APIs
"""
Planner Agent
</>Python
PLANNER_PROMPT = """
Break the project into tasks.
Return JSON:
[
{ "task": "...", "agent": "coding" },
{ "task": "...", "agent": "testing" }
]
"""
Research Agent
</>Python
RESEARCH_PROMPT = """
Research the topic using web data.
Summarize relevant libraries and solutions.
"""
Coding Agent
</>Python
CODING_PROMPT = """
You are a senior Python developer.
Write production-ready code.
Constraints:
- modular
- type hints
- unit tests
"""
Testing Agent
</>Python
TEST_PROMPT = """
Write unit tests for the code.
Use pytest.
Ensure coverage.
"""
Debug Agent
</>Python
DEBUG_PROMPT = """
Analyze error logs.
Identify root cause.
Return fix.
"""
DevOps Agent
</>Python
DEVOPS_PROMPT = """
Create deployment pipeline.
Include:
Dockerfile
CI workflow
deployment instructions
"""
Critic Agent
</>Python
CRITIC_PROMPT = """
Evaluate the result.
Is the task solved?
If not, explain improvements.
"""
Git Agent
</>Python
GIT_PROMPT = """
Create commit messages.
Format:
type(scope): message
"""
四、Hierarchical Planning
planning/hierarchical_planner.py
</>Python
class PlanNode:
def __init__(self,name):
self.name = name
self.children = []
self.status = "pending"
def add(self,node):
self.children.append(node)
Example plan:
Goal: build SaaS
├─ design architecture
├─ create backend
│ ├─ database
│ └─ API
└─ frontend
五、Tree-of-Thought Reasoning
planning/tot_reasoner.py
</>Python
class ToTReasoner:
def explore(self,problem):
thoughts = [
"approach A",
"approach B",
"approach C"
]
return thoughts
AI 會 嘗試多個解法。
六、LangGraph Workflow
LangGraph 負責 agent workflow。
</>Python
from langgraph.graph import StateGraph
class AgentState(dict):
pass
def build_graph():
graph = StateGraph(AgentState)
graph.add_node("ceo", ceo_agent)
graph.add_node("architect", architect_agent)
graph.add_node("planner", planner_agent)
graph.add_node("coding", coding_agent)
graph.add_node("testing", testing_agent)
graph.add_node("devops", devops_agent)
graph.set_entry_point("ceo")
graph.add_edge("ceo","architect")
graph.add_edge("architect","planner")
graph.add_edge("planner","coding")
graph.add_edge("coding","testing")
graph.add_edge("testing","devops")
return graph.compile()
七、Docker Sandbox
AI 必須在 sandbox 執行程式。
sandbox/docker_manager.py
</>Python
import docker
class DockerSandbox:
def __init__(self):
self.client = docker.from_env()
def run_code(self,image,cmd):
container = self.client.containers.run(
image,
cmd,
detach=True
)
return container.logs()
八、Git 自動 Commit Agent
agents/git_agent.py
</>Python
import subprocess
def commit_changes(msg):
subprocess.run(["git","add","."])
subprocess.run([
"git","commit","-m",msg
])
AI 可以:
寫程式
commit
push
九、Autonomous Repo Builder
repo_builder/project_generator.py
</>Python
import os
class ProjectGenerator:
def create_saas(self,name):
os.makedirs(name+"/backend")
os.makedirs(name+"/frontend")
os.makedirs(name+"/tests")
self.create_readme(name)
十、SaaS Template
</>Python
FASTAPI_TEMPLATE = """
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def hello():
return {"message":"hello"}
"""
十一、Browser Tool
</>Python
from playwright.sync_api import sync_playwright
def browse(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
十二、Terminal Tool
</>Python
import subprocess
def run_cmd(cmd):
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True
)
return result.stdout
十三、Vector Memory
RAG:
</>Python
from sentence_transformers import SentenceTransformer
import faiss
Store:
code
tasks
docs
errors
十四、Autonomous SaaS Creation
AI 可以:
User:
build todo SaaS
AI:
1 define product
2 design architecture
3 create repo
4 write backend
5 write tests
6 dockerize
7 deploy
十五、完整 Autonomous Loop
User Goal
↓
CEO Agent
↓
Architecture
↓
Task planning
↓
Coding
↓
Testing
↓
Debugging
↓
Git commit
↓
Deployment
↓
Critic review
↓
Next iteration
十六、推薦本地模型(4090)
LLM:
Qwen2.5 14B
DeepSeek-Coder 33B (4bit)
Embedding:
bge-m3
十七、最終能力
完成後可以做到:
自動建立 SaaS
自動寫 backend
自動 debug
自動測試
自動 deploy
自動 commit
接近:























