Tất cả trang Học

Tác vụ đầu tiên của bạn, từ đầu đến cuối

Bạn sẽ tạo một dự án nhỏ có một test lỗi, cho AgentDuo một test gate, và để hai agent lập kế hoạch, sửa, kiểm tra và review lỗi đó. Mất vài phút và một số ít lần gọi agent trên tài khoản của bạn.

Trên trang này

Trước khi bắt đầu

  • Claude Code và Codex đã được cài và đăng nhập, và AgentDuo đã được cài: ứng dụng desktop, duo hoặc tiện ích VS Code.
  • Node.js và Git trên máy của bạn: test của dự án chạy bằng node --test, và pipeline cần một kho Git.

Tạo dự án

Dự án có một hàm định dạng số giây thành “1h 02m 05s”, và một lỗi: với từ một giờ trở lên, nó đếm mọi phút kể từ lúc bắt đầu. Hãy tạo ba tệp này trong một thư mục mới tên duo-first-task, bằng bất kỳ trình soạn thảo nào:

package.json

{
  "name": "duo-first-task",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --test"
  }
}

src/duration.js

// Formats a number of seconds for a progress line: "7s", "4m 09s", "1h 02m 05s".
export function formatDuration(totalSeconds) {
  const hours = Math.floor(totalSeconds / 3600);
  const minutes = Math.floor(totalSeconds / 60);
  const seconds = totalSeconds % 60;
  const pad = (n) => String(n).padStart(2, "0");
  if (hours > 0) return `${hours}h ${pad(minutes)}m ${pad(seconds)}s`;
  if (minutes > 0) return `${minutes}m ${pad(seconds)}s`;
  return `${seconds}s`;
}

test/duration.test.js

import assert from "node:assert/strict";
import { test } from "node:test";
import { formatDuration } from "../src/duration.js";

test("seconds only", () => {
  assert.equal(formatDuration(7), "7s");
});

test("minutes and seconds", () => {
  assert.equal(formatDuration(249), "4m 09s");
});

test("hours, minutes and seconds", () => {
  assert.equal(formatDuration(3725), "1h 02m 05s");
});

Tiếp theo là cấu hình AgentDuo, với một gate: AgentDuo chạy npm test sau mỗi vòng triển khai và đưa kết quả cho reviewer.

.agentduo/config.yaml

# .agentduo/config.yaml for the first-task tutorial.
# agentduo runs this gate after every implementation round and shows its result to the code reviewer.
gates:
  - name: tests
    command: "npm test"
    required: true

Trên macOS, Linux, WSL hoặc Git Bash, script này tạo cả bốn tệp cùng lúc:

Terminal (POSIX shell)

mkdir -p duo-first-task/src duo-first-task/test duo-first-task/.agentduo
cd duo-first-task
cat > package.json <<'EOF'
{
  "name": "duo-first-task",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --test"
  }
}
EOF
cat > src/duration.js <<'EOF'
// Formats a number of seconds for a progress line: "7s", "4m 09s", "1h 02m 05s".
export function formatDuration(totalSeconds) {
  const hours = Math.floor(totalSeconds / 3600);
  const minutes = Math.floor(totalSeconds / 60);
  const seconds = totalSeconds % 60;
  const pad = (n) => String(n).padStart(2, "0");
  if (hours > 0) return `${hours}h ${pad(minutes)}m ${pad(seconds)}s`;
  if (minutes > 0) return `${minutes}m ${pad(seconds)}s`;
  return `${seconds}s`;
}
EOF
cat > test/duration.test.js <<'EOF'
import assert from "node:assert/strict";
import { test } from "node:test";
import { formatDuration } from "../src/duration.js";

test("seconds only", () => {
  assert.equal(formatDuration(7), "7s");
});

test("minutes and seconds", () => {
  assert.equal(formatDuration(249), "4m 09s");
});

test("hours, minutes and seconds", () => {
  assert.equal(formatDuration(3725), "1h 02m 05s");
});
EOF
cat > .agentduo/config.yaml <<'EOF'
# .agentduo/config.yaml for the first-task tutorial.
# agentduo runs this gate after every implementation round and shows its result to the code reviewer.
gates:
  - name: tests
    command: "npm test"
    required: true
EOF

Khởi tạo kho Git

Trong thư mục duo-first-task (các lệnh này cũng chạy được trong PowerShell):

Terminal

git init
git add .
git commit -m "Start: formatDuration with a failing test"

Nếu Git hỏi bạn là ai, hãy đặt git config user.name "Your Name" và git config user.email "you@example.com", rồi commit lại.

Xem test thất bại

Terminal

npm test

Hai test đạt và một test thất bại. Trong output:

Output (excerpt)

✖ hours, minutes and seconds
  + '1h 62m 05s'
  - '1h 02m 05s'
ℹ tests 3
ℹ pass 2
ℹ fail 1

Với lệnh terminal, duo doctor giờ cũng liệt kê gate: gate 'tests': npm test.

Chạy pipeline

Bên triển khai phải sửa một tệp. Để nó làm vậy mà không hỏi cho mỗi lần sửa, hãy chuyển chế độ của Claude sang Edit automatically trước. Nếu giữ Manual, hãy trả lời mỗi yêu cầu cấp quyền bằng Allow once.

  1. Terminal

    Mở chat trong thư mục dự án, chuyển chế độ, và giao tác vụ:

    Terminal, then the chat

    duo
    /mode acceptEdits
    /pipeline Fix formatDuration in src/duration.js: for an hour or more it shows the wrong minutes (3725 seconds gives 1h 62m 05s instead of 1h 02m 05s). Keep the output format, and make npm test pass.

    Hoặc, không qua chat, chỉ bằng một lệnh: duo --accept-edits "Fix formatDuration in src/duration.js: for an hour or more it shows the wrong minutes (3725 seconds gives 1h 62m 05s instead of 1h 02m 05s). Keep the output format, and make npm test pass."

  2. Ứng dụng desktop

    Chọn Open project… và chọn duo-first-task. Đặt chế độ quyền dưới ô nhập thành Edit automatically, chọn Pipeline trong menu người nhận (hoặc gõ /pipeline trước tác vụ), và gửi tác vụ ở trên.

  3. VS Code

    Mở thư mục, mở chat, chọn Edit automatically trên chip chế độ và Pipeline trên chip người nhận, rồi gửi tác vụ.

Điều gì xảy ra

Các bước xuất hiện lần lượt, mỗi bước kèm agent đang làm và những gì nó chuyển cho bước sau. Nội dung chính xác khác nhau giữa các lượt chạy; trình tự là:

  1. PLAN

    Codex đọc dự án và viết kế hoạch: mục tiêu, các bước, tiêu chí chấp nhận (ba test đạt, giữ nguyên định dạng) và các rủi ro.

  2. PLAN_REVIEW

    Claude Code đối chiếu kế hoạch với mã. Nếu yêu cầu thay đổi, Codex sẽ chỉnh lại.

  3. PLAN_FINALIZE

    Codex duyệt kế hoạch cuối cùng.

  4. IMPLEMENT

    Claude Code sửa src/duration.js và báo cáo những gì đã làm.

  5. VERIFY

    AgentDuo chạy npm test. Nếu gate thất bại, công việc quay lại Claude Code trước khi có bất kỳ review nào.

  6. CODE_REVIEW

    Codex review diff cùng kết quả gate. Nó chấp thuận, hoặc gửi các phát hiện trở lại cho một vòng nữa.

Lượt chạy kết thúc bằng DONE khi Codex chấp thuận, không còn phát hiện chặn nào và gate đạt. Nếu thay vào đó nó dừng lại để hỏi bạn, xem Quyết định, dừng và tiếp tục.

Xem lại kết quả

AgentDuo đã thay đổi working tree và không commit gì. Hãy xem thay đổi:

Terminal

git diff
npm test

Bạn sẽ thấy một thay đổi ở dòng tính phút, đại loại như:

git diff (excerpt)

-  const minutes = Math.floor(totalSeconds / 60);
+  const minutes = Math.floor((totalSeconds % 3600) / 60);

và ℹ pass 3, ℹ fail 0 từ các test. Các agent có thể viết cách sửa khác; điều cần giữ vững là các test.

  • Trong chat, /diff hiển thị những gì lượt chạy đã thay đổi và /plan hiển thị kế hoạch cuối cùng. Trong ứng dụng desktop và VS Code, hãy mở Changes và Plan.
  • duo status hiển thị các bước và chi phí của lượt chạy; duo list liệt kê các lượt chạy của workspace. report.md của mỗi lượt nằm trong .agentduo/runs/<run-id>/.

Thử dừng và tiếp tục

Chạy lại tác vụ trên một bản sao mới (hoặc một tác vụ nhỏ khác), và nhấn Esc (hoặc Stop) khi một bước đang chạy. Bước đó kết thúc và lượt chạy giữ nguyên trạng thái. Sau đó:

duo

/resume

chạy lại bước đã dừng. Sau khi đóng chat, duo resume trong cùng thư mục tiếp tục lượt chạy gần nhất, và ứng dụng desktop liệt kê nó dưới Resumable runs. /resume <note> thêm ghi chú cho các agent.

Commit bản sửa

Khi diff trông ổn, hãy tự commit. Dữ liệu chạy dưới .agentduo/runs/ có .gitignore riêng, nên nó không nằm trong commit.

Terminal

git add -A
git commit -m "Fix minutes in formatDuration"

Mẹo

Lần tới hãy dùng dự án của chính bạn. Thêm lệnh test của bạn làm gate, bắt đầu với tác vụ nhỏ, và giữ chế độ Manual cho đến khi bạn biết những công cụ nào muốn cho Claude dùng mà không cần hỏi. Quyền hướng dẫn cách cho phép chúng.