Python: [错误]: AG-UI 将排队批准流中的工具结果都显示出来,但最终快照会丢弃第一个结果
"""Local AG-UI queued-result snapshot reproduction; no model/API calls."""
import asyncio import json from typing import Any from agent_framework import ( Agent, BaseChatClient, ChatResponse, ChatResponseUpdate, Content, FunctionTool, ToolApprovalMiddleware, ) from agent_framework._middleware import ChatMiddlewareLayer from agent_framework._tools import FunctionInvocationLayer from agent_framework._types import ResponseStream from agent_framework.observability import ChatTelemetryLayer from agent_framework_ag_ui import ( AgentFrameworkAgent, InMemoryAGUIThreadSnapshotStore, add_agent_framework_fastapi_endpoint, ) from fastapi import FastAPI from fastapi.testclient import TestClient
class ScriptedClient(FunctionInvocationLayer, ChatMiddlewareLayer, ChatTelemetryLayer, BaseChatClient): def init(self) -> None: super().init(middleware=[]) self.calls = 0 self.input_results: list[list[str]] = []
def _inner_get_response(
self, *, messages: Any, stream: bool = False, options: Any, **kwargs: Any
) -> ResponseStream:
assert stream
self.input_results.append([c.call_id for m in messages for c in m.contents if c.type == "function_result"])
return ResponseStream(self.updates(), finalizer=ChatResponse.from_updates)
async def updates(self):
self.calls += 1
contents = [
…
内容来源: microsoft/agent-framework