Jev Engineering

Nhiều thói quen của coding agent chỉ hợp lý vì KV cache. Much of how coding agents work only makes sense because of the KV cache.

Câu hỏi gốc của Diogo Almeida: nếu language model không có KV cache, bạn sẽ thiết kế coding agent thế nào? Trả lời nó là thấy thiết kế nào đáng giữ, thiết kế nào chỉ là đường vòng quanh chi phí. Diogo Almeida's starting question: how would you design a coding agent if language models had no KV cache? Answering it shows which designs are worth keeping and which are just detours around cost.

Cùng 10 lượt làm việc, context sẵn 100k token. Độ dài thanh là tiền. Same 10 turns, 100k tokens already in context. Bar length is money.

Ở lại model đắtStay on the expensive model ~$1.30
Sang model rẻ rồi quay vềSwitch to cheap, then back ~$2.09
đọc từ cache (rẻ)cache reads (cheap) output và tool outputoutput and tool output cache nguội: ghi mới, xử lý lạicold cache: rewrite, reprocess

Giả định minh hoạ: giá 5/25 và 3/15 USD mỗi triệu token, đọc cache 10%, ghi cache 125%. Khoản đỏ lớn cuối là model đắt đọc lại toàn bộ context khi quay về. Illustrative assumptions: $5/$25 and $3/$15 per million tokens, cache reads at 10%, writes at 125%. The big red block is the expensive model rereading the whole context on return.

Bốn điểm ảnh gốc cần hiểu đúngFour things the source image needs corrected

  • Đây là phác thảo, không phải sản phẩm. Almeida gọi ghi chú của mình là brainstorm và mong cộng đồng tự xây. Chưa có Jev harness chính thức. It's a sketch, not a product. Almeida calls his notes brainstorming and hopes the community builds it. No official Jev harness exists.
  • Routing chỉ lỗ khi quay về. Tác vụ độc lập, không cần context phiên cha, route sang model rẻ vẫn tiết kiệm. Routing only loses money on the return trip. Independent tasks that don't need parent context still save money on a cheap model.
  • "Không hallucinate" nghĩa là không ra ngoài schema. Jev vẫn có thể chọn sai một giá trị hợp lệ. "Can't hallucinate" means no out-of-schema values. Jev can still pick a wrong valid value.
  • "Không có đổi mới ngoài model" là quan điểm. Phần harness của Claude Code, Codex, Cursor đã thay đổi nhiều qua các phiên bản. "No innovation outside the model" is an opinion. The harnesses in Claude Code, Codex, and Cursor have changed a lot across versions.

Chọn cái nàoWhich one to pick

Bắt đầu từ bên trái. Phần lớn đội không cần đi sang bên phải.Start on the left. Most teams never need to go right.

Không dùng gì cảUse none of it

Đủ dùng khi phiên ngắn, một model, và bạn không tự viết harness.Enough when sessions are short, you use one model, and you don't write your own harness.

  1. Một model, bật prompt caching, giữ system prompt và tool cố định cả phiên.One model, prompt caching on, system prompt and tools fixed for the session.
  2. Mỗi tác vụ một phiên mới, bàn giao bằng commit.One fresh session per task, handed off via commits.
  3. AGENTS.md ngắn.A short AGENTS.md.
  4. Hook trước tool với danh sách chặn lệnh phá huỷ.A pre-tool hook blocking destructive commands.
  • Không tự viết harness?Not writing your own harness?—Baseline, thêm X3 qua hookBaseline, add X3 via hooks
  • Agent chạy lệnh khi không ai canh?Agent runs commands unattended?X3làm đầu tiêndo first
  • Đang routing giữa nhiều model?Routing between models?X1
  • Schema tool chiếm trên 15% context?Tool schemas over 15% of context?C2
  • AGENTS.md dài, nhiều mảng?Long, multi-area AGENTS.md?C3
  • Agent kẹt vòng lặp, báo xong sai?Agent loops or claims done falsely?X2
  • Phiên nhiều giờ, restart thường xuyên?Multi-hour sessions, frequent restarts?S1rồi mớithenC1

Kiến trúc được đề xuấtThe proposed architecture

Nét liền là dữ liệu chảy qua. Nét đứt là quyết định Jev đưa ra ở mỗi lượt.Solid lines are data flow. Dashed lines are decisions Jev makes on each turn.

Jev harness: chunk store and Jev decisions feed context assembly and router, which feed the runtime that calls tools and models. Chunk store turns · tool calls · diffs AGENTS.md · cached prefix addressable, typed Jev Choice · Score · Noul typed answers + probabilities Context Assembly Router Runtime Tools snippets first, schema on demand LLMs frontier · cheap · reviewers repo · files · test logs · git history permit
Chunk storeChunk store
Mọi thứ trong phiên được lưu thành chunk có địa chỉ, không phải một chuỗi text dài.Everything in the session is stored as addressable chunks, not one long string.
Jev
Trả lời các câu hỏi mỗi lượt: hiện chunk nào, có tái dùng cache không, model và tool nào, lệnh có được chạy không.Answers the per-turn questions: which chunks to show, whether to reuse the cache, which model and tool, whether a command may run.
Context Assembly · Router
Lắp prompt từ chunk và chọn model, có tính chi phí xử lý lại và chính sách bảo mật.Builds the prompt from chunks and picks the model, pricing in reprocessing and a security policy.
Runtime
Gọi tool theo tầng và gửi việc tới model frontier, model rẻ hoặc reviewer chạy nền.Calls tools in tiers and sends work to frontier, cheap, or background reviewer models.

Bảy khái niệmSeven concepts

Mã chữ cái là nhóm, không phải thứ tự. Câu có viền màu là cái giá bạn chấp nhận trả.The letter code is the group, not an order. The colored line is the price you agree to pay.

Trạng tháiState

dữ liệu harness lưu và truy xuấtwhat the harness stores and retrieves

S1

Trạng thái tường minhExplicit state

Trạng tháiState

Lưu lịch sử thành chunk có kiểu và địa chỉ, rồi lắp prompt từ chúng thay vì nối đuôi.Store history as typed, addressable chunks and assemble prompts from them instead of appending.

[fixed prefix: system + core tools]  ← never reorder
[u-014][tc-221][diff-087][md#db]      ← assembled per turn
Dùng choUse for
Phiên nhiều giờ, audit, khôi phục state hỏngMulti-hour sessions, audits, recovering corrupted state
ĐượcGain
Restart không mất hết; truy vết mọi lựa chọn contextRestarts don't lose everything; every context choice is traceable
MấtLose
Sắp xếp lại prompt là phá prefix cache, hoá đơn tăngReordering the prompt breaks the prefix cache and raises the bill

Đổi sự đơn giản của lịch sử nối đuôi lấy khả năng chọn lọc, khôi phục và kiểm toán context.Trades the simplicity of append-only history for the ability to select, recover, and audit context.

Dấu hiệu:Tell: sau sự cố không ai trả lời được model đã thấy gì.after an incident, nobody can say what the model saw.

Ngữ cảnhContext

cái gì được đưa vào promptwhat goes into the prompt

C1

Chấm điểm chunkChunk scoring

meta-attention

Hỏi Jev từng chunk có liên quan tới truy vấn hiện tại không, và nên hiện ở dạng nào. Thay cho compaction nén mù.Ask Jev whether each chunk is relevant to the current query, and in what form. Replaces blind compaction.

chunk → Score → 0 hide · 1 short · 2 long · 3 full
Dùng choUse for
Phiên dài đầy log cũ, đổi chủ đề giữa phiên, lọc kết quả tìm kiếmLong sessions full of stale logs, mid-session topic changes, filtering search results
ĐượcGain
Nén có mục đích; rerank: top-1 5% → 18% với khoảng $0.06 cho 1 200 lần chấmPurposeful compression; rerank: top-1 5% → 18% for about $0.06 across 1,200 scores
MấtLose
70–500 ms mỗi lượt; chunk liên quan gián tiếp dễ bị loại; chưa được kiểm chứng trên agent thật70–500 ms per turn; indirectly relevant chunks get dropped; untested on real agents

Đổi độ ổn định của prefix cache và một ít độ trễ lấy context gọn, sát truy vấn.Trades prefix-cache stability and some latency for lean, query-specific context.

Dấu hiệu:Tell: hơn nửa context là output model không bao giờ nhắc lại.over half the context is output the model never mentions again.

C2

Tool theo tầngTiered tool disclosure

Ngữ cảnhContext

Mỗi tool một dòng mô tả; schema đầy đủ chỉ nạp khi tool được chọn.One description line per tool; the full schema loads only when the tool is picked.

100+ snippets → Jev Choice top-K → 1 full schema
Dùng choUse for
Nhiều MCP server, bộ CLI lớn, sản phẩm "batteries included"Many MCP servers, large CLI toolsets, "batteries included" products
ĐượcGain
Context không tăng theo số toolContext no longer grows with tool count
MấtLose
Phương án na ná nhau thì Jev chọn kém (90 ô: thua heuristic; 16 phương án rõ: ngang solver)Jev struggles with look-alike options (90 cells: lost to a heuristic; 16 clear options: matched a solver)

Đổi việc model thấy mọi tool từ đầu lấy context nhẹ và số tool gần như không giới hạn.Trades the model seeing every tool upfront for a light context and near-unlimited tools.

Dấu hiệu:Tell: schema tool chiếm 10–20% context trước khi làm gì.tool schemas take 10–20% of context before any work.

C3

Hướng dẫn có điều kiệnConditional instructions

Ngữ cảnhContext

Cắt AGENTS.md thành đoạn có phạm vi; chỉ nạp đoạn liên quan tới tác vụ.Split AGENTS.md into scoped sections; load only those relevant to the task.

#general  always
#db       migrations/**, *.sql   (glob)
#payments "billing work"         (Jev Noul)
Dùng choUse for
Monorepo nhiều quy ước, quy tắc cho thao tác hiếmMonorepos with many conventions, rules for rare operations
ĐượcGain
Ít token cố định, model ít bị phân tâmFewer fixed tokens, less distraction
MấtLose
Lọc nhầm là vi phạm im lặng, không ai báoMis-filtering is a silent violation nobody reports

Đổi sự chắc chắn model luôn thấy mọi quy tắc lấy context gọn và ít nhiễu.Trades the certainty that every rule is always visible for lean, low-noise context.

Dấu hiệu:Tell: model áp quy tắc release khi đang sửa CSS.the model applies release rules while editing CSS.

Thực thiExecution

ai chạy, cái gì được phép chạywho runs, what may run

X1

Routing có tính cacheCache-aware routing

Thực thiExecution

So sánh model bằng tổng chi phí thật, gồm cả việc model đích phải đọc lại context chưa có trong cache.Compare models by true total cost, including the target rereading context it hasn't cached.

Opus ──────────────────► warm
Opus ─► Sonnet ─► Opus   reprocess ALL
Dùng choUse for
Harness tự viết có nhiều model; tách tác vụ độc lập; giữ code nhạy cảm trong nhàCustom multi-model harnesses; offloading independent tasks; keeping sensitive code in-house
ĐượcGain
Tránh kiểu routing đắt hơn ~60% trong ví dụ minh hoạAvoids routing that cost ~60% more in the illustration
MấtLose
Cần mô hình giá và TTL đúng; phép tính phải nằm trong codeNeeds correct prices and TTLs; the math must live in code

Đổi phần tiết kiệm bề nổi của model rẻ lấy tổng chi phí thật thấp hơn cho phiên dài.Trades a cheap model's surface savings for lower true cost on long sessions.

Dấu hiệu:Tell: bạn quyết định route bằng bảng giá mỗi token.you pick routes from a per-token price sheet.

X2

Reviewer chạy nềnBackground reviewers

Thực thiExecution

Các tác vụ chỉ đọc dùng chung một lượt truy xuất state, hỏi Jev song song, chỉ trả về cảnh báo.Read-only tasks share one state retrieval, ask Jev in parallel, and only return warnings.

state ─┬─ stub? ─ loop? ─ "done" w/o tests? ─ rule break?
       └─► flags to main agent
Dùng choUse for
Vòng lặp kẹt, báo xong không bằng chứng, code giả, vi phạm quy ướcStuck loops, unproven "done", fake code, convention breaks
ĐượcGain
Kiểm tra mọi bước với chi phí gần bằng khôngChecks every step at near-zero cost
MấtLose
Không giải thích hay sửa được; Jev bắt 6/7 lỗi, Fable 5.1 bắt 7/7Can't explain or fix; Jev caught 6 of 7 defects, Fable 5.1 caught 7

Đổi độ sâu của review bằng LLM lấy khả năng soát mọi bước gần như miễn phí.Trades the depth of an LLM review for checking every step almost for free.

Dấu hiệu:Tell: cùng một lệnh test chạy năm lần mà không đổi gì.the same test command runs five times with no change.

X3

Kiểm duyệt lệnhPermission gating

Thực thiExecution

Trước mỗi lệnh, hỏi Jev lệnh có phá huỷ, lệch tác vụ, hay khác kế hoạch không; code quyết định cho chạy hay giữ lại.Before each command, ask Jev if it's destructive, off-task, or off-plan; code decides to allow or hold.

< 0.5 allow · 0.5–0.7 warn · > 0.7 hold for a human
Dùng choUse for
Agent chạy qua đêm, thay allowlist dài hàng trăm dòngOvernight agents, replacing allowlists hundreds of lines long
ĐượcGain
pi-warden: 17 000 lần gọi, giữ 42 lần, ~88% đúng, ~250 mspi-warden: 17,000 calls, 42 holds, ~88% correct, ~250 ms
MấtLose
Là bộ lọc, không phải ranh giới bảo mật; nội dung thao túng có thể đẩy kết quảA filter, not a security boundary; manipulative content can push results

Đổi sự chắc chắn của việc người duyệt mọi lệnh lấy tính tự chủ với rủi ro đo bằng xác suất.Trades a human approving every command for autonomy with risk measured as probability.

Dấu hiệu:Tell: bạn bấm "Allow" cho mọi lệnh vì quá nhiều.you click "Allow" on everything because there's too much.

Bảng đánh đổiTrade-off table

Cột "rủi ro phá prefix cache" là cột quyết định: mọi lợi ích nén đều phải trừ đi nó.The "prefix-cache risk" column decides everything: every compression gain has it subtracted.

Khái niệmConcept Tiết kiệm tokenToken savings Độ trễ thêmAdded latency Rủi ro phá prefix cachePrefix-cache risk Rủi ro mất thông tinInformation-loss risk Độ khó vận hànhOps difficulty Đã kiểm chứngHow proven
S1Gián tiếpIndirectKhông đáng kểNegligibleCao nếu làm saiHigh if done wrongThấpLowCaoHighÝ tưởng, tự làmIdea, homegrown
C1CaoHigh70–500 msCaoHighTrung bìnhMediumCaoHighChỉ có số ở rerankRerank numbers only
C2Cao khi nhiều toolHigh with many toolsThêm một bướcOne extra stepTrung bìnhMediumTrung bìnhMediumTrung bìnhMediumCó tiền lệ (skill)Precedent (skills)
C3Thấp–trung bìnhLow–mediumGần như khôngAlmost noneThấp nếu cố định theo tác vụLow if fixed per taskCaoHighThấpLowDễ tự kiểmEasy to verify
X1Trung bình–caoMedium–highVài trăm msA few hundred msLà thứ cần tránhWhat it avoidsThấpLowTrung bìnhMediumCó tính toán, chưa có số thậtWorked math, no production data
X2Tăng nhẹSlight increase0 nếu song song0 if parallelKhôngNoneKhôngNoneThấpLowCó dự án cộng đồngCommunity projects
X3Tăng nhẹSlight increase~250 msKhôngNoneKhôngNoneThấpLowCó số (pi-warden)Measured (pi-warden)

Anti-patterns

Sai lầmMistakeVì sao saiWhy it's wrongSửa thế nàoFix
Route theo giá mỗi tokenRouting by per-token priceBỏ qua chi phí đọc lại khi quay vềIgnores reprocessing on returnCộng chi phí khởi động lạnh; chỉ route tác vụ độc lậpAdd cold-start cost; route only independent tasks
Lắp lại cả prompt mỗi lượtReassembling the whole prompt each turnPhá prefix cacheBreaks the prefix cacheGiữ prefix cố định, chỉ lắp phần đuôiKeep the prefix fixed, assemble only the tail
Bắt Jev tính, đếm, so ngàyAsking Jev to compute, count, compare datesJev nhận diện hình dạng, không tínhJev recognizes shapes, doesn't computeLàm bằng code, đưa kết quả vào stateDo it in code, pass the result as state
Jev là lớp bảo mật duy nhấtJev as the only security layerNội dung thao túng đẩy được xác suấtManipulative content shifts probabilitiesSandbox, backup, danh sách chặn cứngSandbox, backups, a hard blocklist
Choice với hàng chục phương án na náChoice over dozens of look-alike optionsJev phân biệt kémJev discriminates poorlyLọc bằng code xuống danh sách ngắn, mô tả rõFilter in code to a short, well-described list
Quy tắc an toàn nằm trong đoạn có điều kiệnSafety rules in conditional sectionsLọc nhầm là vi phạm im lặngMis-filtering is a silent violationLuôn nạp cố địnhAlways load them
Tin "0% hallucination" là "luôn đúng"Reading "0% hallucination" as "always right"Chỉ nghĩa là không ra ngoài schemaIt only means in-schemaĐo trên dữ liệu của bạn, dùng ngưỡng độ tin cậyMeasure on your data, gate on confidence
Làm cả kiến trúc một lầnBuilding the whole architecture at oncePhần lớn chưa kiểm chứngMost of it is unprovenTừng khái niệm, đo trước và sauOne concept at a time, measure before and after

Ba câu cần nhớThree things to remember

  • Nhiều thói quen tồn tại vì xử lý lại context quá đắt, không phải vì chúng tối ưu. Hỏi lại từng cái: nếu không có KV cache thì sao?Many habits exist because reprocessing context is expensive, not because they're optimal. Ask of each: what if there were no KV cache?
  • Mọi quyết định động về context đều trả giá bằng prefix cache. Chỉ làm khi lợi ích lớn hơn chi phí đọc lại, và đo chứ đừng đoán.Every dynamic context decision is paid for in prefix cache. Do it only when the gain beats the reprocessing cost, and measure rather than guess.
  • Jev dùng để phán xét, không để suy nghĩ thay. Câu hỏi hẹp, phép tính trong code, ngưỡng từ dữ liệu, và luôn có một lớp bảo vệ không phụ thuộc vào nó.Use Jev to judge, not to think for you. Narrow questions, math in code, thresholds from data, and always a safeguard that doesn't depend on it.