Back to all posts

使用 VM0 GitHub Actions 整合自動化你的 AI 智能體

使用 VM0 GitHub Actions 整合自動化你的 AI 智能體

介紹

今天,我們分享了一個實用範例,使用 vm0-ai/run-action,這是一個 GitHub Action,可讓你直接從 CI/CD 流程觸發 VM0 工作流程。這項整合將智能體自動化帶入你的 GitHub 儲存庫,讓你輕鬆排程並自動執行 AI 智能體。

什麼是 VM0

VM0 是一個用於建構 AI 智能體的智能體執行環境。它提供協調智能體技能、在沙盒中執行智能體,以及用自然語言定義智能體工作流程的基礎設施。

什麼是 GitHub Action

GitHub Actions 是 GitHub 內建的自動化平台,讓你能根據事件或排程執行工作流程。利用 cron 任務,你可以在固定間隔自動執行任務,例如執行 CI 流程、背景作業或 AI 智能體。

從本地到雲端:用 GitHub Actions 執行 VM0 工作流程

過去,執行 VM0 工作流程需要在本地機器上執行 vm0 run 指令。雖然這對於開發和測試很有效(而且 VM0 目前仍在測試階段!),但在以下情境會遇到挑戰:

  • 排程自動化-在特定時間執行智能體需要手動操作
  • CI/CD 整合-將智能體納入部署流程較為複雜
  • 團隊協作-跨團隊分享與協調智能體執行不易
  • 正式環境部署-在正式環境管理智能體有困難

有了全新的 vm0-ai/run-action,你現在可以透過簡單的 Action 設定,直接從 GitHub Actions 觸發 VM0 工作流程。不再需要手動執行指令,只要描述你的智能體任務,GitHub 就會自動排程與執行。

快速開始:你的第一個 VM0 GitHub Action

在 GitHub Actions 中使用 VM0 非常簡單。以下是一個基本範例:

- name: Run VM0 Agent
  uses: vm0-ai/run-action@v1
  with:
    agent: my-agent
    prompt: "Build and test the project"
    artifact-name: my-artifact
    vm0-token: ${{ secrets.VM0_TOKEN }}

設定驗證

要讓 GitHub Actions 能與 VM0 驗證,你需要在儲存庫中設定 VM0_TOKEN 機密。這只需設定一次:

# Generate a VM0 authentication token and store it in GitHub Secrets
vm0 auth setup-token | gh secret set VM0_TOKEN

這個指令會從你本地的 VM0 驗證產生一組權杖,並安全地儲存在 GitHub 儲存庫的機密中,讓你的工作流程可以使用。

實際案例:自動化內容發佈

讓我們透過一個完整範例,展示 VM0 GitHub Actions 整合的威力。我們將建立一個自動化內容農場,每天將 AI 新聞文章發佈到 dev.to。

情境說明

我們已有一個現成的 VM0 工作流程,位於 vm0-cookbooks/104-content-farm,會每日收集 AI 新聞並發佈文章。現在,我們希望這個工作流程能自動按排程執行。

步驟 1:建立 GitHub 儲存庫

首先,建立一個新儲存庫來存放你的自動化工作流程:

# Create and set up your repository
git clone <https://github.com/yourusername/vm0-content-farm>
cd vm0-content-farm

步驟 2:設定工作流程

在你的儲存庫中建立 .github/workflows/daily.yaml:

name: Content Farm

on:
  schedule:
    # Run at 10:00 AM UTC+8 (2:00 AM UTC) every day
    - cron: '0 2 * * *'
  workflow_dispatch:

jobs:
  run-content-farm:
    runs-on: ubuntu-latest
    steps:
      - name: Run Content Farm Agent
        uses: vm0-ai/run-action@v1
        with:
          agent: content-farm
          prompt: "Write an article about recent AI developments, providing brief summaries of each story to help readers quickly browse the news over their morning coffee"
          artifact-name: content-farm-output
          vm0-token: ${{ secrets.VM0_TOKEN }}
          secrets: |
            CLAUDE_CODE_OAUTH_TOKEN=${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
            FAL_KEY=${{ secrets.FAL_KEY }}
            DEVTO_API_KEY=${{ secrets.DEVTO_API_KEY }}

我們來拆解主要組件:

  • schedule:使用 cron 語法,每天於 2:00 上午 PST,UTC-8 執行
  • workflow_dispatch:允許手動觸發以便測試
  • agent:指定要執行的 VM0 智能體
  • prompt:提供智能體應執行的指令
  • secrets:將所需的 API 金鑰與權杖傳遞給智能體

步驟 3:設定你的機密

在儲存庫中設定必要的驗證權杖:

# Set up Claude Code authentication
claude setup-token
gh secret set CLAUDE_CODE_OAUTH_TOKEN --body "your-claude-token"

# Set up other required API keys
gh secret set FAL_KEY --body "your-fal-key"
gh secret set DEVTO_API_KEY --body "your-devto-api-key"

安全提醒:這些機密會安全儲存在 GitHub,只能被你的工作流程存取,永遠不會顯示在日誌或工作流程輸出中。

步驟 4:新增自動部署工作流程

建立 .github/workflows/publish.yml

  name: Publish Agent

  on:
    push:
      branches:
        - main

  jobs:
    publish:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v4
        - uses: vm0-ai/compose-action@v1
          with:
            vm0-token: ${{ secrets.VM0_TOKEN }}

這會在每次推送到 main 時自動部署你的智能體設定,無需手動執行 vm0 compose。

步驟 5:部署與測試

  Deploy:
  # Get the content-farm agent configuration
  git clone https://github.com/vm0-ai/vm0-cookbooks
  cp -r vm0-cookbooks/104-content-farm/* ./

  # Push to trigger auto-deployment
  git add .
  git commit -m "feat: add content farm agent"
  git push origin main

  Test:
  # Manually trigger the workflow
  gh workflow run scheduled-run.yml

完成了!你的智能體現在會在推送時自動部署,並依排程執行。

結論

VM0 GitHub Actions 整合協助你將 AI 智能體帶入現有的開發工作流程。

你不再需要手動執行智能體或將其視為一次性腳本,而是能直接在 CI/CD 流程及排程中執行。這讓你更容易:

  • 自動執行重複性任務,無需時時監控
  • 將智能體融入日常開發與發佈流程
  • 與團隊分享並持續優化智能體工作流程
  • 以更少意外交付智能體自動化

無論你是發佈內容、產生報告、審查程式碼,或自動化內部工作流程,VM0 GitHub Actions 都能讓你在需要時,簡單可靠地執行 AI 智能體。

立即開始,探索我們的 cookbooks repository 以取得實作範例,並在你的 GitHub 工作流程中試用

vm0-ai/run-action。

其他資源

Stay in the loop

// Get the latest insights on AI teammates and collaboration.