refactor(agent): inject deps via context_schema, LLM-driven photo/confirm nodes
- graph.py: LangGraph-native DI - StateGraph(context_schema=GraphDeps), nodes take (state, runtime: Runtime[GraphDeps]); build_graph() decoupled from LLM; deleted scaffold _event_reply/_fake_llm_propose/stub nodes - photo.py: model proposes stage+body via per-mode prompts (direct/addon); validator enforces clientMode exits; deterministic event forcing removed - confirm.py: single runtime for single/dual confirm, extraction call isolated per person_index - llm.py: workflow_fake_llm() (offline workflow-faithful responder, history-aware) for smoke/tests - backend: LangGraphBackend(graph, llm) passes context per call - tests: invoke helpers inject GraphDeps; illegal-proposal test asserts error + state untouched via second well-behaved fake Verified: 143 passed; smoke turns 1/2/1 with original welcome text
This commit is contained in:
@@ -11,15 +11,16 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from src.agent.graph import build_graph
|
||||
from src.agent.graph import GraphDeps, build_graph, workflow_fake_llm
|
||||
|
||||
|
||||
async def ask(graph, thread_id: str, text: str) -> dict:
|
||||
async def ask(graph, thread_id: str, text: str, llm=None) -> dict:
|
||||
# 只传本轮变化的字段;对已有 checkpoint 的 thread 传完整初始状态,
|
||||
# 其中的 turn_count=0 会覆盖已累计的值(LangGraph 输入按通道覆盖)。
|
||||
return await graph.ainvoke(
|
||||
{"session_id": thread_id, "input_text": text},
|
||||
config={"configurable": {"thread_id": thread_id}},
|
||||
context=GraphDeps(llm=llm or workflow_fake_llm()),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user