All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m41s
主要变更: - 简化 agent_service:移除复杂双协程,只用 stream_mode=["updates"] - stream_context:提供更清晰的 API (set_stream_queue/get_stream_queue) - main_graph_builder:简化图结构,移除 tools 节点和条件边 - agent 节点:包含完整 ReAct 循环 + 流式 Tool Calling 拼接 - 前端:适配新的事件格式 - 添加测试文件:test_full_react_streaming.py, test_stream.py
23 lines
630 B
Python
23 lines
630 B
Python
"""
|
||
流式上下文,用于在 LangGraph 节点和 agent_service 之间传递 token 队列
|
||
清晰的 API,更易用!
|
||
"""
|
||
import contextvars
|
||
import asyncio
|
||
from typing import Optional, Any
|
||
|
||
# 上下文变量:存储每个请求专属的 token 队列
|
||
stream_queue_ctx: contextvars.ContextVar[Optional[asyncio.Queue]] = contextvars.ContextVar(
|
||
"stream_queue", default=None
|
||
)
|
||
|
||
|
||
def set_stream_queue(queue: asyncio.Queue) -> None:
|
||
"""设置当前请求的队列"""
|
||
stream_queue_ctx.set(queue)
|
||
|
||
|
||
def get_stream_queue() -> Optional[asyncio.Queue]:
|
||
"""获取当前请求的队列"""
|
||
return stream_queue_ctx.get()
|