fix: chat stream 走 regulatory agent 支持工具调用,修复 workflow ValidationError
1. chat.py stream 端点改为调用 regulatory_node.stream_working()(pydantic-ai run_stream),支持工具调用 + 逐 token 流式输出 2. regulatory_node 新增 stream_working 方法,通过 asyncio.Queue 推送 token 3. ConsciousnessNodeDeps.available_skills 加默认值 None,修复 ForWorkflowInput/ ForregulatoryInput 路径的 ValidationError Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,7 @@ class ConsciousnessNodeDeps(DepsModel):
|
||||
"""ConsciousnessNode 在 pydantic-ai Agent 中使用的依赖:原始指令、当前指令以及可用 Skill 列表。"""
|
||||
original_command: str
|
||||
command: str
|
||||
available_skills: Optional[List[str]]
|
||||
available_skills: Optional[List[str]] = None
|
||||
|
||||
class ConsciousnessNodeInput(RequestModel):
|
||||
"""ConsciousnessNode 各类入参的共同基类,仅用于打 schema 标签。"""
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import asyncio
|
||||
import datetime
|
||||
from typing import Union
|
||||
from kilostar.utils.standalone_proxy import actor_class
|
||||
@@ -125,6 +126,37 @@ class RegulatoryNode:
|
||||
"""
|
||||
return await self._run(payload)
|
||||
|
||||
async def stream_working(self, payload: MessageRequest, token_queue: "asyncio.Queue") -> None:
|
||||
"""流式工具调用版本:逐 token 推送到 queue,工具调用结果也会通过 token 输出。
|
||||
|
||||
完成后 push None 作为终止信号。
|
||||
"""
|
||||
platform = payload.platform
|
||||
user_name = payload.user_name
|
||||
message = payload.message
|
||||
time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
if self.agent is None:
|
||||
await token_queue.put(None)
|
||||
return
|
||||
|
||||
try:
|
||||
deps = RegulatoryNodeDeps(
|
||||
platform=platform,
|
||||
user_name=user_name,
|
||||
time=time_str
|
||||
)
|
||||
async with self.agent.run_stream(
|
||||
user_prompt=message, deps=deps, output_type=str
|
||||
) as stream_result:
|
||||
async for delta in stream_result.stream_text(delta=True):
|
||||
await token_queue.put(delta)
|
||||
except Exception as e:
|
||||
self.logger.exception(f"RegulatoryNode.stream_working failed: {e}")
|
||||
await token_queue.put(f"\n\n[错误: {str(e)}]")
|
||||
finally:
|
||||
await token_queue.put(None)
|
||||
|
||||
async def _run(
|
||||
self, payload: MessageRequest
|
||||
) -> Union[MessageResponse, None]:
|
||||
|
||||
Reference in New Issue
Block a user