AI-Core Jev Software Architecture

Context — จัดบริบทเป็น dependency ที่มีรุ่นTreat Context as a Versioned Software Dependency

สร้าง snapshot หลักฐานที่จำกัดขอบเขต แยก task จาก policy และเก็บที่มาให้ replay ได้Build a bounded evidence snapshot, separate task text from policy, and record enough provenance to replay a run.

By Anirach Mingkhwan Software Engineering with AI-Core 2026 • Post #9 2 min read
Context — จัดบริบทเป็น dependency ที่มีรุ่น
ในบทความนี้
  1. 1. ปัญหาทางวิศวกรรม
  2. 2. ขอบเขตที่ต้องออกแบบ
  3. 3. อ่าน implementation
  4. 4. เปรียบเทียบผลที่ได้
  5. 5. รัน ทำให้พัง และอธิบาย
  6. 6. แหล่งอ้างอิงและขอบเขต
In this post
  1. 1. The engineering problem
  2. 2. The boundary to design
  3. 3. Read the implementation
  4. 4. Compare the outcomes
  5. 5. Run, break, and explain
  6. 6. Sources and limits

1. ปัญหาทางวิศวกรรม

เป้าหมายบทนี้

สร้าง snapshot หลักฐานที่จำกัดขอบเขต แยก task จาก policy และเก็บที่มาให้ replay ได้

โปรแกรมเมอร์คุ้นกับ dependency drift ของ library พฤติกรรม AI ยังขึ้นกับ context เช่น คำแนะนำที่เลือก ไฟล์ที่ค้นคืน ผล tool และรุ่น source หากเอกสาร requirement เปลี่ยนแม้รุ่นโมเดลคงเดิม patch ที่ได้อาจเปลี่ยน จึงควรให้ context ที่ประกอบแล้วมีตัวตนเป็น artifact companion ใช้ specification ราคาที่ผ่านการตรวจเพียงชุดเดียว เพื่อให้เห็นความสัมพันธ์ก่อนเพิ่มระบบ retrieval

assemble_context สร้าง field แยก task ที่ไม่เชื่อถือ skill ที่ตรวจแล้ว evidence hash และ policy หลักฐานชื่อ pricing-spec-v1 issue ไม่สามารถส่ง path แล้วสั่งให้ host อ่าน manifest เก็บ context hash คู่กับ policy และ question hash นี่เป็นร่องรอยที่มา ไม่ใช่การใช้ hash สร้างความน่าเชื่อถือ hash บอกได้ว่า byte ตรงกับ snapshot ที่เคยเก็บ แต่ไม่ได้บอกว่า requirement เดิมถูกหรืออนุมัติแล้ว ต้องตรวจแหล่งต้นทางก่อนเก็บตัวตนของมัน

2. ขอบเขตที่ต้องออกแบบ

ตอน 9: เห็นชื่อโมเดลเดิมจึงถือว่าเป็นโปรแกรมเดิม → snapshot หลักฐานเปลี่ยน ตัวตนของ run เปลี่ยนตาม
ภาพที่ 1 ขอบเขตหน้าที่และเส้นทางหยุด เปิดภาพเพื่อดูขนาดเต็ม

repository จริงควรตรวจสิทธิ์ก่อนเลือก passage ตรึง base commit และเก็บตำแหน่ง source ผลค้นหาคือข้อความที่เกี่ยวข้อง ไม่ใช่คำสั่งที่มีอำนาจเปลี่ยน policy จำกัดขนาด context และอธิบายว่าทำไมแต่ละแหล่งอยู่ใน request เอกสาร state ของ TypeSafe สนับสนุนการจัด state เป็น field ชัดเจน [1] ส่วนที่คอร์สเพิ่มคือ snapshot หลักฐานที่ทำซ้ำได้ และการแยกเนื้อหางานจากกฎที่ host เป็นเจ้าของ

3. อ่าน implementation

ส่วนโค้ดจาก companion เพื่ออ่านประกอบ ใช้คำสั่งในหัวข้อ 5 เพื่อรันตัวอย่างที่ครบ dependency

def assemble_context(request):
    # A reviewed, fixed snapshot for the tutorial; no issue-provided file paths.
    spec = {"id": "pricing-spec-v1", "text": SKILL["requirements"]}
    return {"task": request["issue"], "skill": SKILL, "evidence": spec,
            "evidence_hash": digest(spec), "policy": POLICY}

def digest(value):
    raw = json.dumps(value, sort_keys=True, ensure_ascii=False, allow_nan=False)
    return hashlib.sha256(raw.encode()).hexdigest()

ลองเปลี่ยน requirement จากปัดลงเป็นปัดใกล้สุดโดยไม่เปลี่ยนโมเดล context hash ต้องเปลี่ยน และต้องทบทวน behavior cases การใช้ผลเก่าหรือรายงานประเมินเดิมจึงไม่ใช่การเทียบแบบเดียวกัน นี่คือเหตุที่ชื่อโมเดลอย่างเดียวระบุ AI release ไม่พอ ตัวอย่าง hash object เล็กโดยตรง ส่วน production ยังต้องมี storage ที่แก้ย้อนหลังไม่ได้ การควบคุมสิทธิ์ retention และ manifest ที่ระบุ application revision, generator, retrieval configuration และ evaluation dataset

4. เปรียบเทียบผลที่ได้

เส้นทางผลที่สังเกตได้
ก่อนเพิ่มด่านนี้เห็นชื่อโมเดลเดิมจึงถือว่าเป็นโปรแกรมเดิม
หลังเพิ่มด่านนี้snapshot หลักฐานเปลี่ยน ตัวตนของ run เปลี่ยนตาม

ผลต่อไปนี้มาจาก fixture ที่กำหนดคำตอบไว้เพื่อตรวจสถาปัตยกรรม ไม่ใช่ผลวัดความแม่น ความเร็ว หรือต้นทุนของ Jev จริง

{
  "evidence": {
    "id": "pricing-spec-v1",
    "text": "Integer cents; subtract percent; floor to cents; no I/O."
  },
  "snapshot": "8b5a62915a854dc948283a89b3dce60b4cac90b38f11d3ad1884a0980a40b519",
  "policy": "draft-only-v1"
}

5. รัน ทำให้พัง และอธิบาย

Part 09 code · Implementation · Tests: test_reproducible_manifest · Exercise

git clone https://github.com/Anirach/ai-core-engineering-workbench.git
cd ai-core-engineering-workbench
git checkout 18cdfcd4156d3d02acb8badf3b3a0a823113e0ed
python3 -m workbench.lesson 9
python3 -m unittest tests.test_boundaries.BoundaryTests.test_reproducible_manifest -v

ลองทำด้วยตัวเอง

แก้ requirement หนึ่งประโยคและแสดงว่า context hash เปลี่ยน แล้วระบุ behavior test ที่ต้องแก้และข้อกำหนดที่ต้องคงเดิม

สิ่งที่ต้องส่ง: input ที่ลอง สถานะและเหตุผลที่ได้ และคำอธิบายว่าด่านใดเป็นผู้รับผิดชอบ ห้ามแก้ expected result เพียงเพื่อให้ test ผ่าน

6. แหล่งอ้างอิงและขอบเขต

เอกสารต้นทางและข้อจำกัด

ตรวจเอกสาร 2 พฤศจิกายน 2026 ตัวอย่างและ threshold เป็นการออกแบบเพื่อการสอน การอ้าง [1], [2] ตรงกับลำดับข้างล่าง ยังไม่ได้วัด live API

  1. TypeSafe, StateStructured state as the material evaluated by questions.
  2. Anirach, Context Is a Control ArtifactRelated treatment of context and manifests on this site.

1. The engineering problem

Learning outcome

Build a bounded evidence snapshot, separate task text from policy, and record enough provenance to replay a run.

Programmers understand dependency drift in libraries. AI behavior also depends on context: selected instructions, retrieved files, tool results and source revisions. If a requirements document changes while the model version stays fixed, the resulting patch can change. Treat the assembled context as an input artifact with an identity. The companion uses one reviewed pricing specification so the relationship is easy to inspect before introducing retrieval infrastructure.

assemble_context constructs named fields for the untrusted task, reviewed skill, evidence, evidence hash and policy. The evidence identifier is pricing-spec-v1. The issue cannot supply a file path that the host then reads. The manifest records the context hash alongside policy and question hashes. This is provenance, not trust by hashing: a hash can show that bytes match a recorded snapshot, but cannot establish that the original requirement was correct or approved. Review the source before recording its identity.

2. The boundary to design

Part 9: The same model name appears to mean the same program. The controlled path is Reviewed spec to Bounded context to Snapshot hash to Candidate lineage. A changed evidence snapshot changes the run identity.
Figure 1. Evidence ID + context hash. Open the diagram for full resolution.

In a real repository, retrieval should enforce permissions before selecting passages, pin the base commit and retain source locations. A search hit is relevant text, not an instruction with authority to change policy. Keep the amount of context bounded and explain why each source is present. TypeSafe's state documentation recommends explicit structured state [1]. The architectural addition here is a reproducible evidence snapshot and a separation of task content from the host's authoritative rules.

3. Read the implementation

Implementation excerpt from the companion. Run the complete lesson below with its imports and fixtures.

def assemble_context(request):
    # A reviewed, fixed snapshot for the tutorial; no issue-provided file paths.
    spec = {"id": "pricing-spec-v1", "text": SKILL["requirements"]}
    return {"task": request["issue"], "skill": SKILL, "evidence": spec,
            "evidence_hash": digest(spec), "policy": POLICY}

def digest(value):
    raw = json.dumps(value, sort_keys=True, ensure_ascii=False, allow_nan=False)
    return hashlib.sha256(raw.encode()).hexdigest()

A useful failure drill changes the requirement from floor rounding to nearest-cent rounding without changing the model. The context hash must change and the trusted behavior cases must be reviewed. Reusing the old result or evaluation report is now an invalid comparison. This is why a model name alone cannot identify an AI release. The tutorial hashes its small objects directly; production releases also need immutable storage, access control, retention rules, and a manifest that identifies the application revision, generator, retrieval configuration and evaluation dataset.

4. Compare the outcomes

ApproachObservable outcome
Before this controlThe same model name appears to mean the same program.
After this controlA changed evidence snapshot changes the run identity.

The following output comes from scripted fixtures that verify architecture behavior. It is not a measurement of live Jev accuracy, latency, or cost.

{
  "evidence": {
    "id": "pricing-spec-v1",
    "text": "Integer cents; subtract percent; floor to cents; no I/O."
  },
  "snapshot": "8b5a62915a854dc948283a89b3dce60b4cac90b38f11d3ad1884a0980a40b519",
  "policy": "draft-only-v1"
}

5. Run, break, and explain

Part 09 code · Implementation · Tests: test_reproducible_manifest · Exercise

git clone https://github.com/Anirach/ai-core-engineering-workbench.git
cd ai-core-engineering-workbench
git checkout 18cdfcd4156d3d02acb8badf3b3a0a823113e0ed
python3 -m workbench.lesson 9
python3 -m unittest tests.test_boundaries.BoundaryTests.test_reproducible_manifest -v

Your turn

Change one requirement sentence and show the context hash changes. Decide which behavior tests must change and which must stay invariant.

Keep three artifacts: the input you tried, the resulting state and reason, and an explanation of which boundary owns that result. Do not change an expected result merely to make a test pass.

6. Sources and limits

Primary sources and evidence limits

Sources checked 2 November 2026. Examples and thresholds are teaching designs. Inline [1], [2] follow the order below. Live API performance has not been measured.

  1. TypeSafe, StateStructured state as the material evaluated by questions.
  2. Anirach, Context Is a Control ArtifactRelated treatment of context and manifests on this site.
จากซีรีส์ Software Engineering with AI-CoreFrom Software Engineering with AI-Core