2025 強大 AI Agent 登陸 VSCode | 打造終極語言模型程式助理


「當我看著 AI Agent(代理)在 VSCode 中自動修復 bug、生成完整功能模組,甚至主動提出架構優化建議時,我知道程式開發的遊戲規則已經永遠改變了。」

這不是科幻電影的情節,而是 2025 年每個開發者都能擁有的現實。AI Agent(代理)不再只是簡單的程式碼補全工具,它已經進化成能夠理解上下文、自主決策、甚至跨模型協作的智能編程夥伴

AI Agent

什麼是 AI Agent?

如果說過去的 AI 只是「會聊天的工具」, 那 AI 代理,就是那個會「自己動手做事」的助手。

傳統 AIAI 代理
只會聊天,提供建議主動規劃與執行任務
回答問題,但不操作給出成果,而不只是建議
無上下文意圖可理解上下文並自主決策

AI 代理的核心運作模式

AI Agent 不再只是單一模型,而是一個具備 意圖與行動能力的系統 (Intelligent Agent)。即便這次我們只用 Gemma3,它也能獨立完成從規劃到生成的整個流程:

  • 撰寫技術文檔與 README
  • 理解需求
  • 規劃專案架構
  • 生成程式碼

安裝 Gemma3 模型

假設已經安裝好 VSCode、Continue 外掛以及 Ollama。如果尚未安裝,可先參考前一篇教學完成 Ollama 安裝。

  • 下載 Gemma3 模型:
ollama pull gemma3:27b
ollama list

檢查是否成功下載與模型大小。

  • 啟動本地服務:
ollama serve
  • 快速測試:
curl http://localhost:11434/api/generate -d '{"model":"gemma3:27b","prompt":"Hello"}'

若收到 JSON 回應,代表 API 可正常使用。

安裝 Continue 外掛

  • 開啟 VSCode
  • 搜尋安裝 Continue
  • 開啟設定檔 ~/.continue/config.yaml
  • 將 Gemma3 配置加入:
name: LocalAI-Gemma
version: 1.0.0
schema: v1

models:
  - name: Gemma3 27B (Doc Agent)
    provider: ollama
    model: gemma3:27b
    roles: [chat, edit, apply]
    defaultCompletionOptions:
      temperature: 0.3

context:
  - provider: file
  - provider: code
  - provider: diff
  - provider: terminal

rules:
  - Give concise and clear answers
  - Always provide code examples if possible
  - Explain your reasoning when making architectural decisions

prompts:
  - name: generate_flask_project
    description: Generate a full Flask project structure with blueprints, models, and config
    prompt: |
      Please generate a complete Flask project structure with main app, blueprints, models, and config files.
      Explain each file and folder briefly.
      Provide the code in markdown code blocks.

mcpServers: []
data: []

AI Agent 協作實戰:從需求到生成

假設需求:

  • 「生成一個完整 Flask 專案,包含 app、藍圖 (blueprints)、模型 (models)、配置 (config) 與 README。」

流程示範:

  1. 打開 VSCode,啟動 Continue 外掛
  2. 切換到 Agent 模式
  3. 選擇模型 Gemma3 27B
  4. 輸入 Prompt
Generate a complete Flask project with blueprints, models, config, and README.

AI Agent 自動生成結果

  • 專案結構
flask_project/
├── app/
│   ├── __init__.py
│   ├── main.py
│   └── config.py
├── blueprints/
│   ├── api/
│   │   ├── __init__.py
│   │   └── routes.py
│   └── auth/
│       ├── __init__.py
│       └── routes.py
├── models/
│   ├── user_model.py
│   └── article_model.py
├── extensions.py
├── requirements.txt
└── README.md
  • 初始化 Flask 應用(app/__init__.py
from flask import Flask
from app.config import Config
from extensions import db, migrate
from blueprints.api import api_bp
from blueprints.auth import auth_bp

def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(api_bp)
    app.register_blueprint(auth_bp)

    return app
  • 主程式入口(app/main.py
from app.__init__ import create_app

app = create_app()

if __name__ == '__main__':
    app.run(debug=True)
  • 應用設定(app/config.py
import os

class Config:
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', 'sqlite:///db.sqlite')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SECRET_KEY = os.environ.get('SECRET_KEY', 'your-secret-key')
  • API 藍圖初始化(blueprints/api/__init__.py
from flask import Blueprint

api_bp = Blueprint('api', __name__, url_prefix='/api')
from blueprints.api import routes
  • API 路由(blueprints/api/routes.py
from flask import jsonify
from blueprints.api.__init__ import api_bp

@api_bp.route('/test', methods=['GET'])
def test():
    return jsonify({'message': 'API 測試成功!'})
  • 認證藍圖初始化(blueprints/auth/__init__.py
from flask import Blueprint

auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
from blueprints.auth import routes
  • 認證路由(blueprints/auth/routes.py
from flask import jsonify, request
from blueprints.auth.__init__ import auth_bp

@auth_bp.route('/login', methods=['POST'])
def login():
    data = request.get_json()
    # 測試範例,請換成實際認證邏輯
    if data.get('username') == 'test' and data.get('password') == 'password':
        return jsonify({'message': '登入成功!'})
    else:
        return jsonify({'message': '帳號或密碼錯誤'}), 401
  • 資料模型:User(models/user_model.py
from extensions import db

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)

    def __repr__(self):
        return f'<User {self.username}>'
  • 資料模型:Article(models/article_model.py
from extensions import db

class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship('User', backref=db.backref('articles', lazy=True))

    def __repr__(self):
        return f'<Article {self.title}>'
  • 擴充功能初始化(extensions.py
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

db = SQLAlchemy()
migrate = Migrate(db, db)
  • 依賴清單(requirements.txt
Flask
Flask-SQLAlchemy
Flask-Migrate
  • README.md
# Flask Project Template

## Description

This is a basic Flask project template with blueprints, models, and configuration. It provides a starting point for building web applications with Flask.

## Dependencies

- Python 3.6 or higher
- Flask
- Flask-SQLAlchemy
- Flask-Migrate

## Installation

1. Clone the repository:

   ```bash
   git clone [your-repository-url]
   cd [your-project-directory]
   ```

2. Create a virtual environment (recommended):

   ```bash
   python3 -m venv venv
   source venv/bin/activate  # On Linux/macOS
   venv\Scripts\activate  # On Windows
   ```

3. Install dependencies:

   ```bash
   pip install -r requirements.txt
   ```

4. Initialize the database:

   ```bash
   flask db init
   flask db migrate
   flask db upgrade
   ```

## Running the Application

```bash
flask run
```

The application will be accessible at `http://127.0.0.1:5000/`.

## API Endpoints

- `/api/test`:  Returns a JSON message indicating the API is working.
- `/auth/login`:  Simulates a login endpoint.

## Project Structure

```
flask_project/
├── app/
│   ├── __init__.py
│   ├── main.py
│   └── config.py
├── blueprints/
│   ├── api/
│   │   ├── __init__.py
│   │   └── routes.py
│   └── auth/
│       ├── __init__.py
│       └── routes.py
├── models/
│   ├── user_model.py
│   └── article_model.py
├── extensions.py
├── requirements.txt
└── README.md
```

結論

AI Agent(代理)是具備自主思考與行動能力的智能系統,能夠深度理解人類意圖、自主規劃執行步驟,並實際完成複雜任務。與傳統AI僅被動回答問題不同,AI 代理會主動分析需求、制定策略、選擇工具,並執行具體行動,例如自動建立完整專案架構、撰寫可運行程式碼、生成技術文件,並確保最終成果符合預期目標。

更進階的是,多個AI 代理能夠組成協作網絡,如同專業團隊般分工合作。不同專長的代理各司其職——邏輯推理專家負責架構設計、程式開發專家專注代碼實現、文檔專家完善技術資料,形成高效的工作流水線。這種協作模式不僅提升任務完成質量,更大幅擴展了可處理問題的複雜度。

這種「從理解到執行」的完整能力鏈,標誌著AI技術從被動工具到主動夥伴的本質轉變。AI 代理不再只是回答問題的聊天機器人,而是真正能動手解決問題的智能助手,為人類工作者帶來前所未有的效率革命,重新定義人機協作的未來樣貌。