設計接近 Devin 的 AI 系統架構。
這是一個 工程級 Autonomous Software Engineer Agent,能力接近:- Devin
- OpenDevin
- Devika
- AutoGPT
整體會包含你要求的全部模組:
- Codebase reasoning
- Terminal agent
- Browser agent
- Planning tree
- Self-improving tool learning
- Multi-agent system
- Memory + RAG
- Autonomous coding loop
而且 4090 本地可跑。
一、Devin級 AI 系統總架構
USER GOAL
│
▼
Task Planner Agent
│
┌─────────────┼─────────────┐
▼ ▼
Research Agent Code Agent
│ │
▼ ▼
Browser Tool Codebase Reasoner
│ │
▼ ▼
Knowledge RAG File + AST Analyzer
│ │
▼ ▼
Memory ◄────────► Reflection Agent
│
▼
Terminal Executor
│
▼
Test + Debug Loop
│
▼
Final Result
核心思想:
Goal
↓
Planning tree
↓
Multi-agent execution
↓
Self reflection
↓
Code improvement
↓
Loop until success
二、完整專案架構
devin_like_agent/
│
├── agents/
│ ├── planner_agent.py
│ ├── research_agent.py
│ ├── code_agent.py
│ ├── reflection_agent.py
│
├── tools/
│ ├── terminal_tool.py
│ ├── browser_tool.py
│ ├── file_tool.py
│ ├── code_runner.py
│
├── reasoning/
│ ├── codebase_reasoner.py
│ ├── ast_parser.py
│
├── planning/
│ ├── planning_tree.py
│
├── memory/
│ ├── vector_memory.py
│ ├── graph_memory.py
│
├── learning/
│ ├── tool_learning.py
│
├── server/
│ ├── api.py
│
└── ui/
├── chat_ui.py
三、Planning Tree(任務樹)
Devin 類 AI 必須有 任務樹規劃。
planning/planning_tree.py
</>Python
class TaskNode:
def __init__(self, task):
self.task = task
self.children = []
self.status = "pending"
def add_subtask(self, subtask):
node = TaskNode(subtask)
self.children.append(node)
return node
class PlanningTree:
def __init__(self, root_task):
self.root = TaskNode(root_task)
def get_next_task(self):
stack = [self.root]
while stack:
node = stack.pop()
if node.status == "pending":
return node
stack.extend(node.children)
return None
四、Codebase Reasoning
Devin 的核心能力之一。
它會:
理解 repo
分析 function
找到 dependency
修改程式碼
reasoning/codebase_reasoner.py
</>Python
import os
class CodebaseReasoner:
def __init__(self, repo_path):
self.repo = repo_path
def list_files(self):
files = []
for root,_,f in os.walk(self.repo):
for file in f:
if file.endswith(".py"):
files.append(os.path.join(root,file))
return files
def search_code(self, keyword):
results = []
for file in self.list_files():
with open(file) as f:
text = f.read()
if keyword in text:
results.append(file)
return results
五、AST 解析(理解程式)
reasoning/ast_parser.py
</>Python
import ast
class CodeParser:
def parse_functions(self, file):
with open(file) as f:
tree = ast.parse(f.read())
funcs = []
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
funcs.append(node.name)
return funcs
這讓 agent 可以:
理解 code structure六、Terminal Agent
Devin 可以操作 terminal。
tools/terminal_tool.py
</>Python
import subprocess
def run_command(cmd):
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True
)
return result.stdout
Agent 可做:
git clone
pip install
pytest
docker build
七、Browser Agent
tools/browser_tool.py
</>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.content()
browser.close()
return text[:2000]
使用
Playwright
八、Self-Improving Tool Learning
Agent 可以 學習新工具。
learning/tool_learning.py
</>Python
class ToolLearner:
def __init__(self):
self.tools = {}
def add_tool(self,name,code):
self.tools[name] = code
def get_tools(self):
return self.tools
配合 LLM:
LLM 生成新工具
↓
保存
↓
下次使用
這就是 自我進化 agent。
九、Multi-Agent System
Devin 類 AI 必須 多 agent 協作。
Agents:
Planner Agent
Research Agent
Code Agent
Reflection Agent
Planner Agent
agents/planner_agent.py
</>Python
class PlannerAgent:
def plan(self,goal):
return [
"research problem",
"analyze codebase",
"write code",
"run tests"
]
Research Agent
</>Python
class ResearchAgent:
def research(self,query,browser):
return browser(query)
Code Agent
</>Python
class CodeAgent:
def write_code(self,task):
return f"# code for {task}"
Reflection Agent
</>Python
class ReflectionAgent:
def review(self,result):
if "error" in result:
return "fix code"
return "success"
十、Autonomous Execution Loop
真正的 Devin agent 會一直 loop。
</>Python
while True:
task = planner.next_task()
result = executor.run(task)
review = reflection.review(result)
if review == "success":
break
十一、Memory 系統
Vector Memory
RAG:
sentence-transformers
faiss
Graph Memory
追蹤:
task
dependency
file
function
十二、完整 Agent Loop
最終流程:
User goal
↓
Planner Agent
↓
Planning tree
↓
Research agent
↓
Codebase reasoning
↓
Code agent
↓
Terminal execution
↓
Test result
↓
Reflection agent
↓
Fix code
↓
Loop
這就是 Devin 的核心邏輯。
十三、4090 本地配置
推薦模型:
Qwen2.5 14B
DeepSeek-Coder 33B (4bit)
Embedding:
bge-m3
Agent framework:
LangGraph十四、能力會接近
完成後能力接近:
- AutoGPT
- OpenDevin
- Devika
可以做到:
自動寫程式
自動 debug
自動查資料
自動部署
自動測試
十五、如果做到真正接近 Devin
還需要再加:
1️⃣ Workspace sandbox
Docker container。
2️⃣ Code diff patch system
AI 修改 code。
3️⃣ Git agent
自動 commit。
4️⃣ Long horizon planning
任務 > 100 steps。






















