feat(агент): факт региональной базы подкладывается в контекст

Модель не выбирала regional_rate сама, поэтому при вопросе с кодом и названием
региона приложение само берёт факт из regional_ref и добавляет его в контекст с
пометкой «региональная база»; федеральную не подставляет. Инструмент принимает
название региона и учитывает склонение; пять проверок.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-22 16:28:02 +10:00
co-authored by Claude Code
parent 9f6f38b6ba
commit b969b9131f
5 changed files with 110 additions and 7 deletions
+22 -2
View File
@@ -28,8 +28,28 @@ def _subject_name(con, subject_id, registry=None):
DEFAULT_DB = Path(os.environ.get("REGIONAL_REF_PATH", "/app/data/regional_ref.sqlite"))
def lookup(code: str, subject_id: int, kind: str | None = None,
db: Path | str | None = None, registry: Path | str | None = None) -> dict:
def _resolve_region(region: str | None, registry=None) -> int | None:
if not region:
return None
try:
data = json.loads(Path(registry or DEFAULT_REGISTRY).read_text(encoding="utf-8"))
except Exception:
return None
want = region.strip().lower()
for s in data.get("subjects", []):
name = (s.get("name") or "").lower()
if want == name or want in name:
return int(s["code"])
return None
def lookup(code: str, subject_id: int | None = None, kind: str | None = None,
db: Path | str | None = None, registry: Path | str | None = None,
region: str | None = None) -> dict:
if subject_id is None:
subject_id = _resolve_region(region, registry)
if subject_id is None:
return {"status": "region_not_loaded", "base": "региональная",
"message": "регион не распознан", "subject": region}
db = Path(db or os.environ.get("REGIONAL_REF_PATH", str(DEFAULT_DB)))
if not Path(db).is_file():
return {"status": "db_unavailable", "base": "региональная",