# Reconnect the cache exercise to an Agent project / 将缓存练习接回 Agent 项目

## English

### Follow one actual call, then inspect its business result

This walkthrough reconnects the read-only cache lesson to the same fictional after-sales Agent. It contains a preserved baseline and an integrated copy. Both use the original deterministic teaching model, actual local merchant HTTP and separate SQLite databases. The integrated copy changes the real order-read tool call, not a demonstration helper that the Agent never calls. Its business effect remains a fictional return application; it does not issue a refund.

The guided implementation is supplied so you can inspect a complete transfer. Running it is reference practice. Your own implementation and changed-requirement evidence come from [LEARNER_TASK.md](https://ai.lwkjob.com/lab/project-integration/LEARNER_TASK.md). Read [LEVEL_DELIVERABLES.md](https://ai.lwkjob.com/lab/project-integration/LEVEL_DELIVERABLES.md) for junior, intermediate and senior contributions, and [ASSESSMENT_EXAMPLES.json](https://ai.lwkjob.com/lab/project-integration/ASSESSMENT_EXAMPLES.json) for authored scoring explanations.

### Setup and commands

Use Python 3.10 or newer without third-party packages. Extract the [source package](https://ai.lwkjob.com/downloads/agent-project-integration-v1.zip) into a new ordinary practice directory and run from its root. The program uses loopback HTTP subprocesses and fictional local data; allow local port binding in your environment. No model credentials or Java are required.

```sh
python3 integration_demo.py demo --work work/demo --out work/demo/report.json
python3 -m json.tool work/demo/report.json
python3 integration_demo.py regression --work work/regression --out work/regression/report.json
python3 -m unittest -v test_integration.py
```

Keep the run directory and reports together with your source digests. A report does not certify its own truth; inspect the trace, HTTP records and SQLite state that support each claim. Do not change expected results to make a report green. Repeated guided runs are not independently solved tasks or unseen interview performance.

### Trace the transfer in order

1. **Source origin.** Compare the baseline SOURCE_PROVENANCE.json with the packaged manifest and the original seven-stage project. The baseline is retained for comparison. Record original file digests before changing your own copy.
2. **Actual call site.** Inspect integrated/agent.py and its Agent.read_order path from the real get_order tool. Compare it with baseline/agent.py. The integrated/order_cache.py decision contract is invoked by that path; the output influences the order data actually used by the Agent. A passing standalone cache function alone cannot prove this connection.
3. **Current merchant authority.** The merchant authenticates the session and supplies current tenant/user ownership and versions over local HTTP. Agent or model-supplied identity is not authority. A row in SQLite does not bypass revocation or current ownership checks. Inspect the actual request/response sequence, not only the cache decision label.
4. **Persistent cache.** Inspect the integrated cache row and its tenant, user, order, query, policy/data version and expiry binding. A read result can be reused only under the current authorized contract. Approval, creation, reconciliation and their receipts retain their own boundaries; a write receipt is not an order-read result.
5. **Restart and changed conditions.** The demonstration starts a new Agent process against persisted state. It also changes authority, data or policy while keeping other inputs controlled. Inspect whether a hit used the persisted row, which change caused a miss or denial, and whether forbidden data was returned. A simulated restart flag without a new process is insufficient.
6. **Merchant business receipt.** Follow the main-return task through explicit approval, a deliberately interrupted write response and reconciliation under the original operation key. Cross-check the Agent state with the independently queried merchant ledger. Exactly one application is a business invariant; a successful tool response alone is not a task-success metric.
7. **Original regression.** Compare both branches under the original six labels: ordinary, battery, missing-evidence, other-user, other-tenant and expired-window. Preserve those labels and the source cases. A new cache hit must not weaken policy evidence, approval binding or tenant isolation.

### Turn the walkthrough into personal evidence

First hand-trace one cache hit and one denial. State the expected returned value, state change and merchant effect before running. Then inspect the call-site diff and the failed-before/passed-after records for a personally changed boundary. Implement the independent learner requirement in a fresh copy, retain its specified red baseline and rerun the original regression. Submit the source diff, actual run inputs, reports, trace and an explanation of the first failure. An evaluator then changes one complete requirement and observes your correction.

The independent task introduces an observation-age constraint that the guided integration does not implement. Existing revocation, version and expiry demonstrations are supplied answers; rerunning them is not the independent task. The task's age bound narrows a local observation window and cannot eliminate every cross-request authorization race. The merchant must still recheck current authority at approval and execution.

### What the result can establish

The supplied runs demonstrate a bounded local implementation, real local HTTP, SQLite persistence, process restart, current authorization and fictional merchant effects. They use public authored scenarios and a deterministic teaching model. They do not measure real-model token use or cost, model-selection quality, production throughput, distributed authorization, real students or employer outcomes. The cache still performs current authority work; a hit count does not directly establish a latency gain.

Keep four evidence states separate in the [blank reviewer worksheet](https://ai.lwkjob.com/lab/capstone/ASSESSMENT_TEMPLATE.json): local engineering, real-provider integration, reviewer-observed performance and production responsibility. Unobserved scores and gates remain pending. This walkthrough contributes to the [full career paths](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md); it does not complete the intermediate or senior route.

Publish content/routes through the content API and these sources/ZIP through website assets when authorized. The existing miniapp can show the prose and copy these absolute links without client changes. A local package and validation report do not mean the resources are live.

## 中文

### 跟踪一次真实调用，再查看业务结果

这个示范把订单只读缓存练习接回同一个虚构售后 Agent，提供保留的 baseline 和 integrated 副本。两者沿用原确定性教学生成器，使用真实本机商家 HTTP 和各自的 SQLite 数据库。集成改的是实际订单读取工具调用，不是 Agent 从未调用的示范 helper。业务效果仍是虚构退货申请，不会退款。

引导实现有现成源码，便于查看完整迁移，运行它属于参考练习。本人实现和变需求证据来自 [LEARNER_TASK.md](https://ai.lwkjob.com/lab/project-integration/LEARNER_TASK.md)。初级、中级、资深的专题贡献见 [LEVEL_DELIVERABLES.md](https://ai.lwkjob.com/lab/project-integration/LEVEL_DELIVERABLES.md)，作者编制的评分理由见 [ASSESSMENT_EXAMPLES.json](https://ai.lwkjob.com/lab/project-integration/ASSESSMENT_EXAMPLES.json)。

### 环境与命令

使用 Python 3.10 或更新版本，无第三方依赖。在普通新练习目录解压[源码包](https://ai.lwkjob.com/downloads/agent-project-integration-v1.zip)，从包根运行。程序使用本机回环 HTTP 子进程和虚构数据，环境需允许绑定本机端口，不需要模型凭据或 Java。

```sh
python3 integration_demo.py demo --work work/demo --out work/demo/report.json
python3 -m json.tool work/demo/report.json
python3 integration_demo.py regression --work work/regression --out work/regression/report.json
python3 -m unittest -v test_integration.py
```

将运行目录、报告和源码摘要一起保留。报告不能自行证明真实性；逐项查看支撑主张的轨迹、HTTP 记录和 SQLite 状态，不改预期结果求全绿。重复引导运行不算独立完成的任务，也不算未见面试题表现。

### 按顺序追踪集成

1. **源码来源。** 将 baseline 的 SOURCE_PROVENANCE.json 与包 manifest、原七阶段项目对照。基线保留用于比较；修改本人副本前记录原文件摘要。
2. **实际调用点。** 查看 integrated/agent.py 内真实 get_order 工具进入 Agent.read_order 的路径，对照 baseline/agent.py。该路径调用 integrated/order_cache.py 的决定合同，输出影响 Agent 实际使用的订单数据；缓存纯函数单独通过不能证明已接入。
3. **当前商家权威。** 商家认证 session，通过本机 HTTP 提供当前租户、用户、归属和版本。Agent 或模型自报身份不能授权；SQLite 中有行也不能绕过撤权或当前归属检查。查看实际请求返回顺序，不能只看 hit/deny 标签。
4. **持久化缓存。** 查看缓存行与租户、用户、订单、查询、政策/数据版本及过期时间的绑定；只读结果只在当前授权合同下复用。审批、创建、对账和回执仍有独立边界，写回执不是订单只读结果。
5. **重启与条件变化。** 示范使用持久状态启动新的 Agent 进程，并在其他输入受控时改变权限、数据或政策。检查命中是否实际读到持久行，什么变化触发 miss/deny，是否返回了禁止数据；只设置 restart 标记不算进程重启。
6. **商家业务回执。** 跟踪 main-return：明确审批、故意中断写响应、用原操作键对账。把 Agent 状态与独立读取的商家账本交叉核对；恰好一份申请是业务不变量，工具响应成功本身不是任务成功率。
7. **原基线回归。** 用 ordinary、battery、missing-evidence、other-user、other-tenant、expired-window 原六标签对照两个分支，保留标签和原案例。新增命中不能削弱政策证据、审批绑定和租户隔离。

### 将引导变成本人证据

先手算一次命中和一次拒绝，在执行前写预期返回、状态变化、商家效果。再查看调用点 diff 和本人改变边界后的失败/通过记录。在新副本实现独立任务，保留规定的红基线并回归原项目；提交本人 diff、实际输入、报告、轨迹及首个失败说明。随后由评审改变一项完整需求，观察本人修正。

独立任务新增引导集成尚未实现的观察年龄约束。撤权、版本和失效演示已有答案，重放它们不算独立作业。年龄上限只能缩短本机观察窗口，不能消除所有跨请求鉴权竞态；审批和执行处商家仍须重查当前权限。

### 结果能证明什么

交付运行证明有界本机实现、真实本机 HTTP、SQLite 持久化、进程重启、当前授权和虚构商家效果，使用公开作者场景与确定性教学生成器。它不测真实模型 token/成本、选工具能力、生产吞吐、分布式权限、真实学员或雇主结果。命中仍有当前权限查询，次数不能直接证明延迟改善。

在[空白评审记录](https://ai.lwkjob.com/lab/capstone/ASSESSMENT_TEMPLATE.json)中分开记录本机工程、真实提供方接入、评审观察表现、生产责任；未观察分数和关卡保持 pending。本示范为[完整职责路径](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md)贡献一部分证据，不会完成中级或资深整条路线。

授权发布时，课程路线经内容 API 发布，源码和 ZIP 经网站资源发布。现有小程序可显示正文并复制这些绝对链接，无需改客户端代码；本机打包和验收不代表资源已上线。
