dev-proPRO
OverviewLộ Trình HọcPhỏng VấnAI System
dev-pro— Thực chiến Frontend React, Next.js & Luyện phỏng vấn
contact@dev-pro.online•Code thật. Phỏng vấn thật.
AI Engineeringunderstand · build · evaluate

Lộ trình (3 tracks)

A01AI System Foundations
AI System Foundations0/2 hoàn thành
A02Agent Runtime & Orchestration
Agent Runtime & Orchestration0/3 hoàn thành
A03Agent Skills Engineering
Agent Skills Engineering0/7 hoàn thành
  • Bài học (7)
  • Agent Skills Deep Dive70 phút · Nâng cao
  • Skill không phải Prompt, Tool hay Agent34 phút · Nâng cao
  • Anatomy & Progressive Disclosure38 phút · Nâng cao
  • Authoring: Trigger, Contract & Composition46 phút · Nâng cao
  • Vì sao agents/ chỉ có openai.yaml?36 phút · Nâng cao
  • Scripts, References, Assets & Hooks42 phút · Nâng cao
  • Testing, Evals & Skill Supply Chain52 phút · Nâng cao
Tiến độ0/12 bài
Agent Skills Engineering
Nâng cao
42 phút
#Scripts
#Determinism
#Hooks

Scripts, References, Assets & Hooks

Quyết định phần nào nên là prose, executable, reference, template hay lifecycle hook và thiết kế failure contract an toàn.

Core Mental Model

Judgment ở trong prose; transformation deterministic ở trong code; enforcement chắc chắn ở trong test/hook; knowledge dài ở reference.

Những điều cần nắm chắc

Script phải có input/output/exit-code contract và không được che giấu side effect.

Skill phải hướng dẫn khi chạy script, không chỉ đặt script cạnh SKILL.md.

Hook phù hợp invariant tại lifecycle event; skill phù hợp reasoning theo task.

Assets là vật liệu đầu ra, không nên bị nạp như instruction.

Nội dung bài viết

Quy tắc script-vs-prose

Nếu cùng input luôn phải tạo cùng output và một chương trình có thể làm đáng tin cậy hơn, ưu tiên script: parse report, validate schema, render artifact, normalize data. Nếu quyết định phụ thuộc intent, risk hoặc evidence không hoàn chỉnh, giữ nó trong prose để model suy luận.

Đừng chuyển mọi thứ thành script. Code tăng dependency, permission surface và maintenance. Script chỉ đáng có khi giảm variance, token cost hoặc lỗi thao tác đủ lớn.

Executable contract cần được viết như API

SKILL.md phải nói working directory, command, input, output, exit codes, files được phép ghi và cách xử lý failure. Script phải validate input trước side effect, ghi diagnostic ra stderr, structured result ra stdout và không in secret.

Không dùng script để lách approval hoặc sandbox. Skill text không thể cấp quyền; harness vẫn phải authorize command và target.

Script thực sự được gọi như thế nào?

Luồng đầy đủ có ít nhất sáu ranh giới: model đọc instruction; model quyết định cần executable; model phát tool call; harness kiểm tra command và permission; operating system tạo process; stdout, stderr và exit code quay lại thành observation. scripts/ chỉ là convention tổ chức file, không phải auto-run directory.

Điểm này giải thích vì sao cùng một skill có thể chạy trên hai harness nhưng hành vi khác nhau. Model có thể đưa ra cùng command, song harness A cho network còn harness B chặn; harness A yêu cầu approval còn harness B chỉ cho đọc. Skill ảnh hưởng proposal, harness quyết định capability thực tế.

  • Trước execution: mới có intent và arguments do model đề xuất.
  • Trong execution: sandbox, environment, cwd và dependency quyết định kết quả.
  • Sau execution: model chỉ biết những gì observation trả về, không tự biết process đã làm gì ngoài contract.

Reference ảnh hưởng reasoning nhưng không tự hành động

Reference được đọc vào context giống evidence. Nó có thể thay đổi kết luận, branch hoặc tool call tiếp theo, nhưng không tự ghi file hay gọi API. Tác động gián tiếp vẫn lớn: tài liệu sai có thể khiến model đề xuất hành động sai, nên reference cần owner, version và điều kiện đọc.

Pointer nên nói rõ trigger, path và mục tiêu. Ví dụ: “Nếu diff thay đổi authentication, đọc references/auth-threat-model.md để tạo checklist” tốt hơn “đọc references khi cần”. Cách viết này vừa giảm context vừa tạo được eval case quan sát rõ file nào đáng lẽ phải được mở.

Thiết kế stdout, stderr và exit code như protocol

stdout nên ổn định và machine-readable khi model phải parse kết quả; stderr dành cho diagnostic; exit 0 nghĩa là command hoàn thành theo contract, không nhất thiết business result là “pass”. Non-zero phải phân biệt invalid input, dependency thiếu và execution failure nếu workflow cần recovery khác nhau.

Một script tốt còn định nghĩa idempotency và write set. Chạy lại có ghi đè an toàn không? File nào được tạo? Partial failure để lại artifact nào? Không trả lời được các câu này thì agent khó retry và harness khó review side effect.

Hook khác skill ở tính bắt buộc

Skill dựa vào activation và model compliance. Hook chạy tại event do runtime định nghĩa, phù hợp với formatting sau edit, secret scan trước commit hoặc telemetry sau tool call. Nếu một constraint không được phép bỏ sót, đừng chỉ viết nó thành lời nhắc.

Hook cũng cần budget và failure policy. Một hook fail-closed tăng an toàn nhưng có thể khóa workflow; fail-open giữ availability nhưng phải tạo alert và evidence.

Code & cấu trúc tham khảo

SKILL.md gọi script bằng một contract có thể kiểm thử

markdown
1## Bundle inspection
2
3Run only when the user provides an existing Next.js build report.
4
51. From the repository root, run:
6 `python3 scripts/inspect_bundle.py <report.json>`
72. Treat stdout as JSON with `largestRoutes`.
83. Treat exit 2 as invalid input; do not retry unchanged.
94. Treat exit 3 as a missing dependency; report the dependency.
105. The script is read-only. Stop if it requests a writable target.
116. Compare the result with references/performance-budgets.md.
12
13Done when every reported regression cites route bytes and its budget.

Takeaway: Instruction nối judgment với executable bằng trigger, command, result schema, recovery và done-condition.

Script trả structured evidence

python
1#!/usr/bin/env python3
2import json
3import sys
4from pathlib import Path
5
6if len(sys.argv) != 2:
7 raise SystemExit('usage: inspect_bundle.py <report.json>')
8
9report = Path(sys.argv[1]).resolve()
10if not report.is_file():
11 raise SystemExit(f'report not found: {report}')
12
13data = json.loads(report.read_text(encoding='utf-8'))
14routes = sorted(data['routes'], key=lambda item: item['bytes'], reverse=True)
15print(json.dumps({'largestRoutes': routes[:5]}))

Takeaway: Script thu thập fact lặp lại; skill vẫn phải diễn giải impact dựa trên budget và context sản phẩm.

Tài liệu đọc thêm

Repo, đặc tả và bài viết gốc để đi sâu sau bài học.

6 nguồn chọn lọc
Article
antigravity.google

Google Antigravity Hooks

Lifecycle interceptor hooks và use case enforcement.

Spec
agentskills.io

Agent Skills specification — scripts

Yêu cầu và khuyến nghị cho optional executable resources.

Repository
github.com

Superpowers writing-skills

Cách tổ chức skill, heavy reference và reusable tools.

Docs
developers.openai.com

OpenAI — Shell tool

Hosted shell execution, command lifecycle và container environment.

Docs
developers.openai.com

OpenAI — Local shell

Đưa tool call về runtime local và giữ application chịu trách nhiệm thực thi.

Article
packaging.python.org

Python packaging guide — CLI tools

Entrypoint và packaging contract khi script phát triển thành reusable CLI.