acps-grammar-tree 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- acps_grammar_tree-1.0.0/PKG-INFO +35 -0
- acps_grammar_tree-1.0.0/pyproject.toml +72 -0
- acps_grammar_tree-1.0.0/setup.cfg +4 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/PKG-INFO +35 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/SOURCES.txt +26 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/dependency_links.txt +1 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/entry_points.txt +2 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/requires.txt +11 -0
- acps_grammar_tree-1.0.0/src/acps_grammar_tree.egg-info/top_level.txt +1 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/__init__.py +8 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/__main__.py +6 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/agents/__init__.py +7 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/agents/base.py +117 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/agents/error_tracer.py +48 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/agents/exercise.py +45 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/agents/syntax.py +48 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/cli.py +43 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/demo.py +40 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/identity.py +76 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/mesh.py +55 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/models.py +129 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/orchestrator.py +196 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/py.typed +0 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/registry.py +85 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/report.py +98 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/rules.py +841 -0
- acps_grammar_tree-1.0.0/src/grammar_tree/runtime.py +228 -0
- acps_grammar_tree-1.0.0/tests/test_workflow.py +107 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: acps-grammar-tree
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Protocol-native English grammar diagnostics for systematic gap analysis and Chinglish correction. Syntax, Error Tracer and Exercise agents collaborate over acps-sdk AIP v2 to turn sentence trees into rule-level blind-spot analysis and targeted practice.
|
|
5
|
+
Author: ACPs Grammar Tree Engineering
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/acps-grammar-tree/
|
|
8
|
+
Keywords: acps-sdk,multi-agent,english-grammar,syntax-tree,chinglish,adaptive-learning
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Education
|
|
20
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/plain
|
|
24
|
+
Requires-Dist: acps-sdk==2.1.0
|
|
25
|
+
Requires-Dist: fastapi>=0.100.0
|
|
26
|
+
Requires-Dist: httpx>=0.25.0
|
|
27
|
+
Requires-Dist: pydantic>=2.0.0
|
|
28
|
+
Requires-Dist: uvicorn>=0.27.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
33
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
34
|
+
|
|
35
|
+
ACPs Grammar Tree is a protocol-native diagnostic workflow for learners and educators addressing recurring English grammar gaps and Chinglish transfer. Three auditable AIP v2 specialists connect constituency-tree visualization, rule-level error provenance and 3-5 targeted exercises. It supports systematic remediation rather than opaque sentence scoring, with typed products, ADP skill discovery and a reproducible local demo.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "acps-grammar-tree"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Protocol-native English grammar diagnostics for systematic gap analysis and Chinglish correction. Syntax, Error Tracer and Exercise agents collaborate over acps-sdk AIP v2 to turn sentence trees into rule-level blind-spot analysis and targeted practice."
|
|
9
|
+
readme = {text = "ACPs Grammar Tree is a protocol-native diagnostic workflow for learners and educators addressing recurring English grammar gaps and Chinglish transfer. Three auditable AIP v2 specialists connect constituency-tree visualization, rule-level error provenance and 3-5 targeted exercises. It supports systematic remediation rather than opaque sentence scoring, with typed products, ADP skill discovery and a reproducible local demo.", content-type = "text/plain"}
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "ACPs Grammar Tree Engineering" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"acps-sdk",
|
|
15
|
+
"multi-agent",
|
|
16
|
+
"english-grammar",
|
|
17
|
+
"syntax-tree",
|
|
18
|
+
"chinglish",
|
|
19
|
+
"adaptive-learning",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 5 - Production/Stable",
|
|
23
|
+
"Intended Audience :: Education",
|
|
24
|
+
"Natural Language :: English",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Education",
|
|
33
|
+
"Topic :: Text Processing :: Linguistic",
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
]
|
|
36
|
+
dependencies = [
|
|
37
|
+
"acps-sdk==2.1.0",
|
|
38
|
+
"fastapi>=0.100.0",
|
|
39
|
+
"httpx>=0.25.0",
|
|
40
|
+
"pydantic>=2.0.0",
|
|
41
|
+
"uvicorn>=0.27.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
dev = [
|
|
46
|
+
"build>=1.0.0",
|
|
47
|
+
"pytest>=8.0.0",
|
|
48
|
+
"ruff>=0.6.0",
|
|
49
|
+
"twine>=5.0.0",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.scripts]
|
|
53
|
+
grammar-tree = "grammar_tree.cli:main"
|
|
54
|
+
|
|
55
|
+
[project.urls]
|
|
56
|
+
Homepage = "https://pypi.org/project/acps-grammar-tree/"
|
|
57
|
+
|
|
58
|
+
[tool.setuptools.packages.find]
|
|
59
|
+
where = ["src"]
|
|
60
|
+
|
|
61
|
+
[tool.setuptools.package-data]
|
|
62
|
+
grammar_tree = ["py.typed"]
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
testpaths = ["tests"]
|
|
66
|
+
addopts = "-q"
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 100
|
|
70
|
+
|
|
71
|
+
[tool.ruff.lint]
|
|
72
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: acps-grammar-tree
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Protocol-native English grammar diagnostics for systematic gap analysis and Chinglish correction. Syntax, Error Tracer and Exercise agents collaborate over acps-sdk AIP v2 to turn sentence trees into rule-level blind-spot analysis and targeted practice.
|
|
5
|
+
Author: ACPs Grammar Tree Engineering
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/acps-grammar-tree/
|
|
8
|
+
Keywords: acps-sdk,multi-agent,english-grammar,syntax-tree,chinglish,adaptive-learning
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Education
|
|
20
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/plain
|
|
24
|
+
Requires-Dist: acps-sdk==2.1.0
|
|
25
|
+
Requires-Dist: fastapi>=0.100.0
|
|
26
|
+
Requires-Dist: httpx>=0.25.0
|
|
27
|
+
Requires-Dist: pydantic>=2.0.0
|
|
28
|
+
Requires-Dist: uvicorn>=0.27.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
33
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
34
|
+
|
|
35
|
+
ACPs Grammar Tree is a protocol-native diagnostic workflow for learners and educators addressing recurring English grammar gaps and Chinglish transfer. Three auditable AIP v2 specialists connect constituency-tree visualization, rule-level error provenance and 3-5 targeted exercises. It supports systematic remediation rather than opaque sentence scoring, with typed products, ADP skill discovery and a reproducible local demo.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
src/acps_grammar_tree.egg-info/PKG-INFO
|
|
3
|
+
src/acps_grammar_tree.egg-info/SOURCES.txt
|
|
4
|
+
src/acps_grammar_tree.egg-info/dependency_links.txt
|
|
5
|
+
src/acps_grammar_tree.egg-info/entry_points.txt
|
|
6
|
+
src/acps_grammar_tree.egg-info/requires.txt
|
|
7
|
+
src/acps_grammar_tree.egg-info/top_level.txt
|
|
8
|
+
src/grammar_tree/__init__.py
|
|
9
|
+
src/grammar_tree/__main__.py
|
|
10
|
+
src/grammar_tree/cli.py
|
|
11
|
+
src/grammar_tree/demo.py
|
|
12
|
+
src/grammar_tree/identity.py
|
|
13
|
+
src/grammar_tree/mesh.py
|
|
14
|
+
src/grammar_tree/models.py
|
|
15
|
+
src/grammar_tree/orchestrator.py
|
|
16
|
+
src/grammar_tree/py.typed
|
|
17
|
+
src/grammar_tree/registry.py
|
|
18
|
+
src/grammar_tree/report.py
|
|
19
|
+
src/grammar_tree/rules.py
|
|
20
|
+
src/grammar_tree/runtime.py
|
|
21
|
+
src/grammar_tree/agents/__init__.py
|
|
22
|
+
src/grammar_tree/agents/base.py
|
|
23
|
+
src/grammar_tree/agents/error_tracer.py
|
|
24
|
+
src/grammar_tree/agents/exercise.py
|
|
25
|
+
src/grammar_tree/agents/syntax.py
|
|
26
|
+
tests/test_workflow.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
grammar_tree
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Base class for independently hosted AIP grammar specialists."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from typing import ClassVar
|
|
7
|
+
|
|
8
|
+
from acps_sdk.acs import AgentCapabilitySpec, AgentSkill
|
|
9
|
+
from acps_sdk.aip import TaskCommand, TaskResult, TaskState
|
|
10
|
+
from acps_sdk.aip.aip_rpc_server import CommandHandlers, DefaultHandlers, TaskManager
|
|
11
|
+
|
|
12
|
+
from ..identity import PROJECT_VERSION, build_capability_spec
|
|
13
|
+
from ..runtime import TERMINAL_STATES, ResultBuilder
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AipAgent(ABC):
|
|
17
|
+
"""One specialist exposing a single discoverable ACPs skill."""
|
|
18
|
+
|
|
19
|
+
name: ClassVar[str]
|
|
20
|
+
description: ClassVar[str]
|
|
21
|
+
skill_id: ClassVar[str]
|
|
22
|
+
skill_name: ClassVar[str]
|
|
23
|
+
skill_description: ClassVar[str]
|
|
24
|
+
tags: ClassVar[tuple[str, ...]]
|
|
25
|
+
examples: ClassVar[tuple[str, ...]] = ()
|
|
26
|
+
product_name: ClassVar[str]
|
|
27
|
+
|
|
28
|
+
def __init__(self, aic: str) -> None:
|
|
29
|
+
self.aic = aic
|
|
30
|
+
self.endpoint_url: str | None = None
|
|
31
|
+
self._result = ResultBuilder(aic)
|
|
32
|
+
|
|
33
|
+
def attach_endpoint(self, endpoint_url: str) -> None:
|
|
34
|
+
self.endpoint_url = endpoint_url
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def capability_spec(self) -> AgentCapabilitySpec:
|
|
38
|
+
if self.endpoint_url is None:
|
|
39
|
+
raise RuntimeError(f"{self.name} has no endpoint; start its server first")
|
|
40
|
+
skill = AgentSkill(
|
|
41
|
+
id=self.skill_id,
|
|
42
|
+
name=self.skill_name,
|
|
43
|
+
description=self.skill_description,
|
|
44
|
+
version=PROJECT_VERSION,
|
|
45
|
+
tags=list(self.tags),
|
|
46
|
+
examples=list(self.examples) or None,
|
|
47
|
+
input_modes=["text/plain", "application/json"],
|
|
48
|
+
output_modes=["application/json"],
|
|
49
|
+
)
|
|
50
|
+
return build_capability_spec(
|
|
51
|
+
aic=self.aic,
|
|
52
|
+
name=self.name,
|
|
53
|
+
description=self.description,
|
|
54
|
+
skill=skill,
|
|
55
|
+
endpoint_url=self.endpoint_url,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def build_handlers(self) -> CommandHandlers:
|
|
59
|
+
return CommandHandlers(
|
|
60
|
+
on_start=self._on_start,
|
|
61
|
+
on_continue=self._on_continue,
|
|
62
|
+
on_cancel=self._on_cancel,
|
|
63
|
+
on_complete=self._on_complete,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
async def _on_start(
|
|
67
|
+
self,
|
|
68
|
+
command: TaskCommand,
|
|
69
|
+
task: TaskResult | None,
|
|
70
|
+
) -> TaskResult:
|
|
71
|
+
if task is not None:
|
|
72
|
+
return task
|
|
73
|
+
created = TaskManager.create_task(command)
|
|
74
|
+
created.senderId = self.aic
|
|
75
|
+
if command.sessionId:
|
|
76
|
+
created.sessionId = command.sessionId
|
|
77
|
+
return self.handle_start(command, created)
|
|
78
|
+
|
|
79
|
+
async def _on_continue(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
80
|
+
if task.status.state in TERMINAL_STATES:
|
|
81
|
+
return task
|
|
82
|
+
return self.fail(task, f"{self.name} does not accept continue commands")
|
|
83
|
+
|
|
84
|
+
async def _on_cancel(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
85
|
+
result = await DefaultHandlers.cancel(command, task)
|
|
86
|
+
result.senderId = self.aic
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
async def _on_complete(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
90
|
+
result = await DefaultHandlers.complete(command, task)
|
|
91
|
+
result.senderId = self.aic
|
|
92
|
+
return result
|
|
93
|
+
|
|
94
|
+
@abstractmethod
|
|
95
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
96
|
+
"""Consume an AIP start command and return its terminal result."""
|
|
97
|
+
|
|
98
|
+
def publish(
|
|
99
|
+
self,
|
|
100
|
+
task: TaskResult,
|
|
101
|
+
payload: dict[str, object],
|
|
102
|
+
*,
|
|
103
|
+
summary: str,
|
|
104
|
+
) -> TaskResult:
|
|
105
|
+
return self._result.publish(
|
|
106
|
+
task,
|
|
107
|
+
TaskState.Completed,
|
|
108
|
+
payload,
|
|
109
|
+
product_name=self.product_name,
|
|
110
|
+
summary=summary,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def fail(self, task: TaskResult, message: str) -> TaskResult:
|
|
114
|
+
return self._result.fail(task, message)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
__all__ = ["AipAgent"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Error Tracer Agent: map surface errors to grammar-rule blind spots."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..models import ErrorTraceRequest
|
|
9
|
+
from ..rules import trace_errors
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ErrorTracerAgent(AipAgent):
|
|
15
|
+
name = "Error Tracer Agent"
|
|
16
|
+
description = (
|
|
17
|
+
"Consumes the Syntax Agent's tree and links each detected error to evidence, "
|
|
18
|
+
"a rule-level blind spot, a correction and a confidence score."
|
|
19
|
+
)
|
|
20
|
+
skill_id = "error-trace"
|
|
21
|
+
skill_name = "Chinglish error tracing and rule-gap diagnosis"
|
|
22
|
+
skill_description = (
|
|
23
|
+
"Explains not only what is wrong but why the error occurs, with special "
|
|
24
|
+
"coverage of clause linking, non-finite verbs and verb complementation."
|
|
25
|
+
)
|
|
26
|
+
tags = ("error-trace", "chinglish", "grammar-rules")
|
|
27
|
+
examples = (
|
|
28
|
+
"Trace 'Although ..., but ...' to connector overload.",
|
|
29
|
+
"Explain why look forward to requires a gerund.",
|
|
30
|
+
)
|
|
31
|
+
product_name = "error-trace-report"
|
|
32
|
+
|
|
33
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
34
|
+
try:
|
|
35
|
+
request = ErrorTraceRequest.model_validate(
|
|
36
|
+
decode_payload(first_text(command))
|
|
37
|
+
)
|
|
38
|
+
report = trace_errors(request)
|
|
39
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
40
|
+
return self.fail(task, f"Error Tracer Agent rejected the payload: {exc}")
|
|
41
|
+
summary = (
|
|
42
|
+
f"定位 {len(report.issues)} 处错误;"
|
|
43
|
+
f"学习焦点:{';'.join(report.learning_focus)}"
|
|
44
|
+
)
|
|
45
|
+
return self.publish(task, report.model_dump(mode="json"), summary=summary)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
__all__ = ["ErrorTracerAgent"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Exercise Agent: generate rule-aligned practice from the diagnosis product."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..models import ExerciseRequest
|
|
9
|
+
from ..rules import generate_exercises
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ExerciseAgent(AipAgent):
|
|
15
|
+
name = "Exercise Agent"
|
|
16
|
+
description = (
|
|
17
|
+
"Transforms the Error Tracer's validated blind spot into three to five "
|
|
18
|
+
"multiple-choice, correction, rewrite and translation drills with answer keys."
|
|
19
|
+
)
|
|
20
|
+
skill_id = "targeted-exercises"
|
|
21
|
+
skill_name = "Blind-spot-aligned grammar practice"
|
|
22
|
+
skill_description = (
|
|
23
|
+
"Consumes an error-trace report and generates focused exercises whose answer "
|
|
24
|
+
"explanations reinforce the same diagnosed grammar rule."
|
|
25
|
+
)
|
|
26
|
+
tags = ("targeted-exercises", "adaptive-practice", "grammar-remediation")
|
|
27
|
+
examples = (
|
|
28
|
+
"Create four connector drills for an Although/but diagnosis.",
|
|
29
|
+
"Generate gerund practice after diagnosing look forward to hear.",
|
|
30
|
+
)
|
|
31
|
+
product_name = "exercise-report"
|
|
32
|
+
|
|
33
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
34
|
+
try:
|
|
35
|
+
request = ExerciseRequest.model_validate(
|
|
36
|
+
decode_payload(first_text(command))
|
|
37
|
+
)
|
|
38
|
+
report = generate_exercises(request)
|
|
39
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
40
|
+
return self.fail(task, f"Exercise Agent rejected the payload: {exc}")
|
|
41
|
+
summary = f"围绕“{report.focus}”生成 {len(report.exercises)} 道专项练习"
|
|
42
|
+
return self.publish(task, report.model_dump(mode="json"), summary=summary)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
__all__ = ["ExerciseAgent"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Syntax Agent: constituency-tree projection and clause-role annotation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..models import DiagnosticRequest
|
|
9
|
+
from ..rules import analyze_syntax
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SyntaxAgent(AipAgent):
|
|
15
|
+
name = "Syntax Agent"
|
|
16
|
+
description = (
|
|
17
|
+
"Builds an inspectable constituency tree with subject, predicate, finite "
|
|
18
|
+
"verb, subordinate clause and non-finite phrase annotations."
|
|
19
|
+
)
|
|
20
|
+
skill_id = "syntax-tree"
|
|
21
|
+
skill_name = "Rule-guided English syntax-tree projection"
|
|
22
|
+
skill_description = (
|
|
23
|
+
"Consumes one English sentence and returns a structured tree plus an ASCII "
|
|
24
|
+
"visualization so downstream diagnosis can reference explicit clause structure."
|
|
25
|
+
)
|
|
26
|
+
tags = ("syntax-tree", "constituency", "clause-analysis")
|
|
27
|
+
examples = (
|
|
28
|
+
"Annotate the clauses in 'Although he was tired, but he kept working.'",
|
|
29
|
+
"Mark the subject, predicate and infinitive complement of a sentence.",
|
|
30
|
+
)
|
|
31
|
+
product_name = "syntax-report"
|
|
32
|
+
|
|
33
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
34
|
+
try:
|
|
35
|
+
request = DiagnosticRequest.model_validate(
|
|
36
|
+
decode_payload(first_text(command))
|
|
37
|
+
)
|
|
38
|
+
report = analyze_syntax(request)
|
|
39
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
40
|
+
return self.fail(task, f"Syntax Agent rejected the payload: {exc}")
|
|
41
|
+
summary = (
|
|
42
|
+
f"识别 {report.clause_count} 个分句、{len(report.tokens)} 个 token;"
|
|
43
|
+
"句法树已发布"
|
|
44
|
+
)
|
|
45
|
+
return self.publish(task, report.model_dump(mode="json"), summary=summary)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
__all__ = ["SyntaxAgent"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Command-line interface for ACPs Grammar Tree."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
from .demo import run_demo, run_diagnosis
|
|
10
|
+
from .identity import PROJECT_VERSION
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="grammar-tree",
|
|
16
|
+
description=(
|
|
17
|
+
"Diagnose English grammar with Syntax, Error Tracer and Exercise "
|
|
18
|
+
"agents collaborating through acps-sdk AIP v2."
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--version", action="version", version=f"%(prog)s {PROJECT_VERSION}"
|
|
23
|
+
)
|
|
24
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
25
|
+
|
|
26
|
+
demo = subparsers.add_parser("demo", help="run the canonical Chinglish diagnosis")
|
|
27
|
+
demo.add_argument("--json", action="store_true", help="print the typed report as JSON")
|
|
28
|
+
|
|
29
|
+
diagnose = subparsers.add_parser("diagnose", help="diagnose one English sentence")
|
|
30
|
+
diagnose.add_argument("sentence", help="sentence enclosed in quotes")
|
|
31
|
+
diagnose.add_argument("--json", action="store_true", help="print JSON instead of text")
|
|
32
|
+
return parser
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
36
|
+
args = build_parser().parse_args(argv)
|
|
37
|
+
if args.command == "demo":
|
|
38
|
+
return asyncio.run(run_demo(as_json=args.json))
|
|
39
|
+
return asyncio.run(run_diagnosis(args.sentence, as_json=args.json))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""One-command startup and end-to-end Chinglish diagnosis demonstration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from .identity import PROJECT_NAME, PROJECT_VERSION
|
|
8
|
+
from .mesh import LocalAgentMesh
|
|
9
|
+
from .orchestrator import GrammarSession
|
|
10
|
+
from .report import render_report
|
|
11
|
+
from .rules import DEMO_SENTENCE
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def run_diagnosis(sentence: str, *, as_json: bool = False) -> int:
|
|
15
|
+
"""Start three RPC services, diagnose one sentence and print the report."""
|
|
16
|
+
|
|
17
|
+
print(f"{PROJECT_NAME} v{PROJECT_VERSION}")
|
|
18
|
+
print("Leader 通过 ADP 发现技能,再以 AIP v2 JSON-RPC 依次分发结构化任务。")
|
|
19
|
+
with LocalAgentMesh() as mesh:
|
|
20
|
+
print("本地多智能体网格:")
|
|
21
|
+
for agent in mesh.agents:
|
|
22
|
+
print(f" · {agent.name}: skill={agent.skill_id}, endpoint={agent.endpoint_url}")
|
|
23
|
+
print("\n[Leader] 提交任务:" + sentence)
|
|
24
|
+
async with GrammarSession(mesh.registry) as session:
|
|
25
|
+
report = await session.diagnose(sentence)
|
|
26
|
+
print()
|
|
27
|
+
if as_json:
|
|
28
|
+
print(json.dumps(report.model_dump(mode="json"), ensure_ascii=False, indent=2))
|
|
29
|
+
else:
|
|
30
|
+
print(render_report(report))
|
|
31
|
+
return 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async def run_demo(*, as_json: bool = False) -> int:
|
|
35
|
+
"""Run the canonical Although/but Chinglish case without user interaction."""
|
|
36
|
+
|
|
37
|
+
return await run_diagnosis(DEMO_SENTENCE, as_json=as_json)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = ["run_demo", "run_diagnosis"]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""ACP identity and capability-spec helpers for the grammar mesh."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
|
|
7
|
+
from acps_sdk.acs import (
|
|
8
|
+
AgentCapabilities,
|
|
9
|
+
AgentCapabilitySpec,
|
|
10
|
+
AgentEndPoint,
|
|
11
|
+
AgentProvider,
|
|
12
|
+
AgentSkill,
|
|
13
|
+
)
|
|
14
|
+
from acps_sdk.aic import is_valid_aic_format
|
|
15
|
+
|
|
16
|
+
PROJECT_NAME = "acps-grammar-tree"
|
|
17
|
+
PROJECT_VERSION = "1.0.0"
|
|
18
|
+
PROTOCOL_VERSION = "02.00"
|
|
19
|
+
AIC_PREFIX = "1.2.156.3088.1.1.34C2.478BDF"
|
|
20
|
+
LEADER_AIC = f"{AIC_PREFIX}.00000E.0GTL"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def make_aic(instance_serial: str, checksum: str) -> str:
|
|
24
|
+
"""Build and validate one ten-level ACP agent identity."""
|
|
25
|
+
|
|
26
|
+
aic = f"{AIC_PREFIX}.{instance_serial}.{checksum}"
|
|
27
|
+
if not is_valid_aic_format(aic):
|
|
28
|
+
raise ValueError(f"Invalid AIC '{aic}': does not match the AIC grammar")
|
|
29
|
+
return aic
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def build_capability_spec(
|
|
33
|
+
*,
|
|
34
|
+
aic: str,
|
|
35
|
+
name: str,
|
|
36
|
+
description: str,
|
|
37
|
+
skill: AgentSkill,
|
|
38
|
+
endpoint_url: str,
|
|
39
|
+
) -> AgentCapabilitySpec:
|
|
40
|
+
"""Create the ACS document advertised through local ADP discovery."""
|
|
41
|
+
|
|
42
|
+
return AgentCapabilitySpec(
|
|
43
|
+
aic=aic,
|
|
44
|
+
active=True,
|
|
45
|
+
last_modified_time=datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
46
|
+
protocol_version=PROTOCOL_VERSION,
|
|
47
|
+
name=name,
|
|
48
|
+
description=description,
|
|
49
|
+
version=PROJECT_VERSION,
|
|
50
|
+
provider=AgentProvider(
|
|
51
|
+
country_code="CN",
|
|
52
|
+
organization="ACPs Grammar Tree Labs",
|
|
53
|
+
department="Diagnostic Language Engineering",
|
|
54
|
+
url="https://pypi.org/project/acps-grammar-tree/",
|
|
55
|
+
name="Grammar Tree Platform Team",
|
|
56
|
+
),
|
|
57
|
+
security_schemes={},
|
|
58
|
+
end_points=[AgentEndPoint(url=endpoint_url, transport="JSONRPC")],
|
|
59
|
+
capabilities=AgentCapabilities(
|
|
60
|
+
streaming=False,
|
|
61
|
+
notification=False,
|
|
62
|
+
message_queue=[],
|
|
63
|
+
),
|
|
64
|
+
default_input_modes=["text/plain", "application/json"],
|
|
65
|
+
default_output_modes=["application/json"],
|
|
66
|
+
skills=[skill],
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
__all__ = [
|
|
71
|
+
"LEADER_AIC",
|
|
72
|
+
"PROJECT_NAME",
|
|
73
|
+
"PROJECT_VERSION",
|
|
74
|
+
"build_capability_spec",
|
|
75
|
+
"make_aic",
|
|
76
|
+
]
|