Metadata-Version: 2.4
Name: acps-reading-prism
Version: 1.0.0
Summary: ACPs-native multi-agent close-reading studio for advanced English. A Parser Agent dismantles long sentences into clause trees, a Context Agent reconstructs background, stance and context-bound word senses, and a Question Agent designs comprehension items with reasoning paths and distractor diagnosis. The Leader orchestrates all three over AIP v2 and returns one audit-ready reading report for postgraduate exams, IELTS/TOEFL passages and Economist-style journalism.
Author-email: ACPs Reading Prism Engineering <team@acps-reading-prism.dev>
License-Expression: MIT
Project-URL: Homepage, https://github.com/acps-labs/acps-reading-prism
Project-URL: Repository, https://github.com/acps-labs/acps-reading-prism
Project-URL: Documentation, https://github.com/acps-labs/acps-reading-prism#readme
Project-URL: Changelog, https://github.com/acps-labs/acps-reading-prism/releases
Keywords: acps,acps-sdk,multi-agent,agent-collaboration,acp,aip,close-reading,english-reading-comprehension,syntax-analysis,reading-comprehension,ielts,toefl,postgraduate-entrance-exam,economist,education-technology
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.100.0
Requires-Dist: httpx>=0.25.0
Requires-Dist: pydantic>=2.0.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"
Requires-Dist: ruff>=0.6.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Dynamic: license-file

# acps-reading-prism

> A protocol-native multi-agent close-reading studio for advanced English.

**acps-reading-prism 1.0.0** turns a single English passage into an auditable
close-reading report. Three specialist agents — a **Parser Agent**, a
**Context Agent** and a **Question Agent** — collaborate over the ACPs protocol
stack (ACS + ADP + AIP v2, powered by [`acps-sdk==2.1.0`](https://pypi.org/project/acps-sdk/)).
A **Leader** agent plans the workflow, dispatches work in parallel and merges
the structured products into one report.

It is built for the reading load that actually hurts: postgraduate entrance
exams, IELTS/TOEFL passages, and *Economist*-style long-form journalism where a
single sentence can carry four layers of subordination and the author's stance
lives between the lines.

---

## Why "Reading Prism"?

A prism does not add light; it decomposes one beam into its spectrum. This tool
does the same to a passage: one text goes in, and three separable spectra come
out —

* **syntax** (clause tree, main clause, grammatical roles),
* **context** (background knowledge, authorial stance, context-bound senses),
* **logic** (item design, evidence location, distractor diagnosis).

The Leader then recombines them into one reading report. Hence: **ACPs Reading
Prism**.

## Why multiple agents instead of one prompt?

| Concern | Single monolithic prompt | Reading Prism mesh |
| --- | --- | --- |
| Long-sentence grammar | diluted by task-switching | a dedicated Parser skill with a clause-level product |
| Cultural background / stance | often hallucinated or omitted | a Context skill with explicit background cards and evidence |
| Question quality | one-shot, hard to audit | a Question skill that consumes the *products* of the other two and cites evidence sentences |
| Failure isolation | one bad span ruins everything | per-task states, AIP task ids, timed traces |

The collaboration is a real fan-out / fan-in, not three prompts glued together:

```
                 ┌────────────────┐
   article ─────▶│  Parser Agent  │──┐
                 └────────────────┘  │   structured ParseReport
                                     ├──▶┌──────────────────┐
                 ┌────────────────┐  │   │  Question Agent  │──▶ QuizReport
   article ─────▶│ Context Agent  │──┘   └──────────────────┘
                 └────────────────┘          ▲
                                     ContextReport
                                                 │
                                     ┌───────────┴───────────┐
                                     │  Leader (orchestrator) │──▶ ReadingReport
                                     └───────────────────────┘
```

Parser and Context run **concurrently** (`asyncio.gather`); Question runs only
after both products arrive, and its payload includes the full ParseReport and
ContextReport. Every hop is an AIP task with its own id, state and latency,
surfaced in the report's collaboration table.

## Agent roster

| Agent | Skill id | Responsibility | Product |
| --- | --- | --- | --- |
| Parser Agent | `prism-sentence-parser` | Long-sentence decomposition: concession / cause / condition / relative / object / comparative / appositive / participle clauses, plus subject–predicate–object–adverbial chunks | `ParseReport` |
| Context Agent | `prism-context-analyst` | Background cards, author stance trajectory, hedging cues, context-bound word senses, collocations, morphology hints | `ContextReport` |
| Question Agent | `prism-question-designer` | Main-idea, detail, vocabulary-in-context, inference and attitude items; evidence sentence + distractor flaw labels | `QuizReport` |
| Leader | `LEADER_AIC` | ADP discovery, parallel dispatch, product validation, report synthesis | `ReadingReport` |

Each partner publishes an **ACS** capability document, is discovered through
**ADP** (`skills.tags` filter), and is driven through the **AIP v2** task
lifecycle (`start` / `continue` / `cancel` / `complete`). Payloads travel as
`TextDataItem` JSON and products as `StructuredDataItem`, so no private wire
format leaks into the protocol layer.

## Install

```bash
python -m venv .venv

# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate

pip install -e ".[dev]"
```

The only runtime dependency that matters is `acps-sdk==2.1.0`; FastAPI, uvicorn,
pydantic and httpx are pulled in for the local AIP services.

## One-click demo

```bash
python run_demo.py
# or, after installation:
reading-prism demo
```

The demo starts three loopback AIP services, runs the built-in
*Economist*-style passage through the full workflow, and prints the report.
Expected opening:

```text
==============================================================================
ACPs Reading Prism v1.0.0 · 多智能体外刊精读
==============================================================================
本地 AIP 网格已启动（每个智能体独立进程内 RPC 服务）：
  · Parser Agent    1.2.156.3088 · vendor 34C2 · instance 000101
    skill=prism-sentence-parser        endpoint=http://127.0.0.1:xxxxx/aip/v2/rpc
  · Context Agent   ... instance 000102
  · Question Agent  ... instance 000103

[Leader] 并行派发 Parser Agent 与 Context Agent；两者返回结构化产物后，
再把产物交给 Question Agent 命题。

阅读报告 · The Remote-Work Remaking of Housing and Hiring · 351 ms
```

Then the Markdown report follows: collaboration trace, per-sentence clause
tables, background cards, author stance, a contextual vocabulary table, five
exam-style questions with distractor diagnosis, and a review checklist.

### Analyse your own passage

```bash
reading-prism analyze --file article.txt --title "The Economist · Leaders"
reading-prism analyze --text "Although ..." --max-questions 4
reading-prism demo --json          # raw ReadingReport JSON
```

### Use it as a library

```python
import asyncio

from reading_prism.leader import ReadingSession
from reading_prism.mesh import LocalAgentMesh
from reading_prism.report import render_markdown

async def main() -> None:
    with LocalAgentMesh() as mesh:
        async with ReadingSession(mesh.registry) as session:
            report = await session.analyze(article, title="Leaders")
    print(render_markdown(report))

asyncio.run(main())
```

## Run the tests

```bash
pytest -q
```

The suite covers clause detection, stance/vocabulary recovery, item grounding,
a full three-agent AIP round-trip, and the generic fallback path.

## Build the wheel

```bash
python -m pip install --upgrade build twine
python -m build
```

Artifacts land in `dist/`:

```text
dist/acps_reading_prism-1.0.0-py3-none-any.whl
dist/acps_reading_prism-1.0.0.tar.gz
```

Validate before uploading:

```bash
twine check dist/*
```

## Publish to PyPI

```bash
# 1) TestPyPI first (recommended)
twine upload --repository testpypi dist/*

# 2) Verify the install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ acps-reading-prism==1.0.0

# 3) Production
twine upload dist/*
```

Credentials can come from `~/.pypirc`, or from the environment:

```bash
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-<your-api-token>
```

## Project layout

```text
acps-reading-prism/
├── pyproject.toml                 # name / version 1.0.0 / build config / entry points
├── README.md
├── LICENSE
├── run_demo.py                    # one-click demo runner (adds src/ to sys.path)
├── src/reading_prism/
│   ├── __init__.py
│   ├── __main__.py                # python -m reading_prism
│   ├── cli.py                     # reading-prism demo | analyze
│   ├── demo.py                    # banner + demo orchestration
│   ├── identity.py                # AIC parsing + ACS capability documents
│   ├── models.py                  # pydantic products exchanged over AIP
│   ├── registry.py                # ADP-style discovery registry
│   ├── runtime.py                 # AIP RPC server, payload codec, result builder
│   ├── mesh.py                    # starts + publishes the three partner agents
│   ├── leader.py                  # ReadingSession: discovery → fan-out → fan-in
│   ├── report.py                  # Markdown report renderer
│   ├── corpus.py                  # demo passage, reference translations, lexicon, topic pack
│   ├── py.typed
│   ├── agents/
│   │   ├── base.py                # AIP lifecycle base class
│   │   ├── parser_agent.py
│   │   ├── context_agent.py
│   │   └── question_agent.py
│   └── engine/
│       ├── text.py                # sentence/word utilities
│       ├── syntax.py              # clause parser + chunker
│       ├── context.py             # background / stance / lexical engine
│       └── questions.py           # item generation + distractor diagnosis
└── tests/test_end_to_end.py
```

## Design notes and honest limits

* **Deterministic core, protocol-first boundary.** The syntax/context/question
  engines are rule-based and run offline. They are deliberately behind agent
  boundaries: you can replace any engine with an LLM-backed implementation
  without touching the AIP orchestration or the report schema.
* **Expert topic pack + generic fallback.** The built-in passage ships with a
  curated background pack and item bank; every item is re-verified against the
  parsed evidence sentence. Passages outside the pack still get a full report,
  but the quiz is labelled as a template draft for human review.
* **Background cards are general knowledge.** The report states this explicitly
  and asks readers to verify figures against the source.
* **No API keys, no network calls** beyond loopback AIP RPC. That makes the demo
  reproducible in CI and safe in a classroom.

## License

MIT. See [LICENSE](LICENSE).
