refactor: 简化 AgentScope 运行时模块与 prompt 系统

This commit is contained in:
zl-q
2026-03-15 17:14:15 +08:00
parent 61997f3613
commit 072c09d99d
32 changed files with 750 additions and 1863 deletions
+26 -3
View File
@@ -1,6 +1,13 @@
from __future__ import annotations
from typing import Any, Protocol
from typing import TYPE_CHECKING, Any, Protocol, TypeVar
from ag_ui.core import BaseEvent
if TYPE_CHECKING:
pass
T = TypeVar("T", bound=BaseEvent)
class CodecLike(Protocol):
@@ -15,6 +22,16 @@ class BusLike(Protocol):
async def publish(self, *, session_id: str, event: dict[str, Any]) -> str: ...
def is_base_event(event: Any) -> bool:
return isinstance(event, BaseEvent)
def to_dict(event: BaseEvent | dict[str, Any]) -> dict[str, Any]:
if isinstance(event, BaseEvent):
return event.model_dump(by_alias=True, exclude_none=True)
return event
class AgentScopeEventPipeline:
_codec: CodecLike
_store: StoreLike
@@ -25,7 +42,13 @@ class AgentScopeEventPipeline:
self._store = store
self._bus = bus
async def emit(self, *, session_id: str, event: dict[str, Any]) -> str:
wire_event = self._codec.to_wire(event)
async def emit(
self,
*,
session_id: str,
event: "BaseEvent | dict[str, Any]",
) -> str:
event_dict = to_dict(event)
wire_event = self._codec.to_wire(event_dict)
await self._store.persist(wire_event)
return await self._bus.publish(session_id=session_id, event=wire_event)