feat(bot): chat agent on Gemini 2.5 Flash-Lite — grounded first turn, current-prescription defaults
CI / ruff · pytest (pull_request) Successful in 2m5s
CI / ruff · pytest (pull_request) Successful in 2m5s
Live-tested on OpenRouter: Flash-Lite answers in 3–8 s with correct findings at ~$0.10/$0.40 per 1M tokens (qwen3.7-flash and gpt-oss-120b took 26–32 s). Force a tool call on the first turn, give the model the current prescription, let check_drug_for_patient default to it and return composition, intolerance check and general interactions (alcohol); retry once on an empty final message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -169,3 +169,31 @@ def test_build_provider_modes():
|
||||
assert isinstance(agent.build_provider(Settings(_env_file=None, chat_agent="mock")), MockAgentProvider)
|
||||
assert agent.build_provider(Settings(_env_file=None, chat_agent="openrouter")) is None # no key
|
||||
assert agent.build_provider(Settings(_env_file=None, chat_agent="off")) is None
|
||||
|
||||
|
||||
async def test_check_defaults_to_current_prescription(sertraline):
|
||||
out = json.loads(await run_tool(ToolContext(token=ANDREY), "check_drug_for_patient", {"drug": "мои таблетки"}))
|
||||
assert out["found"] and out["inn"] == "сертралин"
|
||||
assert "лактоз" in out["intolerance_check"] and "нет" in out["intolerance_check"]
|
||||
assert any("Алкоголь" in t for t in out["general_interactions"])
|
||||
|
||||
|
||||
async def test_empty_final_answer_is_nudged(sertraline):
|
||||
replies = iter(
|
||||
[
|
||||
{"role": "assistant", "content": None, "tool_calls": _CALLS},
|
||||
{"role": "assistant", "content": ""},
|
||||
{"role": "assistant", "content": "Алкоголь во время лечения не рекомендуется. Обсудите с врачом."},
|
||||
]
|
||||
)
|
||||
sent = []
|
||||
|
||||
def handler(request):
|
||||
sent.append(json.loads(request.content))
|
||||
return httpx.Response(200, json={"choices": [{"message": next(replies)}]})
|
||||
|
||||
provider = OpenRouterProvider(_settings(), client=httpx.AsyncClient(transport=httpx.MockTransport(handler)))
|
||||
ans = await agent.answer_chat(ANDREY, scrub("пиво можно?"), provider=provider, settings=_settings())
|
||||
assert ans is not None and "Алкоголь" in ans.text
|
||||
assert sent[0]["tool_choice"] == "required" and "tool_choice" not in sent[1]
|
||||
assert "сертралин" in sent[0]["messages"][0]["content"] # patient brief in the system prompt
|
||||
|
||||
Reference in New Issue
Block a user