feat: 引入 Loguru
This commit is contained in:
+20
-3
@@ -3,6 +3,7 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from langgraph.types import Command
|
||||
from loguru import logger
|
||||
|
||||
from app.core.exceptions import BizException
|
||||
from app.observability.tracing import ainvoke_screen
|
||||
@@ -68,10 +69,26 @@ class AgentService:
|
||||
self._active.discard(thread_id)
|
||||
|
||||
async def _execute(self, thread_id, payload, session_id) -> AgentResult:
|
||||
state = await ainvoke_screen(
|
||||
self.graph, payload, thread_id=thread_id, session_id=session_id
|
||||
)
|
||||
# 上下文只作用于当前异步任务,节点自动继承任务标识
|
||||
with logger.contextualize(thread_id=thread_id):
|
||||
logger.info("任务执行开始")
|
||||
try:
|
||||
state = await ainvoke_screen(
|
||||
self.graph, payload, thread_id=thread_id, session_id=session_id
|
||||
)
|
||||
except Exception as exc:
|
||||
# API 异常处理发生在上下文退出后,保留任务标识用于定位
|
||||
exc._agent_thread_id = thread_id
|
||||
raise
|
||||
logger.info(
|
||||
"任务执行结束,状态 {}",
|
||||
"waiting_for_input"
|
||||
if state.get("__interrupt__")
|
||||
else state.get("status"),
|
||||
)
|
||||
|
||||
waiting = bool(state.get("__interrupt__"))
|
||||
|
||||
# 只交付校验通过的完整动作批次,失败草稿留在后端
|
||||
return AgentResult(
|
||||
thread_id=thread_id,
|
||||
|
||||
Reference in New Issue
Block a user