diff --git a/README.md b/README.md index 50544dd..927a873 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,9 @@ uv run mkdocs build --strict Сервис принимает только `calendar.create_event`. Для готового предложения нужны `title`, `startAt`, `endAt` и `timeZone`. Доступны `fake-calendar` и `google-calendar`; demo-модель выбирает Google, если клиент передал его в `availableConnectors`, иначе использует fake. Если полей не хватает, ответ -содержит `clarification`, а `proposal` остаётся `null`. Готовое предложение всегда содержит -`requiresApproval: true`. +содержит `clarification`, а `proposal` остаётся `null`. Если модель не распознала действие или +выбрала недоступный коннектор, пользователь получает просьбу описать задачу снова. Готовое +предложение всегда содержит `requiresApproval: true`. Внешний запрос использует поля `text`, `timeZone` и `availableConnectors`. Проверенная копия схемы лежит в `contracts/agent-runtime-api.yaml`; безопасное обновление выполняет diff --git a/docs/index.md b/docs/index.md index 68d5d9b..30a97df 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,8 @@ Completions API и проверяет JSON-ответ через внутрен Разрешено только действие `calendar.create_event` через `fake-calendar` или `google-calendar`. Обязательны название, начало, конец и часовой пояс. Результат содержит либо `proposal`, либо -`clarification`; обе части могут быть `null`, если модель не нашла действие или коннектор недоступен. +`clarification`. Если модель не нашла действие или коннектор недоступен, сервис возвращает +`clarification` с просьбой описать задачу ещё раз. Создание встречи всегда требует явного подтверждения в `action-service`. Публичный API соответствует `portable-agent/contracts` версии `3.0.0`. Поля называются `text`, diff --git a/src/portable_agent/services/proposal_service.py b/src/portable_agent/services/proposal_service.py index aeceea1..4625bfc 100644 --- a/src/portable_agent/services/proposal_service.py +++ b/src/portable_agent/services/proposal_service.py @@ -19,11 +19,11 @@ def __init__(self, model: IntentModel, policy: PolicyRepository) -> None: async def propose(self, text: str, context: UserContext) -> ProposalResult: reply = await self._model.propose(text, context) if reply is None: - return ProposalResult() + return _unsupported_reply() if reply.kind != "calendar.create_event": - return ProposalResult() + return _unsupported_reply() if reply.connector not in context.available_tools: - return ProposalResult() + return _unsupported_reply() missing_fields = _get_missing_fields(reply.payload) if missing_fields: @@ -37,7 +37,7 @@ async def propose(self, text: str, context: UserContext) -> ProposalResult: try: event = CalendarEvent.model_validate(reply.payload) except ValidationError: - return ProposalResult() + return _unsupported_reply() risk = await self._policy.get_risk(reply, context) return ProposalResult( @@ -78,3 +78,12 @@ def _get_question(missing_fields: list[str]) -> str: names = [_FIELD_NAMES[field] for field in missing_fields] fields_text = names[0] if len(names) == 1 else f"{', '.join(names[:-1])} и {names[-1]}" return f"Укажи {fields_text} встречи." + + +def _unsupported_reply() -> ProposalResult: + return ProposalResult( + clarification=Clarification( + question="Не удалось распознать задачу. Опиши, что нужно сделать.", # noqa: RUF001 + missing_fields=[], + ) + ) diff --git a/tests/test_proposal_service.py b/tests/test_proposal_service.py index 6840e18..441e448 100644 --- a/tests/test_proposal_service.py +++ b/tests/test_proposal_service.py @@ -74,13 +74,17 @@ async def test_propose_incomplete_calendar_event_returns_clarification() -> None @pytest.mark.asyncio -async def test_propose_when_model_returns_no_call_returns_none() -> None: +async def test_propose_when_model_returns_no_call_returns_clarification() -> None: service = ProposalService(FakeModel(None), FakePolicy(Risk.LOW)) result = await service.propose("Привет", context("fake-calendar")) assert result.proposal is None - assert result.clarification is None + assert result.clarification is not None + assert result.clarification.question == ( + "Не удалось распознать задачу. Опиши, что нужно сделать." + ) + assert result.clarification.missing_fields == [] @pytest.mark.asyncio @@ -101,7 +105,7 @@ async def test_propose_when_connector_unavailable_rejects_proposal() -> None: result = await service.propose("Создай встречу", context("google-calendar")) assert result.proposal is None - assert result.clarification is None + assert result.clarification is not None @pytest.mark.asyncio @@ -117,7 +121,7 @@ async def test_propose_when_action_is_not_allowed_returns_empty_result() -> None result = await service.propose("Переведи деньги", context("wallet")) assert result.proposal is None - assert result.clarification is None + assert result.clarification is not None @pytest.mark.asyncio @@ -191,4 +195,4 @@ async def test_propose_when_calendar_payload_is_invalid_returns_empty_result( result = await service.propose("Создай встречу", context("fake-calendar")) assert result.proposal is None - assert result.clarification is None + assert result.clarification is not None diff --git a/uv.lock b/uv.lock index 211b264..28a1edc 100644 --- a/uv.lock +++ b/uv.lock @@ -82,11 +82,11 @@ wheels = [ [[package]] name = "certifi" -version = "2026.7.22" +version = "2026.10.23" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/a3/c2/24167ea9858356b47a87a50d39908bfdb72ceeefe0041586e704e5376b3a/certifi-2026.7.22.tar.gz", hash = "sha256:741e2c3b351ddf169a738da9f2c048608ff7f2c5cc02f1ebc6b118bb090d5d55", size = 138112, upload-time = "2026-07-22T03:35:12.644Z" } +sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/0b/a7/71ac2cff56fec219ed242bb11b8efb69fcc4bec75db06fb7bfe35de520e6/certifi-2026.7.22-py3-none-any.whl", hash = "sha256:62f22742b58a1a33014a2b6b706588a8d7e2a88ae7bd1a6ebe8c992928483775", size = 136983, upload-time = "2026-07-22T03:35:11.276Z" }, + { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" }, ] [[package]]