#!/usr/bin/env python3 # -*- coding: utf-8 -*- """专题十二 · 步骤 2:核对 Agent 活动快照与草稿 max_tokens(应对上 error 里的数字)。""" from __future__ import annotations import sys import _bootstrap # noqa: F401 import _config as C from dify_api import Dify def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: d.login() snap_sql = ( "docker exec %s psql -U postgres -d dify -c " "\"SELECT s.id, s.version, " "s.config_snapshot::json -> 'model' -> 'model_settings' -> 'max_tokens' AS max_tokens " "FROM agent_config_snapshots s JOIN agents a ON s.agent_id = a.id " "WHERE a.app_id = '%s' ORDER BY s.version DESC;\"" % (C.PG_CONTAINER, C.APP_ID) ) out1, _ = d.sh(snap_sql) print("=== 活动快照 ===") print(out1.strip()) draft_sql = ( "docker exec %s psql -U postgres -d dify -c " "\"SELECT id, config_snapshot::json -> 'model' -> 'model_settings' -> 'max_tokens' " "AS max_tokens FROM agent_config_drafts WHERE agent_id = '%s' " "ORDER BY updated_at DESC NULLS LAST;\"" % (C.PG_CONTAINER, C.AGENT_ID) ) out2, _ = d.sh(draft_sql) print("\n=== 编辑草稿 ===") print(out2.strip()) return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())