feat: add stateful responses API

This commit is contained in:
Xin Wang
2026-09-07 00:15:32 +08:00
parent ab409ba9c0
commit 43f2cc445e
22 changed files with 2461 additions and 5 deletions
+29
View File
@@ -315,6 +315,35 @@ class DifyLLMServiceTests(unittest.IsolatedAsyncioTestCase):
class PromptBrainTests(unittest.IsolatedAsyncioTestCase):
async def test_responses_state_skips_completed_prompt_startup(self):
cfg = AssistantConfig(type="prompt")
brain = build_brain(cfg)
brain.restore_text_state(
{
"type": "prompt",
"preflight_finished": True,
"opening_finished": True,
"entry_dispatched": True,
}
)
await brain.setup(
cfg,
BrainRuntime(
context=LLMContext(messages=[]),
llm=FakeLLM(),
queue_frame=noop_queue_frame,
set_system_prompt=lambda _prompt: None,
set_tools=lambda _tools: None,
call_end=FakeCallEnd(),
),
)
self.assertTrue(brain._preflight_finished)
self.assertTrue(brain._opening_finished)
self.assertTrue(brain._entry_dispatched)
self.assertEqual(brain.text_state_snapshot()["type"], "prompt")
async def test_startup_only_tool_is_not_registered_with_llm(self):
startup_tool = RuntimeTool(
id="opening_message",