fix(bot): agent polish — instant small talk, capped tool calls, analogues, plain text, definitions allowed
CI / ruff · pytest (pull_request) Successful in 2m43s

- Greetings / chit-chat answered without the LLM (instant, free, no medical findings dumped into «привет»).
- At most 4 tool calls per turn (one «как дела?» turn fired 23 parallel searches).
- «My drug» is never asked back; analogues → the drug's group, replacement only by the doctor.
- Markdown stripped to plain text with «•»; no sources footer under short replies.
- Diagnosis filter no longer blocks definitions («ПТСР — это расстройство…»); diagnosis-like statements about
  the patient are still blocked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-04 22:43:18 +03:00
co-authored by Claude Opus 5.5
parent f0be84d020
commit e72378f178
4 changed files with 73 additions and 12 deletions
+24
View File
@@ -274,3 +274,27 @@ def test_build_provider_prefers_gigachat():
async def test_web_demo_token_shares_andreys_record():
rec = await emias_records.get("tok-andrey")
assert rec is not None and any("язвенная" in c.name.lower() for c in rec.conditions)
@pytest.mark.parametrize("text", ["прив", "Привет!", "как дела у тебя ? что делаешь ? спишь ?", "добрый вечер"])
async def test_small_talk_without_llm(text):
provider, sent = _fake_openrouter("x", _CALLS)
ans = await agent.answer_chat(ANDREY, scrub(text), provider=provider, settings=_settings())
assert ans is not None and ans.provider == "small_talk" and sent == []
async def test_medical_question_is_not_small_talk():
assert not agent.is_small_talk("привет, можно мне ибупрофен?")
async def test_tool_calls_are_capped(sertraline):
many = [
{"id": f"s{i}", "type": "function", "function": {"name": "search_guidelines", "arguments": '{"query": "x"}'}}
for i in range(20)
]
provider, sent = _fake_openrouter("Ответ по рекомендациям, обсудите с врачом.", many)
ans = await agent.answer_chat(ANDREY, scrub("что такое ПТСР?"), provider=provider, settings=_settings())
assert ans is not None and len(ans.tools) == agent.MAX_TOOL_CALLS_PER_TURN
tool_msgs = [m for m in sent[1]["messages"] if m["role"] == "tool"]
assistant = [m for m in sent[1]["messages"] if m["role"] == "assistant"][0]
assert len(tool_msgs) == len(assistant["tool_calls"]) == agent.MAX_TOOL_CALLS_PER_TURN