落地并存测服全端:智能体 Graph/路由、后台切 8180、主账与部署脚本齐备,便于线上重发与验收。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
智能体唯一 Worker 入口(LLM / 识别 / 报价 PDF / 存档)。
|
||||
|
||||
本文件职责:组装分槽运行时并阻塞至进程结束;不在此写各业务 Handler。
|
||||
禁止:Redis wecom:worker:singleton;禁止五进程拆分;禁止在 HTTP 回调里跑本模块逻辑。
|
||||
本文件职责:组装分槽、Graph、Redis、LLM 网关;阻塞至进程结束。
|
||||
禁止:Redis wecom:worker:singleton;禁止在 HTTP 回调里跑本模块逻辑。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,26 +12,34 @@ import signal
|
||||
import threading
|
||||
|
||||
from agent.config import get_settings
|
||||
from agent.graph import get_graph_runtime, shutdown_graph_runtime
|
||||
from agent.jobs import WorkerRuntime
|
||||
from agent.llm import LlmGateway
|
||||
from agent.redis_coord import get_redis_runtime, shutdown_redis_runtime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
启动 Worker 槽与 inbox/outbox 占位线程,主线程等待停止信号。
|
||||
启动 Worker:wake Stream + LLM Stream + LibreOffice 槽。
|
||||
|
||||
副作用:创建后台线程;骨架不消费真实队列、不连库。
|
||||
并发:LibreOffice 1 槽;HTTP 类至少 2~3 槽;与 inbox/outbox 隔离。
|
||||
Graph resume/wake 仅走 http_jobs 槽。
|
||||
"""
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
|
||||
)
|
||||
settings = get_settings()
|
||||
graph_runtime = get_graph_runtime(settings)
|
||||
redis_runtime = get_redis_runtime(settings)
|
||||
llm = LlmGateway.from_settings(settings)
|
||||
runtime = WorkerRuntime.from_settings(
|
||||
libreoffice_slots=settings.libreoffice_slots,
|
||||
http_job_slots=settings.http_job_slots,
|
||||
settings.libreoffice_slots,
|
||||
settings.http_job_slots,
|
||||
graph=graph_runtime,
|
||||
redis=redis_runtime,
|
||||
llm=llm,
|
||||
)
|
||||
runtime.start()
|
||||
|
||||
@@ -40,12 +48,19 @@ def main() -> None:
|
||||
def _handle_signal(signum: int, _frame: object) -> None:
|
||||
logger.info("收到停止信号 signum=%s", signum)
|
||||
runtime.stop()
|
||||
shutdown_graph_runtime()
|
||||
shutdown_redis_runtime()
|
||||
stop_event.set()
|
||||
|
||||
signal.signal(signal.SIGINT, _handle_signal)
|
||||
signal.signal(signal.SIGTERM, _handle_signal)
|
||||
|
||||
logger.info("Worker 骨架运行中 ytd_env=%s(Ctrl+C 退出)", settings.ytd_env)
|
||||
logger.info(
|
||||
"Worker 运行中 ytd_env=%s checkpoint=%s redis=%s(Ctrl+C 退出)",
|
||||
settings.ytd_env,
|
||||
graph_runtime.checkpoint.backend,
|
||||
redis_runtime.client.backend,
|
||||
)
|
||||
stop_event.wait()
|
||||
logger.info("Worker 已退出")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user