50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""One real agent turn on isolated release dev; never prints response content."""
|
|
import json
|
|
import secrets
|
|
import sqlite3
|
|
|
|
import auth
|
|
import db
|
|
import regional_ref
|
|
from scripts.shadow.send import send
|
|
|
|
|
|
def main() -> None:
|
|
email = "release-smoke@local"
|
|
if db.get_user_by_email(email) is None:
|
|
db.create_user(email, auth.hash_password(secrets.token_hex(16)))
|
|
db.admin_verify_user(email)
|
|
db.set_user_agent_access(email, True)
|
|
try:
|
|
with sqlite3.connect(str(regional_ref.DEFAULT_DB)) as regional:
|
|
sample = regional.execute(
|
|
"select s.name, w.code from works w join subjects s "
|
|
"on s.code=w.subject_id where w.kind='ТЕР' and w.price is not null limit 1"
|
|
).fetchone()
|
|
if not sample:
|
|
raise RuntimeError("no regional test sample")
|
|
region, code = sample
|
|
result = send(
|
|
{"tab_id": "release-smoke", "message":
|
|
f"Составь смету на работу по расценке ТЕР {code} в {region}, объём 1 м3."},
|
|
base_url="http://127.0.0.1:8106", token=auth._make_token(email),
|
|
timeout=360,
|
|
)
|
|
with sqlite3.connect("smeta-web.db") as local:
|
|
usage = local.execute(
|
|
"select output_tokens from llm_usage where username=? and path='agent' "
|
|
"order by ts desc limit 1", (email,)
|
|
).fetchone()
|
|
if not result["дошёл"] or not usage or not (usage[0] or 0) > 0:
|
|
raise RuntimeError("agent route did not finish with accounted output")
|
|
print(json.dumps({"agent_done": True, "output_accounted": True,
|
|
"tool_count": len(result["инструменты"]),
|
|
"duration_s": result["длительность_с"]}))
|
|
finally:
|
|
db.soft_delete_user(email)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|