Feat: enhance webhook response to include status and success fields and simplify ReAct agent (#12091)

### What problem does this PR solve?

change:
enhance webhook response to include status and success fields and
simplify ReAct agent

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
buua436
2025-12-23 09:36:08 +08:00
committed by GitHub
parent bd76b8ff1a
commit 1444de981c
3 changed files with 189 additions and 15 deletions

View File

@ -326,7 +326,6 @@ async def webhook(agent_id: str):
secret = jwt_cfg.get("secret")
if not secret:
raise Exception("JWT secret not configured")
required_claims = jwt_cfg.get("required_claims", [])
auth_header = request.headers.get("Authorization", "")
if not auth_header.startswith("Bearer "):
@ -750,7 +749,7 @@ async def webhook(agent_id: str):
async def sse():
nonlocal canvas
contents: list[str] = []
status = 200
try:
async for ans in canvas.run(
query="",
@ -765,6 +764,8 @@ async def webhook(agent_id: str):
content = "</think>"
if content:
contents.append(content)
if ans["event"] == "message_end":
status = int(ans["data"].get("status", status))
if is_test:
append_webhook_trace(
agent_id,
@ -782,7 +783,11 @@ async def webhook(agent_id: str):
}
)
final_content = "".join(contents)
yield json.dumps(final_content, ensure_ascii=False)
return {
"message": final_content,
"success": True,
"code": status,
}
except Exception as e:
if is_test:
@ -804,10 +809,14 @@ async def webhook(agent_id: str):
"success": False,
}
)
yield json.dumps({"code": 500, "message": str(e)}, ensure_ascii=False)
return {"code": 400, "message": str(e),"success":False}
resp = Response(sse(), mimetype="application/json")
return resp
result = await sse()
return Response(
json.dumps(result),
status=result["code"],
mimetype="application/json",
)
@manager.route("/webhook_trace/<agent_id>", methods=["GET"]) # noqa: F821