refactor: 重构 AgentScope ReAct Runner 与事件处理

- 重构 runtime/runner.py 实现 ReAct Agent 核心逻辑
- 更新事件编码器与存储机制
- 优化 prompt 系统与 tool 调用
- 调整 agent service 与 repository 配合
This commit is contained in:
qzl
2026-03-16 16:10:39 +08:00
parent ab073c88ed
commit 36b104fa37
22 changed files with 1288 additions and 319 deletions
+21 -9
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import time
from collections.abc import Mapping
from typing import Any, cast
from urllib.parse import urlparse
@@ -32,6 +33,11 @@ AUTH_UNAVAILABLE_DETAIL = "Auth service temporarily unavailable"
class SupabaseAuthGateway(AuthServiceGateway):
def __init__(self) -> None:
self._user_lookup_cache_ttl_seconds: int = 60
self._user_lookup_cache_expires_at: float = 0.0
self._users_by_email: dict[str, Any] = {}
def _get_client(self) -> Any:
return supabase_service.get_client()
@@ -185,16 +191,22 @@ class SupabaseAuthGateway(AuthServiceGateway):
async def get_user_by_email(self, email: str) -> UserByEmailResponse:
admin_client = self._get_admin_client()
users = await asyncio.to_thread(_list_auth_users, admin_client)
normalized_email = email.lower()
user = next(
(
candidate
for candidate in users
if str(getattr(candidate, "email", "")).lower() == normalized_email
),
None,
)
now = time.monotonic()
if now >= self._user_lookup_cache_expires_at:
users = await asyncio.to_thread(_list_auth_users, admin_client)
users_by_email: dict[str, Any] = {}
for candidate in users:
candidate_email = str(getattr(candidate, "email", "")).lower()
if candidate_email:
users_by_email[candidate_email] = candidate
self._users_by_email = users_by_email
self._user_lookup_cache_expires_at = (
now + self._user_lookup_cache_ttl_seconds
)
user = self._users_by_email.get(normalized_email)
if user is None:
raise HTTPException(status_code=404, detail="User not found")