# 完整课程的独立练习 / Independent exercises for the complete curriculum

## 中文

这22门是同一售后Agent项目的补充练习，课程四层分别训练原理、实现、排错、设计，不对应职级。初级选有明确边界的本人编码任务；中级完成一个未实现需求并保持基线；资深另交容量/迁移/事故/责任取舍。先读[三条职责路径](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md)。

### 安装与一次完整练习

只需Python3.9或更新版本，无第三方依赖，不要求模型API key。解压[完整源码包](https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip)，保持lab_runner.py与cases/相邻。以缓存课为例：

```bash
python3 lab_runner.py scaffold --course agent-cache-correctness --out cache_student.py
python3 lab_runner.py grade --course agent-cache-correctness --module cache_student.py --out cache-report.json
```

scaffold退出0且拒绝覆盖已有文件；首次空模板grade应退出1。按课程正文的函数合约由本人实现后重跑，全部公开检查通过才退出0。cases/<course>.json记录输入、期望JSON或精确错误，不含正确解。源码、案例和学员模块SHA及Python版本写入报告。

每课只调用声明的function(payload)。输入/输出必须为JSON基本类型；整数不接受bool，输入不得修改，输出不能包含输入dict/list别名。导入失败、提前退出、超时、错题返回包均失败。5秒只防卡死，不是性能门槛。

报告通过仅证明公开固定本地合约。评分器执行可信学员源码，不能隔离恶意代码；请使用虚构数据、普通本机练习目录。公开案例可被背答案，所以本人掌握还需要新增反例、现场修改和评审。每份报告按原理→实现→排错→设计保存：手算关键分支、空模板红基线、本人代码/协助说明、原错误与真实源码修复、相同输入回归、至少一个作者未列出的新条件、ADR与项目迁移记录。不能将复制作者代码、打印passed或改期望结果算作独立实现。

### 把SQL计划实际执行一次

SQL课先按同样流程实现compile_query并生成当前通过的sql-report.json，再执行：

```bash
python3 sqlite_probe.py --report sql-report.json --out sqlite-report.json
```

探针在虚构本机SQLite中执行三条已分级检查的实际SQL/params，独立按台账计算整数cents。单账户、双账户、带引号的账户ID分别应为450、1150、250；不同租户、币种和窗口外记录不得混入。query_only及authorizer还拒绝DELETE。它不证明生产数据库角色/RLS和负载能力，报告也不是防篡改凭证。LIMIT只限制汇总输出行数，不能限制SUM扫描的原始行数；扫描成本须另外测量。

### 回到七阶段售后项目

下列是练习与项目边界的映射，同一专题可能影响多个阶段。纯函数并未自动接入项目，必须另外提交本人项目diff、原基线和新条件的端到端记录。

1. 任务与模型边界：framework-selection、graph-vs-agent-loop、multi-agent-worth-cost。比较约束、控制轨迹和同一来源的证据；不能把多份相同输出当独立验证。
2. 工具合同：tool-catalog-routing、tool-result-artifacts、text-to-sql-guardrails、coding-sandbox-boundary、java-coding-agent-design。实现路由/结果/边界决定，分别补实际数据库权限、隔离环境和本人Java构建/测试；Python决定器不能替代这些系统。
3. 检索与证据：rag-query-rewrite、indirect-prompt-injection、research-report-evidence。保留实体/否定/范围、权限与原文版本；策略夹具不能证明模型抵抗攻击或语义证据正确。
4. 状态与记忆：agent-state-reducers、memory-conflict-time、memory-retrieval-budget、agent-cache-correctness。处理重放、冲突、生效时间、预算与当前权限；按业务字段定义合并语义。
5. 审批与责任转移：agent-handoff-contract、customer-service-action-design、enterprise-agent-design。把当前授权、审批绑定、回执与组件所有权接回main-return，设计不同于已完成的生产集成。
6. 恢复与补偿：agent-streaming-resume、mcp-transport-reconnect、agent-saga-compensation。按原操作身份对账未知写，回放断流/重连/已知效果补偿；JSON状态决定不等于真实网络或分布式事务。
7. 评测与发布：harness-contract并复查前六阶段的独立账本、实际上下文、输入/模块版本及事故时间线。成功分母按任务，未知结果不算成功；打分建议、固定检查和真正生产责任分开。

先查看对应课程正文和cases文件，再实现函数。基础正确后改变权限、版本、重复/乱序、缺失结果或预算中的一项，保留其他条件不变，说明首个失败点及为什么修复有效。初/中/资深使用不同产物和职责门；22课全跑绿也不能自动授予职级。本地工程、真实provider接入、评审观察、生产责任各自记录，真实经验和岗位语言/年限要求按目标JD核验。

### 发布与证据

源码包只含README、runner、package、SQLite探针、22份公开案例和manifest；不含私有正确解、学员报告、数据库、环境文件或凭据。课程和路线通过内容API发布，源码及ZIP作为网站资源同步发布。现有小程序通过正文与复制链接取得练习，无需改客户端代码；本地校验不代表内容已上线。

## English

These 22 exercises extend the same after-sales Agent project. The four lesson tracks train principles, implementation, diagnosis and design; they are not job ranks. Junior work includes personally implemented bounded code; mid-level work independently changes an unimplemented requirement while preserving baseline behavior; senior work adds capacity, migration, incident and ownership decisions. Read the [three responsibility paths](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md) first.

### Setup and one complete exercise

Use Python3.9 or newer, without third-party packages or a model API key. Extract the [complete source package](https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip), keeping lab_runner.py next to cases/. For the cache lesson:

```bash
python3 lab_runner.py scaffold --course agent-cache-correctness --out cache_student.py
python3 lab_runner.py grade --course agent-cache-correctness --module cache_student.py --out cache-report.json
```

Scaffold exits0 and refuses to overwrite a file. The empty template grade should exit1. Implement the declared lesson contract yourself, then rerun; all public checks must pass for exit0. cases/<course>.json contains inputs and expected JSON or exact errors, without a correct solution. Reports include runner, cases and learner-module SHA values and Python version.

Each lesson calls only its declared function(payload). Inputs/outputs must be JSON primitives and containers; bool is not an integer, input cannot change and output cannot alias input dict/list containers. Failed imports, premature exits, hang timeouts and wrong-case packets fail. Five seconds is a hang guard, not a performance criterion.

A green report proves only the public fixed local contract. The runner executes trusted learner source and does not isolate malicious code; use fictional data in an ordinary local practice directory. Public answers can be memorized, so mastery requires new counterexamples, live changes and review. Preserve the progression: manual branch decisions, empty-template red baseline, personal code and assistance disclosure, original fault and actual source repair, same-input regression, at least one condition the author did not list, ADR and project transfer records. Copying author code, printing passed or changing expectations is not independent implementation.

### Execute the SQL plans once

Implement compile_query and produce a current passing sql-report.json through the same lesson workflow, then run:

```bash
python3 sqlite_probe.py --report sql-report.json --out sqlite-report.json
```

The probe executes three graded SQL/params plans in fictional local SQLite and independently sums integer cents from the ledger. Single-account, two-account and quoted-ID results must be450,1150,250; other tenants, currencies and out-of-window rows are excluded. query_only and an authorizer also reject DELETE. This does not establish production database roles/RLS or load capacity; reports are not tamper-proof credentials. LIMIT restricts aggregate output rows, not the input rows scanned by SUM; measure scan cost separately.

### Return to the seven-stage after-sales project

This mapping connects exercise contracts with project boundaries; a topic can affect several stages. A pure function is not automatically integrated into the project. Submit your own project diff, old baseline and end-to-end changed-condition records separately.

1. Task/model boundary: framework-selection, graph-vs-agent-loop, multi-agent-worth-cost. Compare constraints, control traces and evidence origins; repeated copies are not independent verification.
2. Tool contracts: tool-catalog-routing, tool-result-artifacts, text-to-sql-guardrails, coding-sandbox-boundary, java-coding-agent-design. Implement routing/result/boundary decisions, then separately demonstrate real database permissions, isolation and personal Java build/tests. Python decision code cannot replace those systems.
3. Retrieval/evidence: rag-query-rewrite, indirect-prompt-injection, research-report-evidence. Preserve entities, negation, scope, authority and source versions; policy fixtures cannot establish model attack resistance or semantic evidence correctness.
4. State/memory: agent-state-reducers, memory-conflict-time, memory-retrieval-budget, agent-cache-correctness. Handle replay, conflict, effective time, budgets and current authority with field-specific business semantics.
5. Approval/ownership transfer: agent-handoff-contract, customer-service-action-design, enterprise-agent-design. Reconnect current authorization, approval binding, receipts and component ownership to main-return; a design is distinct from completed production integration.
6. Recovery/compensation: agent-streaming-resume, mcp-transport-reconnect, agent-saga-compensation. Reconcile unknown writes under their original identity and replay stream loss, reconnection and known-effect compensation; JSON decisions are not a real network or distributed transaction.
7. Evaluation/release: harness-contract and independent ledger, actual context, input/module versions and incident timelines from the preceding stages. Use task-level denominators and do not count unknowns as successes. Suggested scores, fixed checks and production responsibility remain separate.

Read the lesson body and cases, then implement its function. Change one permission, version, replay/order, missing result or budget condition while keeping the rest fixed. Explain the first failure and why the patch works. Junior/mid-level/senior use different artifacts and responsibility gates; green results across all22 courses do not confer a job rank. Record local engineering, real-provider integration, reviewer observation and production ownership separately. Verify language, tenure and actual experience requirements against the targetJD.

### Publication and evidence

The source-only package includes README, runner, package, SQLite probe, 22 public case files and manifest. It excludes private solutions, learner reports, databases, environment files and credentials. Publish lessons/routes via the contentAPI and source/ZIP via website assets. The existing miniapp retrieves instructions and copyable links without client changes; local validation does not mean publication happened.
