feat: improve agent workflow observability

This commit is contained in:
2026-06-14 14:46:24 +08:00
parent c293cb5e3b
commit 3f75c966c2
7 changed files with 187 additions and 11 deletions
+17 -2
View File
@@ -422,8 +422,23 @@ async def publish_agent(agent_id: str, db: AsyncSession = Depends(get_db)):
# 验证必要配置
if agent.mode == "autonomous":
if not agent.model_id:
raise HTTPException(status_code=400, detail="请先配置模型")
if agent.model_id:
model_result = await db.execute(
select(LLMModel).where(
LLMModel.id == agent.model_id,
LLMModel.is_deleted == False,
)
)
model = model_result.scalar_one_or_none()
if not model:
raise HTTPException(status_code=400, detail="模型不存在")
if not model.is_active:
raise HTTPException(status_code=400, detail="模型已禁用")
elif not await _resolve_default_chat_model_id(db):
raise HTTPException(
status_code=400,
detail="请先在模型配置中启用一个 chat 模型,或为智能体指定模型",
)
elif agent.mode == "dialog_flow":
if not agent.workflow_id:
raise HTTPException(status_code=400, detail="对话流模式需要配置工作流")
@@ -582,6 +582,9 @@ class AgentService:
'type': 'complete',
'elapsed_time': elapsed_time,
'tokens_used': total_tokens,
'total_tokens': total_tokens,
'conversation_id': str(conversation.id),
'message_id': str(assistant_msg.id),
}
except Exception as e: