完成:词典和资讯 API 支持 async 和数据库缓存
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m44s

This commit is contained in:
2026-04-27 17:37:07 +08:00
parent 37ceb6c260
commit f274df6e3d
3 changed files with 161 additions and 16 deletions

View File

@@ -24,7 +24,10 @@ from .agent_subgraphs.common.human_review import (
HumanReview
)
from .agent_subgraphs.contact.api_client import ContactAPIClient
from .agent_subgraphs.dictionary.api_client import DictionaryAPIClient
from .agent_subgraphs.news_analysis.api_client import NewsAPIClient
from .db.init_db import init_subgraph_tables
from .db.models import ContactRepository, DictionaryRepository, NewsRepository
from .logger import info, error
@asynccontextmanager
@@ -42,10 +45,17 @@ async def lifespan(app: FastAPI):
await agent_service.initialize()
# 3. 创建历史查询服务
history_service = ThreadHistoryService(checkpointer)
history_service = ThreadHistoryService(checkpointer.conn)
# 3.5 创建子图 API 客户端(真实数据库模式)
# 3.5 创建子图 Repositories
contact_repo = ContactRepository(checkpointer.conn)
dictionary_repo = DictionaryRepository(checkpointer.conn)
news_repo = NewsRepository(checkpointer.conn)
# 3.6 创建子图 API 客户端(真实数据库模式)
contact_api = ContactAPIClient(checkpointer.conn)
dictionary_api = DictionaryAPIClient(word_repository=dictionary_repo)
news_api = NewsAPIClient(news_repository=news_repo)
# 4. 创建审核管理器
review_manager = ReviewManager(InMemoryReviewStore())
@@ -55,6 +65,11 @@ async def lifespan(app: FastAPI):
app.state.history_service = history_service
app.state.review_manager = review_manager
app.state.contact_api = contact_api
app.state.dictionary_api = dictionary_api
app.state.news_api = news_api
app.state.contact_repo = contact_repo
app.state.dictionary_repo = dictionary_repo
app.state.news_repo = news_repo
# 应用运行中...
yield