Metadata-Version: 2.4
Name: acps-essay-writing-coach
Version: 1.0.0
Summary: ACPs-orchestrated multi-agent writing studio for high-stakes English prose: an eagle-eyed Critic, a lexical Style editor and a discourse-level Structure architect review IELTS/TOEFL essays, study-abroad statements of purpose and executive emails in parallel over the Agent Interaction Protocol, then merge their findings into one weighted, evidence-linked revision plan with sentence-level corrections, register-aware vocabulary upgrades and a total-introduction-body-conclusion outline.
Author-email: ACPs Essay Coach Engineering <team@acps-essay-coach.dev>
License-Expression: MIT
Project-URL: Homepage, https://github.com/acps-labs/acps-essay-writing-coach
Project-URL: Repository, https://github.com/acps-labs/acps-essay-writing-coach
Project-URL: Documentation, https://github.com/acps-labs/acps-essay-writing-coach#readme
Project-URL: Changelog, https://github.com/acps-labs/acps-essay-writing-coach/releases
Keywords: acps,acps-sdk,multi-agent,agent-collaboration,essay-writing,writing-coach,grammar-checker,style-editor,essay-structure,ielts-writing,toefl-writing,statement-of-purpose,business-email
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: End Users/Desktop
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Education
Classifier: Topic :: Education :: Computer Aided Instruction (CAI)
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: acps-sdk==2.1.0
Requires-Dist: fastapi>=0.110.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic>=2.5.0
Requires-Dist: uvicorn>=0.27.0
Provides-Extra: dev
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: pytest>=8.0.0; extra == "dev"
Dynamic: license-file

# ACPs Essay Writing Coach

**Three editors, one essay, one revision plan.** A production-style, multi-agent
English writing review tool built on [`acps-sdk`](https://pypi.org/project/acps-sdk/) **2.1.0**.

`acps-essay-writing-coach` turns a single essay into three independent,
auditable review reports — grammar/spelling, style/vocabulary, and
logic/structure — and then merges them into one weighted revision plan. The
three reviewers run as real ACPs agents, each exposing its own capability
document (ACS), discovered through ADP and driven through AIP v2 task
lifecycle over JSON-RPC.

---

## Why this exists

High-stakes English writing is rarely a single problem. A statement of purpose
can be grammatically clean yet argumentatively flat; a business email can be
well structured yet full of weak, colloquial vocabulary. Single-prompt
"grammar checkers" collapse these dimensions into one opaque score.

This project separates the editorial board the way a real writing centre does:

| Scenario | What the learner needs | Which agent carries it |
| --- | --- | --- |
| Study-abroad statement of purpose | Precise, formal prose and a coherent personal narrative | Style + Structure |
| CET-4/6, IELTS, TOEFL essay practice | Fast sentence-level correction against a stable rubric | Critic |
| Executive English email | Register control, concise signposting, clear next action | Style + Structure |
| Thesis / research abstract | Thesis clarity, paragraph logic, conclusion strength | Structure |

**Why multi-agent instead of one prompt?**

- **Separation of concerns** — each agent owns one rubric and cannot drown out the others.
- **Parallel latency** — the Leader dispatches three AIP tasks concurrently.
- **Auditability** — every dimension has its own score, issues and evidence.
- **Replaceability** — swap the deterministic engine for an LLM per agent without touching the ACPs wiring.

---

## Architecture

```
                        ADP discovery: filter skills.tags
 ┌──────────────────────────────────────────────────────────────────────┐
 │                     Leader  (EssayCoachSession)                      │
 │  AIC 1.2.156.3088.1.1.34C2.478BDF.00000L.0SEN                        │
 └───────┬──────────────────────┬───────────────────────┬───────────────┘
         │ AIP start (parallel) │ AIP start (parallel)  │ AIP start (parallel)
         ▼                      ▼                       ▼
 ┌───────────────┐      ┌───────────────┐       ┌──────────────────┐
 │  CriticAgent  │      │  StyleAgent   │       │  StructureAgent  │
 │  …000001.0SEN │      │  …000002.0SEN │       │  …000003.0SEN    │
 │ grammar       │      │ vocabulary    │       │ thesis / flow    │
 │ spelling      │      │ register      │       │ paragraph roles  │
 │ punctuation   │      │ sentence vary │       │ outline          │
 └───────┬───────┘      └───────┬───────┘       └────────┬─────────┘
         │ AIP product          │ AIP product            │ AIP product
         └──────────────────────┴───────────┬────────────┘
                                            ▼
                              weighted synthesis 40 / 30 / 30
                                            ▼
                                  CoachingReport (one plan)
```

Each agent is a FastAPI/uvicorn service on loopback exposing `POST /aip/v2/rpc`.
The default **mesh** (`LocalAgentMesh`) starts all three in background threads,
publishes their ACS into an in-process ADP registry, and lets the Leader
discover them by skill tag — exactly the same path a remote deployment would use.

### AIP task lifecycle

```
start ──► awaiting-completion ──► complete
  │               │
  └── product ────┘   (grammar/style/structure report as StructuredDataItem)
```

The Leader runs `start` on all three agents with `asyncio.gather`, validates
every product, then issues `complete` for all three. The resulting task IDs and
final states are embedded in `CoachingReport.collaboration`.

---

## Agent roles

| Agent | Skill ID | Input | Output |
| --- | --- | --- | --- |
| **CriticAgent** | `essay-coach.critic` | Full `EssaySubmission` | Corrected essay, per-sentence issues with category/severity, grammar score |
| **StyleAgent** | `essay-coach.style` | Full `EssaySubmission` | Type-token ratio, sentence rhythm, weak-word/cliché/repetition upgrades, style score |
| **StructureAgent** | `essay-coach.structure` | Full `EssaySubmission` | Paragraph roles, thesis statement, conclusion detection, transition coverage, genre outline, structure score |

The Leader applies fixed weights — **Critic 40% / Style 30% / Structure 30%** —
and emits a prioritised action list, a revised opening, and three next steps.

---

## Install

```bash
python -m pip install acps-essay-writing-coach
```

For local development from this repository:

```bash
python -m pip install -e ".[dev]"
```

> No API key, network model, or external service is required. The bundled
> engine is deterministic, so the demo and tests produce reproducible output.

---

## One-command demo

```bash
essay-coach demo
```

or, without relying on the console script:

```bash
python -m essay_coach demo
```

Review your own essay:

```bash
essay-coach review --file examples/sample_essay.txt \
  --title "Should Universities Require Students to Study Abroad?" \
  --genre ielts-task-2 --band "IELTS 6.5" --words 250
```

Paste an essay interactively (finish with a line containing `END`):

```bash
essay-coach practice --genre statement-of-purpose --band "CEFR C1" --words 800
```

Supported genres: `ielts-task-2`, `toefl-independent`, `statement-of-purpose`,
`business-email`. Use `--variant en-GB|en-US` for spelling convention.

---

## Expected output (real run)

The built-in sample deliberately contains 12 sentence-level issues, several
weak words/clichés, and two malformed signposts. The three agents report
independently, then the Leader merges them:

```text
==============================================================================
 ACPs Essay Writing Coach v1.0.0 · AIP v2 多智能体协作演示
 作文: Should Universities Require Students to Study Abroad? | 体裁: ielts-task-2 | 目标: IELTS 6.5 | 字数: 242/250
==============================================================================
[ADP] 通过发现协议解析到以下 ACPs 智能体:
  1. CriticAgent     skill=essay-coach.critic
     aic=1.2.156.3088.1.1.34C2.478BDF.000001.0SEN
  2. StyleAgent      skill=essay-coach.style
     aic=1.2.156.3088.1.1.34C2.478BDF.000002.0SEN
  3. StructureAgent  skill=essay-coach.structure
     aic=1.2.156.3088.1.1.34C2.478BDF.000003.0SEN
[Leader] 正在通过 AIP v2 并发派发 3 个批改任务（Critic / Style / Structure）...

[CriticAgent] 语法与拼写纠错 · 得分 61/100 · 14 句 / 242 词 · 12 处问题（4.96/100 词）
  #1  S1  [MAJOR · 主谓一致] "people is"  ->  "people are"
  #5  S4  [MAJOR · 主谓一致] "studying abroad give"  ->  "studying abroad gives"
  #9  S8  [MODERATE · 介词搭配] "In the other hand"  ->  "On the other hand"
  #12 S14 [MODERATE · 拼写] "recieve"  ->  "receive"

[StyleAgent] 文风与词汇润色 · 得分 42/100
  词汇多样性(TTR): 0.80 | 平均句长: 17.3 词 | 从句比例: 29%
  高频重复词: students ×6、abroad ×5、people ×3、exchange ×3
  1. [弱词替换] "very"  ->  markedly / notably / considerably
  5. [陈词套话] "with the development of society"  ->  In an increasingly interconnected world

[StructureAgent] 逻辑与结构指导 · 得分 88/100 · 4 段 · 衔接覆盖率 100%
  论点句: In my opinion, I think a short overseas exchange is beneficial, ...
  段落诊断: P2/P3 衔接词形式有误（on one hand / in the other hand）

==============================================================================
 Leader 汇总报告 · 三维加权批改
==============================================================================
  Overall Score: 63.4/100
  - 语法与拼写 (Critic)              61/100 × 权重 40%
  - 文风与词汇 (Style)               42/100 × 权重 30%
  - 逻辑与结构 (Structure)           88/100 × 权重 30%

优先修改动作:
  1. [Critic] 修正第 1 句的主谓一致问题："people is" -> "people are"
  2. [Critic] 修正第 3 句的主谓一致问题："flexibility matter" -> "flexibility matters"
  3. [Style] 替换弱词："very" -> "markedly"
  4. [Structure] 按提纲逐段检查 topic sentence

AIP v2 协作轨迹:
  - CriticAgent    task=task-…  skill=essay-coach.critic     final=completed
  - StyleAgent     task=task-…  skill=essay-coach.style      final=completed
  - StructureAgent task=task-…  skill=essay-coach.structure  final=completed
```

The full report additionally prints the corrected essay, every upgrade with an
example sentence, paragraph-by-paragraph diagnostics, the genre-specific
outline, and the revised opening.

---

## Project structure

```text
acps-essay-writing-coach/
├── pyproject.toml                 # PEP 621 metadata, version 1.0.0, console script
├── README.md
├── LICENSE                        # MIT
├── .gitignore
├── examples/
│   └── sample_essay.txt           # essay used by `essay-coach review --file`
├── src/
│   └── essay_coach/
│       ├── __init__.py
│       ├── __main__.py            # python -m essay_coach
│       ├── py.typed               # PEP 561 marker
│       ├── models.py              # pydantic payloads / report schemas
│       ├── engine.py              # deterministic editorial engine (3 rubrics)
│       ├── identity.py            # AIC + ACS construction
│       ├── registry.py            # in-process ADP discovery service
│       ├── runtime.py             # AIP RPC server + payload codecs
│       ├── leader.py              # parallel task orchestration + synthesis
│       ├── mesh.py                # starts the three agents on loopback
│       ├── cli.py                 # essay-coach demo / review / practice
│       ├── demo.py                # scripted end-to-end demonstration
│       └── agents/
│           ├── __init__.py
│           ├── base.py            # AIP lifecycle base class
│           ├── critic.py          # CriticAgent
│           ├── style.py           # StyleAgent
│           └── structure.py       # StructureAgent
├── tests/
│   └── test_end_to_end.py         # discovery + full AIP review + engine checks
└── dist/                          # generated by `python -m build`
```

---

## Build the wheel

```bash
python -m pip install --upgrade build twine
python -m build --wheel
python -m twine check dist/*
```

Expected artefact:

```text
dist/acps_essay_writing_coach-1.0.0-py3-none-any.whl
```

Verify the built artefact in a clean environment:

```bash
python -m pip install --force-reinstall dist/acps_essay_writing_coach-1.0.0-py3-none-any.whl
essay-coach --version
essay-coach demo
```

To build both sdist and wheel:

```bash
python -m build
```

---

## Publish to PyPI

Always validate on TestPyPI first:

```bash
python -m twine upload --repository testpypi dist/*
python -m pip install --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ acps-essay-writing-coach
```

Then publish to production:

```bash
python -m twine upload dist/*
```

Authenticate with a PyPI API token (recommended) rather than a password:

```powershell
# PowerShell
$env:TWINE_USERNAME = "__token__"
$env:TWINE_PASSWORD = "pypi-XXXXXXXXXXXXXXXXXXXXXXXX"
python -m twine upload dist/*
```

```bash
# bash / zsh
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="pypi-XXXXXXXXXXXXXXXXXXXXXXXX"
python -m twine upload dist/*
```

Or configure `~/.pypirc`:

```ini
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-XXXXXXXXXXXXXXXXXXXXXXXX

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-XXXXXXXXXXXXXXXXXXXXXXXX
```

Before every release, bump `version` in `pyproject.toml` (SemVer), rebuild,
and re-run `twine check`.

---

## Run the tests

```bash
python -m pip install -e ".[dev]"
pytest
```

The suite covers:

1. ADP discovery resolves all three agents by skill tag.
2. A full review runs over real AIP RPC and returns three completed task traces.
3. The Critic engine detects the seeded agreement, preposition and spelling errors.

---

## Design notes

- **Protocol-native payloads.** Reports travel as `StructuredDataItem` inside an
  AIP `Product`; no private transport or ad-hoc envelope is introduced.
- **Deterministic by default.** `EssayEngine` contains the editorial knowledge
  (rules, weak-word maps, clichés, transition lists). This keeps the demo,
  tests and wheel reproducible on any machine.
- **LLM-ready seams.** Replace `review_grammar`, `review_style` or
  `review_structure` with LLM-backed implementations; the ACPs discovery,
  task lifecycle and synthesis remain unchanged.
- **Genre-aware rubrics.** Outlines, contraction checks and target band
  language adapt to `WritingGenre` and `LanguageVariant`.

---

## Naming

- **`acps-`** — the project is built on the ACPs protocol family
  (Agent Capability Specification, Agent Discovery Protocol, Agent Identity
  Code, Agent Interaction Protocol) shipped by `acps-sdk`.
- **`essay-writing-coach`** — the product surface: a coach for high-stakes
  English essays and professional writing, not a generic grammar utility.
- Import package: `essay_coach`; console command: `essay-coach`.

---

## License

MIT © 2026 ACPs Essay Coach Engineering.
