acps-math-multisolver 1.0.0__py3-none-any.whl

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.
@@ -0,0 +1,169 @@
1
+ """Deterministic quadratic-capstone strategies used by the specialist agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..models import SocraticGuide, SocraticRequest, SocraticTurn, SolutionPath, SolveRequest
8
+
9
+ DEMO_PROBLEM = (
10
+ "已知抛物线 y = -x² + 2x + 3 与 x 轴交于 A、B 两点(A 在 B 左侧),"
11
+ "与 y 轴交于点 C。点 P 是抛物线弧 BC 上一动点(不与 B、C 重合)。"
12
+ "(1) 求 A、B、C 的坐标;(2) 求 △PBC 面积的最大值及此时 P 的坐标。"
13
+ )
14
+ DEMO_REQUEST = SolveRequest(problem=DEMO_PROBLEM)
15
+
16
+
17
+ def algebra_solution(request: SolveRequest) -> SolutionPath:
18
+ """Solve the supported capstone by constructing a quadratic area function."""
19
+
20
+ _ensure_supported(request)
21
+ return SolutionPath(
22
+ agent="Algebra Agent",
23
+ path="algebra",
24
+ title="代数路径:面积函数与配方",
25
+ key_idea="以动点横坐标为单变量,把面积转化为区间上的二次函数最值。",
26
+ steps=[
27
+ "令 y=0:−x²+2x+3=0,得 x=−1 或 3,所以 A(−1,0)、B(3,0);"
28
+ "令 x=0,得 C(0,3)。",
29
+ "设 P(t,−t²+2t+3),其中 0<t<3。直线 BC 为 x+y−3=0。",
30
+ "以 BC 为底,|BC|=3√2;点 P 到 BC 的距离 "
31
+ "d=(−t²+3t)/√2(弧 BC 上 P 在直线上方)。",
32
+ "S(t)=1/2·|BC|·d=3/2(−t²+3t)"
33
+ "=−3/2(t−3/2)²+27/8。",
34
+ "二次项系数为负且 t=3/2∈(0,3),故 Smax=27/8;"
35
+ "此时 y=15/4,P(3/2,15/4)。",
36
+ ],
37
+ answer="最大面积为 27/8,此时 P(3/2,15/4)。",
38
+ verification="将 t=3/2 代入面积函数,并由几何路径的切线条件独立复核。",
39
+ )
40
+
41
+
42
+ def geometry_solution(request: SolveRequest) -> SolutionPath:
43
+ """Solve the same capstone by translating a parallel line until tangency."""
44
+
45
+ _ensure_supported(request)
46
+ return SolutionPath(
47
+ agent="Geometry Agent",
48
+ path="geometry",
49
+ title="几何路径:平行线平移与相切",
50
+ key_idea="固定底边后,面积最大等价于高最大;最远平行线的临界状态是相切。",
51
+ steps=[
52
+ "由 −x²+2x+3=0 得 A(−1,0)、B(3,0),且 C(0,3),"
53
+ "所以 |BC|=3√2,直线 BC 为 x+y−3=0。",
54
+ "BC 长度固定,因此面积最大等价于 P 到直线 BC 的距离最大;"
55
+ "这不等同于 P 的纵坐标最大。",
56
+ "作 l∥BC,设 l:x+y=k。向远离 BC 的方向平移 l,"
57
+ "临界位置是与抛物线相切,切点即所求 P。",
58
+ "联立 l 与抛物线:x+(−x²+2x+3)=k,整理得 "
59
+ "x²−3x+(k−3)=0。相切要求 Δ=(−3)²−4(k−3)"
60
+ "=21−4k=0,故 k=21/4。",
61
+ "此时重根 t=3/2,y=k−t=15/4;两平行线 "
62
+ "x+y−3=0 与 x+y−21/4=0 的距离为 9/(4√2)。",
63
+ "Smax=1/2·|BC|·d=1/2·3√2·9/(4√2)=27/8。",
64
+ ],
65
+ answer="最大面积为 27/8,此时 P(3/2,15/4)。",
66
+ verification="切点坐标与代数路径面积函数的顶点坐标完全一致。",
67
+ )
68
+
69
+
70
+ def socratic_guide(request: SocraticRequest) -> SocraticGuide:
71
+ """Build a question chain from validated algebra and geometry products."""
72
+
73
+ _ensure_supported(SolveRequest(problem=request.problem))
74
+ if request.algebra.answer != request.geometry.answer:
75
+ raise ValueError("specialist paths disagree; tutoring is withheld pending review")
76
+
77
+ turns = [
78
+ SocraticTurn(
79
+ number=1,
80
+ focus="shared",
81
+ question="在 P 移动时,BC 的长度会改变吗?若把 BC 作为底,真正变化的量是什么?",
82
+ expected_idea="底边固定,面积的变化完全由点 P 到 BC 的高决定。",
83
+ scaffold="先写出 B、C 的坐标,再观察面积公式 S=1/2×底×高。",
84
+ acknowledgement="你已经把动点问题收敛为‘高的最值’,这是两条路径共同的入口。",
85
+ ),
86
+ SocraticTurn(
87
+ number=2,
88
+ focus="shared",
89
+ question="P 的纵坐标最大,就一定能保证它到斜线 BC 的距离最大吗?为什么?",
90
+ expected_idea="纵坐标是到 x 轴的距离,而本题的高必须垂直于斜线 BC。",
91
+ scaffold="比较‘到 x 轴的距离’与‘到直线 BC 的距离’,它们的方向相同吗?",
92
+ acknowledgement="你排除了把抛物线顶点直接当答案的常见直觉陷阱。",
93
+ ),
94
+ SocraticTurn(
95
+ number=3,
96
+ focus="algebra",
97
+ question="若设 P(t,−t²+2t+3),你能否用 t 同时表示底、高,从而得到面积函数 S(t)?",
98
+ expected_idea="用点到直线距离公式,把面积表示为关于 t 的二次函数。",
99
+ scaffold="先求直线 BC 的方程;在弧 BC 上,判断 x+y−3 的符号再去绝对值。",
100
+ acknowledgement="几何图形现在已经转化为可计算的代数对象。",
101
+ ),
102
+ SocraticTurn(
103
+ number=4,
104
+ focus="algebra",
105
+ question="得到开口向下的二次函数后,除了配方,还必须检查哪个区间条件?",
106
+ expected_idea="顶点横坐标必须落在动点允许的 0<t<3 内。",
107
+ scaffold="回到题意:P 只在弧 BC 上运动,而不是整条抛物线上运动。",
108
+ acknowledgement="你不仅找到了候选最值,还验证了它确实可以取到。",
109
+ ),
110
+ SocraticTurn(
111
+ number=5,
112
+ focus="geometry",
113
+ question=(
114
+ "如果作一条与 BC 平行的直线并向抛物线外侧平移,"
115
+ "何时达到‘仍有公共点’的最后位置?"
116
+ ),
117
+ expected_idea="平行线与抛物线相切时,距离达到临界最大值。",
118
+ scaffold="想象保留最后一个公共点:再向外移动,直线与抛物线就会分离。",
119
+ acknowledgement="你把静态最值看成了直线运动过程中的临界状态。",
120
+ ),
121
+ SocraticTurn(
122
+ number=6,
123
+ focus="geometry",
124
+ question="设这条平行线为 x+y=k,与抛物线联立后,‘相切’对应一元二次方程的哪个条件?",
125
+ expected_idea="联立方程有两个重合实根,因此判别式为零。",
126
+ scaffold="消去 y 后,思考两个交点、一个切点、没有交点分别对应怎样的判别式。",
127
+ acknowledgement="你把几何位置关系准确翻译成了判别式条件。",
128
+ ),
129
+ SocraticTurn(
130
+ number=7,
131
+ focus="synthesis",
132
+ question="代数面积函数的顶点与几何路径的切点重合,是巧合吗?它们共同刻画了什么事实?",
133
+ expected_idea="两种表征都在寻找同一可行弧段上到 BC 距离最大的点。",
134
+ scaffold="暂时不看计算式,只比较两种方法各自对‘最大高’的定义。",
135
+ acknowledgement="你已经从‘会做两法’走向‘理解两法为什么等价’。",
136
+ ),
137
+ ]
138
+ return SocraticGuide(
139
+ strategy="共同表征 → 代数分岔 → 几何分岔 → 双路径贯通;先问关键量,再追问临界条件。",
140
+ source_paths=[request.algebra.key_idea, request.geometry.key_idea],
141
+ turns=turns,
142
+ reflection=(
143
+ "代数法把最值交给函数结构,几何法把最值交给相切临界;"
144
+ "比较二者的约束与结论,比记住单一模板更能迁移到竞赛题和证明题。"
145
+ ),
146
+ )
147
+
148
+
149
+ def _ensure_supported(request: SolveRequest) -> None:
150
+ """Reject unsupported text instead of fabricating a mathematical solution."""
151
+
152
+ if _normalize(request.problem) != _normalize(DEMO_PROBLEM):
153
+ raise ValueError(
154
+ "the deterministic v1.0.0 kernel supports the bundled quadratic "
155
+ "capstone only; use DEMO_REQUEST or add a verified domain strategy"
156
+ )
157
+
158
+
159
+ def _normalize(text: str) -> str:
160
+ return re.sub(r"\s+", "", text).replace("−", "-").replace("(", "(").replace(")", ")")
161
+
162
+
163
+ __all__ = [
164
+ "DEMO_PROBLEM",
165
+ "DEMO_REQUEST",
166
+ "algebra_solution",
167
+ "geometry_solution",
168
+ "socratic_guide",
169
+ ]
@@ -0,0 +1,79 @@
1
+ """ACP identities and Agent Capability Specification helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import UTC, datetime
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-math-multisolver"
17
+ PROJECT_VERSION = "1.0.0"
18
+ PROTOCOL_VERSION = "02.00"
19
+ AIC_PREFIX = "1.2.156.3088.1.1.34C2.478D02"
20
+ LEADER_AIC = f"{AIC_PREFIX}.000200.0MLS"
21
+ PROJECT_URL = "https://pypi.org/project/acps-math-multisolver/"
22
+
23
+
24
+ def make_aic(instance_serial: str, checksum: str) -> str:
25
+ """Build and validate one ten-level ACP agent identity code."""
26
+
27
+ aic = f"{AIC_PREFIX}.{instance_serial}.{checksum}"
28
+ if not is_valid_aic_format(aic):
29
+ raise ValueError(f"Invalid AIC '{aic}': does not match the AIC grammar")
30
+ return aic
31
+
32
+
33
+ def build_capability_spec(
34
+ *,
35
+ aic: str,
36
+ name: str,
37
+ description: str,
38
+ skill: AgentSkill,
39
+ endpoint_url: str,
40
+ ) -> AgentCapabilitySpec:
41
+ """Create the ACS document advertised through local ADP discovery."""
42
+
43
+ return AgentCapabilitySpec(
44
+ aic=aic,
45
+ active=True,
46
+ last_modified_time=datetime.now(UTC).isoformat(timespec="seconds"),
47
+ protocol_version=PROTOCOL_VERSION,
48
+ name=name,
49
+ description=description,
50
+ version=PROJECT_VERSION,
51
+ provider=AgentProvider(
52
+ country_code="CN",
53
+ organization="ACPs Math MultiSolver Labs",
54
+ department="Mathematical Learning Engineering",
55
+ url=PROJECT_URL,
56
+ name="Math MultiSolver Platform Team",
57
+ ),
58
+ security_schemes={},
59
+ end_points=[AgentEndPoint(url=endpoint_url, transport="JSONRPC")],
60
+ capabilities=AgentCapabilities(
61
+ streaming=False,
62
+ notification=False,
63
+ message_queue=[],
64
+ ),
65
+ default_input_modes=["text/plain", "application/json"],
66
+ default_output_modes=["application/json"],
67
+ skills=[skill],
68
+ )
69
+
70
+
71
+ __all__ = [
72
+ "LEADER_AIC",
73
+ "PROJECT_NAME",
74
+ "PROJECT_URL",
75
+ "PROJECT_VERSION",
76
+ "PROTOCOL_VERSION",
77
+ "build_capability_spec",
78
+ "make_aic",
79
+ ]
@@ -0,0 +1,61 @@
1
+ """Local ACPs mesh with three independent AIP RPC specialist services."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from types import TracebackType
6
+
7
+ from .agents import AipAgent, AlgebraAgent, GeometryAgent, SocraticAgent
8
+ from .identity import make_aic
9
+ from .registry import AgentRegistry
10
+ from .runtime import AgentServer
11
+
12
+ _AGENT_SPECS: tuple[tuple[type[AipAgent], str, str], ...] = (
13
+ (AlgebraAgent, "000201", "0ALG"),
14
+ (GeometryAgent, "000202", "0GEO"),
15
+ (SocraticAgent, "000203", "0SOC"),
16
+ )
17
+
18
+
19
+ class LocalAgentMesh:
20
+ """Start, advertise and stop the complete local collaboration team."""
21
+
22
+ def __init__(self) -> None:
23
+ self.registry = AgentRegistry()
24
+ self.agents: list[AipAgent] = []
25
+ self._servers: list[AgentServer] = []
26
+
27
+ def __enter__(self) -> LocalAgentMesh:
28
+ self.start()
29
+ return self
30
+
31
+ def __exit__(
32
+ self,
33
+ exc_type: type[BaseException] | None,
34
+ exc: BaseException | None,
35
+ traceback: TracebackType | None,
36
+ ) -> None:
37
+ self.stop()
38
+
39
+ def start(self) -> None:
40
+ if self._servers:
41
+ return
42
+ try:
43
+ for agent_class, serial, checksum in _AGENT_SPECS:
44
+ agent = agent_class(make_aic(serial, checksum))
45
+ server = AgentServer(agent)
46
+ server.start()
47
+ self.registry.publish(agent.capability_spec)
48
+ self.agents.append(agent)
49
+ self._servers.append(server)
50
+ except Exception:
51
+ self.stop()
52
+ raise
53
+
54
+ def stop(self) -> None:
55
+ for server in reversed(self._servers):
56
+ server.stop()
57
+ self._servers.clear()
58
+ self.agents.clear()
59
+
60
+
61
+ __all__ = ["LocalAgentMesh"]
@@ -0,0 +1,103 @@
1
+ """Typed contracts exchanged by the multi-agent mathematics workflow."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Literal
6
+
7
+ from pydantic import BaseModel, Field
8
+
9
+
10
+ class SolveRequest(BaseModel):
11
+ """A natural-language problem submitted to the specialist team."""
12
+
13
+ problem: str = Field(min_length=1, max_length=4000)
14
+
15
+
16
+ class SolutionPath(BaseModel):
17
+ """A complete, independently generated solution from one specialist."""
18
+
19
+ agent: str
20
+ path: Literal["algebra", "geometry"]
21
+ title: str
22
+ key_idea: str
23
+ steps: list[str] = Field(min_length=2)
24
+ answer: str
25
+ verification: str
26
+
27
+
28
+ class SocraticRequest(BaseModel):
29
+ """The tutor consumes both solutions instead of working in isolation."""
30
+
31
+ problem: str = Field(min_length=1, max_length=4000)
32
+ algebra: SolutionPath
33
+ geometry: SolutionPath
34
+
35
+
36
+ class SocraticTurn(BaseModel):
37
+ """One question with a private learning objective and an optional scaffold."""
38
+
39
+ number: int = Field(ge=1)
40
+ focus: Literal["shared", "algebra", "geometry", "synthesis"]
41
+ question: str
42
+ expected_idea: str
43
+ scaffold: str
44
+ acknowledgement: str
45
+
46
+
47
+ class SocraticGuide(BaseModel):
48
+ """A progressive question chain derived from both solution products."""
49
+
50
+ strategy: str
51
+ source_paths: list[str] = Field(min_length=2, max_length=2)
52
+ turns: list[SocraticTurn] = Field(min_length=3)
53
+ reflection: str
54
+
55
+
56
+ class DialogueTurn(BaseModel):
57
+ """An inspectable learner-tutor exchange in the demonstration transcript."""
58
+
59
+ number: int = Field(ge=1)
60
+ question: str
61
+ learner_response: str
62
+ tutor_reply: str
63
+
64
+
65
+ class AgentTrace(BaseModel):
66
+ """Auditable metadata for one AIP task dispatched by the Leader."""
67
+
68
+ agent: str
69
+ aic: str
70
+ skill_id: str
71
+ task_id: str
72
+ state: str
73
+ elapsed_ms: int = Field(ge=0)
74
+ summary: str
75
+
76
+
77
+ class MultiSolveReport(BaseModel):
78
+ """The final fan-in product containing solutions, tutoring and ACP traces."""
79
+
80
+ report_id: str
81
+ session_id: str
82
+ project_version: str
83
+ sdk_version: str
84
+ problem: str
85
+ algebra: SolutionPath
86
+ geometry: SolutionPath
87
+ socratic: SocraticGuide
88
+ dialogue: list[DialogueTurn] = Field(default_factory=list)
89
+ traces: list[AgentTrace]
90
+ agents_online: list[str]
91
+ total_ms: int = Field(ge=0)
92
+
93
+
94
+ __all__ = [
95
+ "AgentTrace",
96
+ "DialogueTurn",
97
+ "MultiSolveReport",
98
+ "SocraticGuide",
99
+ "SocraticRequest",
100
+ "SocraticTurn",
101
+ "SolutionPath",
102
+ "SolveRequest",
103
+ ]
@@ -0,0 +1,205 @@
1
+ """Leader orchestration: ADP discovery, parallel AIP dispatch and fan-in."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import time
7
+ from dataclasses import dataclass
8
+ from importlib.metadata import version
9
+ from types import TracebackType
10
+ from typing import Any, TypeVar
11
+ from uuid import uuid4
12
+
13
+ from acps_sdk.adp import DiscoveryRequest, FilterOperator
14
+ from acps_sdk.aip import AipRpcClient, TaskResult, TaskState
15
+ from pydantic import BaseModel, ValidationError
16
+
17
+ from .identity import LEADER_AIC, PROJECT_VERSION
18
+ from .models import (
19
+ AgentTrace,
20
+ MultiSolveReport,
21
+ SocraticGuide,
22
+ SocraticRequest,
23
+ SolutionPath,
24
+ SolveRequest,
25
+ )
26
+ from .registry import AgentRegistry, build_filter
27
+ from .runtime import encode_payload, product_payload
28
+
29
+ ALGEBRA_TAG = "algebra-solution"
30
+ GEOMETRY_TAG = "geometry-solution"
31
+ SOCRATIC_TAG = "socratic-guidance"
32
+ SKILL_TAGS = (ALGEBRA_TAG, GEOMETRY_TAG, SOCRATIC_TAG)
33
+ ModelT = TypeVar("ModelT", bound=BaseModel)
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class AgentEndpoint:
38
+ """One specialist endpoint resolved through ADP."""
39
+
40
+ aic: str
41
+ name: str
42
+ skill_id: str
43
+ rpc_url: str
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class _TimedProduct:
48
+ endpoint: AgentEndpoint
49
+ result: TaskResult
50
+ payload: dict[str, Any]
51
+ elapsed_ms: int
52
+
53
+
54
+ class MultiSolveSession:
55
+ """Run ``Algebra ∥ Geometry → Socratic → Leader`` over AIP v2.
56
+
57
+ The Socratic request embeds both validated structured products. The Leader
58
+ therefore never bypasses ACP communication to call specialist logic directly.
59
+ """
60
+
61
+ def __init__(self, registry: AgentRegistry, *, session_id: str | None = None) -> None:
62
+ self._registry = registry
63
+ self.session_id = session_id or f"multisolve-{uuid4()}"
64
+ self._endpoints: dict[str, AgentEndpoint] = {}
65
+ self._clients: dict[str, AipRpcClient] = {}
66
+
67
+ async def __aenter__(self) -> MultiSolveSession:
68
+ self.resolve_team()
69
+ for tag, endpoint in self._endpoints.items():
70
+ self._clients[tag] = AipRpcClient(endpoint.rpc_url, leader_id=LEADER_AIC)
71
+ return self
72
+
73
+ async def __aexit__(
74
+ self,
75
+ exc_type: type[BaseException] | None,
76
+ exc: BaseException | None,
77
+ traceback: TracebackType | None,
78
+ ) -> None:
79
+ for client in self._clients.values():
80
+ await client.close()
81
+ self._clients.clear()
82
+
83
+ def resolve_team(self) -> dict[str, AgentEndpoint]:
84
+ """Discover all required specialists using ADP ``skills.tags`` filters."""
85
+
86
+ for tag in SKILL_TAGS:
87
+ if tag not in self._endpoints:
88
+ self._endpoints[tag] = self._discover(tag)
89
+ return dict(self._endpoints)
90
+
91
+ async def run(self, request: SolveRequest) -> MultiSolveReport:
92
+ """Solve in parallel, then ask the tutor to synthesize a question chain."""
93
+
94
+ started = time.perf_counter()
95
+ algebra_job, geometry_job = await asyncio.gather(
96
+ self._call(ALGEBRA_TAG, request),
97
+ self._call(GEOMETRY_TAG, request),
98
+ )
99
+ algebra = _as_model(algebra_job.payload, SolutionPath)
100
+ geometry = _as_model(geometry_job.payload, SolutionPath)
101
+
102
+ socratic_job = await self._call(
103
+ SOCRATIC_TAG,
104
+ SocraticRequest(problem=request.problem, algebra=algebra, geometry=geometry),
105
+ )
106
+ socratic = _as_model(socratic_job.payload, SocraticGuide)
107
+ traces = [
108
+ _trace(algebra_job, "构造面积二次函数,配方并检查动点区间"),
109
+ _trace(geometry_job, "平移平行线,利用判别式为零定位最大高"),
110
+ _trace(socratic_job, "读取双路径产物,生成七轮苏格拉底式启发"),
111
+ ]
112
+ return MultiSolveReport(
113
+ report_id=f"report-{uuid4()}",
114
+ session_id=self.session_id,
115
+ project_version=PROJECT_VERSION,
116
+ sdk_version=version("acps-sdk"),
117
+ problem=request.problem,
118
+ algebra=algebra,
119
+ geometry=geometry,
120
+ socratic=socratic,
121
+ traces=traces,
122
+ agents_online=[endpoint.name for endpoint in self._endpoints.values()],
123
+ total_ms=int((time.perf_counter() - started) * 1000),
124
+ )
125
+
126
+ async def _call(self, tag: str, payload: BaseModel) -> _TimedProduct:
127
+ endpoint = self._endpoints[tag]
128
+ client = self._client(tag)
129
+ start = time.perf_counter()
130
+ result = await client.start_task(self.session_id, encode_payload(payload))
131
+ elapsed_ms = int((time.perf_counter() - start) * 1000)
132
+ if result.status.state is not TaskState.Completed:
133
+ raise RuntimeError(
134
+ f"{endpoint.name} returned {result.status.state.value}: "
135
+ f"{_failure_text(result)}"
136
+ )
137
+ return _TimedProduct(
138
+ endpoint=endpoint,
139
+ result=result,
140
+ payload=product_payload(result),
141
+ elapsed_ms=elapsed_ms,
142
+ )
143
+
144
+ def _client(self, tag: str) -> AipRpcClient:
145
+ try:
146
+ return self._clients[tag]
147
+ except KeyError as exc:
148
+ raise RuntimeError(
149
+ "session is not started; use 'async with MultiSolveSession(...)'"
150
+ ) from exc
151
+
152
+ def _discover(self, tag: str) -> AgentEndpoint:
153
+ request = DiscoveryRequest(
154
+ type="filtered",
155
+ limit=5,
156
+ filter=build_filter("skills.tags", FilterOperator.ANY_OF, [tag]),
157
+ )
158
+ result = self._registry.discover(request)
159
+ for aic, acs, skill, _group in result.iter_agent_skills():
160
+ endpoints = acs.get("endPoints") or []
161
+ if not endpoints or not endpoints[0].get("url"):
162
+ continue
163
+ return AgentEndpoint(
164
+ aic=aic,
165
+ name=str(acs.get("name", skill.skill_id)),
166
+ skill_id=skill.skill_id,
167
+ rpc_url=str(endpoints[0]["url"]),
168
+ )
169
+ raise LookupError(f"no ACPs agent advertises the tag '{tag}'")
170
+
171
+
172
+ def _as_model(payload: dict[str, Any], model_type: type[ModelT]) -> ModelT:
173
+ try:
174
+ return model_type.model_validate(payload)
175
+ except ValidationError as exc:
176
+ raise RuntimeError(f"malformed product from partner agent: {exc}") from exc
177
+
178
+
179
+ def _trace(product: _TimedProduct, summary: str) -> AgentTrace:
180
+ return AgentTrace(
181
+ agent=product.endpoint.name,
182
+ aic=product.endpoint.aic,
183
+ skill_id=product.endpoint.skill_id,
184
+ task_id=product.result.taskId,
185
+ state=product.result.status.state.value,
186
+ elapsed_ms=product.elapsed_ms,
187
+ summary=summary,
188
+ )
189
+
190
+
191
+ def _failure_text(result: TaskResult) -> str:
192
+ for item in result.status.dataItems or []:
193
+ text = getattr(item, "text", None)
194
+ if text:
195
+ return str(text)
196
+ return "partner agent failed without a diagnostic message"
197
+
198
+
199
+ __all__ = [
200
+ "ALGEBRA_TAG",
201
+ "GEOMETRY_TAG",
202
+ "SOCRATIC_TAG",
203
+ "AgentEndpoint",
204
+ "MultiSolveSession",
205
+ ]
File without changes