test_websocket_api.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. import json
  2. import asyncio
  3. import logging
  4. from collections.abc import AsyncIterator
  5. from pathlib import Path
  6. import httpx
  7. import pytest
  8. from fastapi.testclient import TestClient
  9. from pydantic import ValidationError
  10. from agent_lab.application.contracts import AgentParams, DebugRunRequest, EventAgentParams
  11. from agent_lab.application.queues import RuntimeQueues
  12. from agent_lab.application.runtime import DebugRuntime
  13. from agent_lab.domain.events import ToolCallEvent
  14. from agent_lab.domain.messages import ChatMessage, StreamItem
  15. from agent_lab.infrastructure.chat_client import OpenAICompatibleChatClient
  16. from agent_lab.presentation.web import create_app
  17. class FakeRuntime:
  18. def __init__(self) -> None:
  19. self.requests: list[DebugRunRequest] = []
  20. async def run(self, request: DebugRunRequest) -> AsyncIterator[dict]:
  21. self.requests.append(request)
  22. yield {"type": "session_started"}
  23. yield {"type": "message_delta", "content": "hello"}
  24. yield {"type": "done"}
  25. class QueueAwareRuntime:
  26. def __init__(self) -> None:
  27. self.requests: list[DebugRunRequest] = []
  28. self.queues: RuntimeQueues | None = None
  29. self.task: asyncio.Task | None = None
  30. def start(self, request: DebugRunRequest) -> RuntimeQueues:
  31. self.requests.append(request)
  32. self.queues = RuntimeQueues()
  33. self.task = asyncio.create_task(self._run())
  34. return self.queues
  35. async def _run(self) -> None:
  36. assert self.queues is not None
  37. await self.queues.output.put({"type": "session_started"})
  38. message = await self.queues.input.get()
  39. await self.queues.output.put(
  40. {"type": "message_delta", "content": message.content}
  41. )
  42. await self.queues.output.put({"type": "done"})
  43. async def aclose(self) -> None:
  44. if self.task is not None and not self.task.done():
  45. self.task.cancel()
  46. await asyncio.gather(self.task, return_exceptions=True)
  47. def _request_payload() -> dict:
  48. return {
  49. "user_message": "debug this",
  50. "system_prompts": ["You are a debugger."],
  51. "pre_messages": [{"role": "user", "content": "previous turn"}],
  52. "chat_agent": {
  53. "model": "fake-model",
  54. "temperature": 0.1,
  55. "max_tokens": 200,
  56. },
  57. "event_agent": {
  58. "enabled_tools": ["handoff_note"],
  59. "max_event_loops": 2,
  60. },
  61. }
  62. def test_agent_params_defaults_include_extra_body_and_event_agent_defaults_to_one_round():
  63. chat_params = AgentParams()
  64. event_params = EventAgentParams()
  65. assert chat_params.extra_body == {
  66. "thinking": {"type": "disabled"},
  67. "enable_search": False,
  68. "search_options": {"forced_search": False},
  69. }
  70. assert event_params.extra_body == chat_params.extra_body
  71. assert event_params.max_event_loops == 1
  72. assert event_params.system_prompt == ""
  73. def test_health_returns_ok():
  74. app = create_app(runtime_factory=FakeRuntime)
  75. client = TestClient(app)
  76. response = client.get("/health")
  77. assert response.status_code == 200
  78. assert response.json() == {"status": "ok"}
  79. def test_api_tools_returns_handoff_note_metadata():
  80. app = create_app(runtime_factory=FakeRuntime)
  81. client = TestClient(app)
  82. response = client.get("/api/tools")
  83. assert response.status_code == 200
  84. tools = response.json()
  85. assert [tool["name"] for tool in tools] == [
  86. "handoff_note",
  87. "mock_search",
  88. "mock_ticket",
  89. ]
  90. assert tools[0]["parameters"]["required"] == ["message"]
  91. def test_websocket_debug_streams_runtime_messages():
  92. runtime = FakeRuntime()
  93. app = create_app(runtime_factory=lambda: runtime)
  94. client = TestClient(app)
  95. with client.websocket_connect("/ws/debug") as websocket:
  96. websocket.send_json(_request_payload())
  97. assert websocket.receive_json() == {"type": "session_started"}
  98. assert websocket.receive_json() == {
  99. "type": "message_delta",
  100. "content": "hello",
  101. }
  102. assert websocket.receive_json() == {"type": "done"}
  103. assert runtime.requests[0].user_message == "debug this"
  104. assert runtime.requests[0].pre_messages[0].content == "previous turn"
  105. def test_websocket_debug_logs_session_lifecycle(caplog):
  106. runtime = FakeRuntime()
  107. app = create_app(runtime_factory=lambda: runtime)
  108. client = TestClient(app)
  109. with caplog.at_level(logging.INFO, logger="agent_lab.presentation.web"):
  110. with client.websocket_connect("/ws/debug") as websocket:
  111. websocket.send_json(_request_payload())
  112. assert websocket.receive_json() == {"type": "session_started"}
  113. assert websocket.receive_json() == {
  114. "type": "message_delta",
  115. "content": "hello",
  116. }
  117. assert websocket.receive_json() == {"type": "done"}
  118. assert "websocket session accepted" in caplog.text
  119. assert "websocket request accepted" in caplog.text
  120. assert "websocket session closed" in caplog.text
  121. def test_websocket_debug_enqueues_user_messages_during_running_session():
  122. runtime = QueueAwareRuntime()
  123. app = create_app(runtime_factory=lambda: runtime)
  124. client = TestClient(app)
  125. with client.websocket_connect("/ws/debug") as websocket:
  126. websocket.send_json(_request_payload())
  127. assert websocket.receive_json() == {"type": "session_started"}
  128. websocket.send_json({"type": "user_message", "content": "follow-up"})
  129. assert websocket.receive_json() == {
  130. "type": "message_delta",
  131. "content": "follow-up",
  132. }
  133. assert websocket.receive_json() == {"type": "done"}
  134. assert runtime.requests[0].user_message == "debug this"
  135. def test_websocket_debug_sends_error_for_invalid_request():
  136. app = create_app(runtime_factory=FakeRuntime)
  137. client = TestClient(app)
  138. with client.websocket_connect("/ws/debug") as websocket:
  139. websocket.send_json({"chat_agent": {"model": "fake-model"}})
  140. message = websocket.receive_json()
  141. assert message["type"] == "error"
  142. assert "user_message" in message["message"]
  143. def test_debug_run_request_rejects_invalid_pre_message_role():
  144. payload = _request_payload()
  145. payload["pre_messages"] = [{"role": "developer", "content": "invalid"}]
  146. with pytest.raises(ValidationError) as exc_info:
  147. DebugRunRequest.model_validate(payload)
  148. assert "role" in str(exc_info.value)
  149. def test_debug_run_request_rejects_tool_pre_messages():
  150. payload = _request_payload()
  151. payload["pre_messages"] = [
  152. {
  153. "role": "tool",
  154. "content": "orphan result",
  155. "tool_call_id": "call_1",
  156. }
  157. ]
  158. with pytest.raises(ValidationError, match="pre_messages cannot include tool messages"):
  159. DebugRunRequest.model_validate(payload)
  160. def test_chat_message_allows_internal_tool_replies():
  161. message = ChatMessage(
  162. role="tool",
  163. content='{"message":"handled"}',
  164. name="handoff_note",
  165. tool_call_id="call_1",
  166. )
  167. assert message.role == "tool"
  168. assert message.tool_call_id == "call_1"
  169. class HistoryCapturingChatClient:
  170. def __init__(self) -> None:
  171. self.calls = 0
  172. self.second_call_messages: list[ChatMessage] = []
  173. async def stream_chat(
  174. self,
  175. messages: list[ChatMessage],
  176. tools: list[dict],
  177. params: AgentParams,
  178. ) -> AsyncIterator[StreamItem]:
  179. self.calls += 1
  180. if self.calls == 1:
  181. yield StreamItem.message_delta("Need event help.")
  182. yield StreamItem.event(
  183. ToolCallEvent(
  184. id="call_1",
  185. name="handoff_note",
  186. arguments={},
  187. raw_arguments="{}",
  188. )
  189. )
  190. return
  191. self.second_call_messages = list(messages)
  192. yield StreamItem.message_delta("Final answer.")
  193. @pytest.mark.asyncio
  194. async def test_runtime_appends_assistant_message_before_tool_reply_history():
  195. request = DebugRunRequest(
  196. user_message="debug this",
  197. system_prompts=["You are a debugger."],
  198. pre_messages=[],
  199. chat_agent=AgentParams(model="fake-model", temperature=0.1, max_tokens=200),
  200. event_agent=EventAgentParams(enabled_tools=["handoff_note"], max_event_loops=2),
  201. )
  202. client = HistoryCapturingChatClient()
  203. runtime = DebugRuntime(client)
  204. outputs = [message async for message in runtime.run(request)]
  205. assert client.calls == 2
  206. assert [message.role for message in client.second_call_messages] == [
  207. "system",
  208. "user",
  209. "assistant",
  210. "tool",
  211. "user",
  212. ]
  213. assert client.second_call_messages[2].content == "Need event help."
  214. assert client.second_call_messages[4].content.startswith("EventAgent results:\n")
  215. assert outputs[-1] == {"type": "done"}
  216. @pytest.mark.asyncio
  217. async def test_openai_chat_client_streams_sse_chunks_through_parser():
  218. requests: list[httpx.Request] = []
  219. def handler(request: httpx.Request) -> httpx.Response:
  220. requests.append(request)
  221. payload = json.loads(request.content)
  222. assert payload["stream"] is True
  223. assert payload["model"] == "model-x"
  224. assert payload["messages"] == [{"role": "user", "content": "hi"}]
  225. assert payload["tools"][0]["function"]["name"] == "handoff_note"
  226. assert payload["temperature"] == 0.3
  227. assert payload["max_tokens"] == 50
  228. assert request.headers["authorization"] == "Bearer test-key"
  229. return httpx.Response(
  230. 200,
  231. content=(
  232. b'data: {"choices":[{"delta":{"content":"hi"},"finish_reason":null}]}\n\n'
  233. b"data: [DONE]\n\n"
  234. ),
  235. )
  236. async with httpx.AsyncClient(
  237. transport=httpx.MockTransport(handler),
  238. base_url="https://llm.test/v1",
  239. ) as http_client:
  240. client = OpenAICompatibleChatClient(
  241. api_key="test-key",
  242. base_url="https://llm.test/v1",
  243. default_model="default-model",
  244. request_timeout_seconds=5,
  245. http_client=http_client,
  246. )
  247. items = [
  248. item
  249. async for item in client.stream_chat(
  250. messages=[ChatMessage(role="user", content="hi")],
  251. tools=[
  252. {
  253. "type": "function",
  254. "function": {"name": "handoff_note", "parameters": {}},
  255. }
  256. ],
  257. params=AgentParams(model="model-x", temperature=0.3, max_tokens=50),
  258. )
  259. ]
  260. assert requests[0].url.path == "/v1/chat/completions"
  261. assert [item.content for item in items] == ["hi"]
  262. @pytest.mark.asyncio
  263. async def test_openai_chat_client_uses_default_model_when_request_model_is_blank():
  264. captured_payloads: list[dict] = []
  265. def handler(request: httpx.Request) -> httpx.Response:
  266. captured_payloads.append(json.loads(request.content))
  267. return httpx.Response(
  268. 200,
  269. content=b'data: {"choices":[{"delta":{"content":"hi"},"finish_reason":null}]}\n\n',
  270. )
  271. async with httpx.AsyncClient(
  272. transport=httpx.MockTransport(handler),
  273. base_url="https://llm.test/v1",
  274. ) as http_client:
  275. client = OpenAICompatibleChatClient(
  276. api_key="",
  277. base_url="https://llm.test/v1",
  278. default_model="provider-default",
  279. request_timeout_seconds=5,
  280. http_client=http_client,
  281. )
  282. [
  283. item
  284. async for item in client.stream_chat(
  285. messages=[ChatMessage(role="user", content="hi")],
  286. tools=[],
  287. params=AgentParams(model=" ", temperature=0.3, max_tokens=50),
  288. )
  289. ]
  290. assert captured_payloads[0]["model"] == "provider-default"
  291. @pytest.mark.asyncio
  292. async def test_openai_chat_client_serializes_tool_reply_without_name():
  293. captured_payloads: list[dict] = []
  294. assistant_tool_call = {
  295. "id": "call_1",
  296. "type": "function",
  297. "function": {
  298. "name": "handoff_note",
  299. "arguments": '{"message":"inspect"}',
  300. },
  301. }
  302. def handler(request: httpx.Request) -> httpx.Response:
  303. captured_payloads.append(json.loads(request.content))
  304. return httpx.Response(
  305. 200,
  306. content=b'data: {"choices":[{"delta":{"content":"done"},"finish_reason":null}]}\n\n',
  307. )
  308. async with httpx.AsyncClient(
  309. transport=httpx.MockTransport(handler),
  310. base_url="https://llm.test/v1",
  311. ) as http_client:
  312. client = OpenAICompatibleChatClient(
  313. api_key="",
  314. base_url="https://llm.test/v1",
  315. default_model="provider-default",
  316. request_timeout_seconds=5,
  317. http_client=http_client,
  318. )
  319. [
  320. item
  321. async for item in client.stream_chat(
  322. messages=[
  323. ChatMessage(
  324. role="assistant",
  325. content="",
  326. tool_calls=[assistant_tool_call],
  327. ),
  328. ChatMessage(
  329. role="tool",
  330. content="noted",
  331. name="handoff_note",
  332. tool_call_id="call_1",
  333. ),
  334. ],
  335. tools=[],
  336. params=AgentParams(model="provider-default", temperature=0.3, max_tokens=50),
  337. )
  338. ]
  339. assert captured_payloads[0]["messages"] == [
  340. {
  341. "role": "assistant",
  342. "content": "",
  343. "tool_calls": [assistant_tool_call],
  344. },
  345. {
  346. "role": "tool",
  347. "content": "noted",
  348. "tool_call_id": "call_1",
  349. },
  350. ]
  351. @pytest.mark.asyncio
  352. async def test_openai_chat_client_rejects_tool_message_without_tool_call_id_before_network():
  353. network_called = False
  354. def handler(request: httpx.Request) -> httpx.Response:
  355. nonlocal network_called
  356. network_called = True
  357. return httpx.Response(
  358. 200,
  359. content=b'data: {"choices":[{"delta":{"content":"done"},"finish_reason":null}]}\n\n',
  360. )
  361. async with httpx.AsyncClient(
  362. transport=httpx.MockTransport(handler),
  363. base_url="https://llm.test/v1",
  364. ) as http_client:
  365. client = OpenAICompatibleChatClient(
  366. api_key="",
  367. base_url="https://llm.test/v1",
  368. default_model="provider-default",
  369. request_timeout_seconds=5,
  370. http_client=http_client,
  371. )
  372. with pytest.raises(ValueError, match="tool messages require tool_call_id"):
  373. [
  374. item
  375. async for item in client.stream_chat(
  376. messages=[ChatMessage(role="tool", content="orphan tool result")],
  377. tools=[],
  378. params=AgentParams(model="provider-default", temperature=0.3, max_tokens=50),
  379. )
  380. ]
  381. assert network_called is False
  382. def test_static_pre_message_role_selector_does_not_offer_tool():
  383. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  384. assert '<option value="tool">tool</option>' not in html
  385. def test_static_tools_ui_is_dynamic_and_not_hardcoded_to_handoff_note_checkbox():
  386. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  387. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  388. assert 'id="tool-handoff-note"' not in html
  389. assert "#tool-handoff-note" not in js
  390. assert 'id="tool-list"' in html
  391. assert '"/api/tools"' in js
  392. assert "fetch" in js
  393. def test_static_prompt_workspace_controls_are_available():
  394. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  395. assert 'id="prompt-set-name"' in html
  396. assert 'id="saved-prompt-sets"' in html
  397. assert 'id="save-prompt-set"' in html
  398. assert 'id="load-prompt-set"' in html
  399. assert 'id="delete-prompt-set"' in html
  400. def test_static_prompt_workspace_is_opened_from_a_modal():
  401. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  402. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  403. assert 'id="open-prompt-config"' in html
  404. assert '<dialog id="prompt-dialog"' in html
  405. assert 'id="close-prompt-config"' in html
  406. assert "promptDialog.showModal()" in js
  407. assert "promptDialog.close()" in js
  408. def test_static_agent_config_controls_are_aligned_for_chat_and_event_agents():
  409. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  410. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  411. assert '<dialog id="chat-config-dialog"' in html
  412. assert '<dialog id="event-config-dialog"' in html
  413. assert html.count('id="open-chat-config-panel"') == 1
  414. assert html.count('id="open-event-config-panel"') == 1
  415. assert 'id="open-chat-config"' not in html
  416. assert 'id="open-event-config"' not in html
  417. assert '#open-chat-config"' not in js
  418. assert '#open-event-config"' not in js
  419. assert '#open-chat-config-panel"' in js
  420. assert '#open-event-config-panel"' in js
  421. assert 'id="close-chat-config"' in html
  422. assert 'id="close-event-config"' in html
  423. assert "chatConfigDialog.showModal()" in js
  424. assert "eventConfigDialog.showModal()" in js
  425. assert "chatConfigDialog.close()" in js
  426. assert "eventConfigDialog.close()" in js
  427. for control_id in [
  428. "model",
  429. "temperature",
  430. "max-tokens",
  431. "chat-system-prompt",
  432. "chat-thinking-disabled",
  433. "chat-enable-search",
  434. "chat-forced-search",
  435. "event-model",
  436. "event-temperature",
  437. "event-max-tokens",
  438. "event-system-prompt",
  439. "event-thinking-disabled",
  440. "event-enable-search",
  441. "event-forced-search",
  442. ]:
  443. assert f'id="{control_id}"' in html
  444. assert 'extra_body: buildExtraBody("chat")' in js
  445. assert 'extra_body: buildExtraBody("event")' in js
  446. assert 'system_prompt: document.querySelector("#chat-system-prompt")' in js
  447. assert 'system_prompt: document.querySelector("#event-system-prompt")' in js
  448. def test_static_tools_ui_shows_tool_metadata_and_selection_actions():
  449. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  450. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  451. assert 'id="tool-count"' in html
  452. assert 'id="select-all-tools"' in html
  453. assert 'id="clear-tools"' in html
  454. assert "tool-card" in js
  455. assert "tool-description" in js
  456. assert "tool-required" in js
  457. assert "function updateToolCount()" in js
  458. def test_static_app_handles_audit_messages():
  459. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  460. css = Path("src/agent_lab/presentation/static/styles.css").read_text()
  461. assert 'message.type === "audit"' in js
  462. assert 'appendLog("audit"' in js
  463. assert ".audit" in css
  464. def test_static_app_shows_wait_state_and_immediate_user_echo():
  465. html = Path("src/agent_lab/presentation/static/index.html").read_text()
  466. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  467. css = Path("src/agent_lab/presentation/static/styles.css").read_text()
  468. assert 'id="run-button"' in html
  469. assert 'const runButton = document.querySelector("#run-button")' in js
  470. assert 'appendLog("user", submittedMessage)' in js
  471. assert 'statusEl.textContent = "Waiting for first token"' in js
  472. assert "function startElapsedTimer()" in js
  473. assert "function stopElapsedTimer()" in js
  474. assert "function setRunState(" in js
  475. assert "if (firstTokenAt) {\n hasBackendRoundStats = true;" in js
  476. assert "hasBackendRoundStats && firstTokenAt" in js
  477. assert ".user" in css
  478. def test_static_prompt_workspace_uses_stable_storage_hooks():
  479. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  480. assert "agent-lab.prompt-sets.v1" in js
  481. assert "function savePromptSet()" in js
  482. assert "function loadPromptSet()" in js
  483. assert "function deletePromptSet()" in js
  484. def test_static_app_handles_backend_round_stats_messages():
  485. js = Path("src/agent_lab/presentation/static/app.js").read_text()
  486. assert 'message.type === "round_stats"' in js
  487. assert "function updateRoundStats(" in js
  488. assert "#stat-ttft" in js
  489. assert "#stat-elapsed" in js
  490. @pytest.mark.asyncio
  491. async def test_openai_chat_client_omits_stream_options_when_usage_disabled():
  492. captured_payloads: list[dict] = []
  493. def handler(request: httpx.Request) -> httpx.Response:
  494. captured_payloads.append(json.loads(request.content))
  495. return httpx.Response(
  496. 200,
  497. content=b'data: {"choices":[{"delta":{"content":"hi"},"finish_reason":null}]}\n\n',
  498. )
  499. async with httpx.AsyncClient(
  500. transport=httpx.MockTransport(handler),
  501. base_url="https://llm.test/v1",
  502. ) as http_client:
  503. client = OpenAICompatibleChatClient(
  504. api_key="",
  505. base_url="https://llm.test/v1",
  506. default_model="provider-default",
  507. request_timeout_seconds=5,
  508. include_usage=False,
  509. http_client=http_client,
  510. )
  511. [
  512. item
  513. async for item in client.stream_chat(
  514. messages=[ChatMessage(role="user", content="hi")],
  515. tools=[],
  516. params=AgentParams(model="provider-default", temperature=0.3, max_tokens=50),
  517. )
  518. ]
  519. assert "stream_options" not in captured_payloads[0]
  520. @pytest.mark.asyncio
  521. async def test_openai_chat_client_merges_agent_extra_body_into_payload():
  522. captured_payloads: list[dict] = []
  523. def handler(request: httpx.Request) -> httpx.Response:
  524. captured_payloads.append(json.loads(request.content))
  525. return httpx.Response(
  526. 200,
  527. content=b'data: {"choices":[{"delta":{"content":"hi"},"finish_reason":null}]}\n\n',
  528. )
  529. async with httpx.AsyncClient(
  530. transport=httpx.MockTransport(handler),
  531. base_url="https://llm.test/v1",
  532. ) as http_client:
  533. client = OpenAICompatibleChatClient(
  534. api_key="",
  535. base_url="https://llm.test/v1",
  536. default_model="provider-default",
  537. request_timeout_seconds=5,
  538. http_client=http_client,
  539. )
  540. [
  541. item
  542. async for item in client.stream_chat(
  543. messages=[ChatMessage(role="user", content="hi")],
  544. tools=[],
  545. params=AgentParams(
  546. model="provider-default",
  547. temperature=0.3,
  548. max_tokens=50,
  549. extra_body={
  550. "thinking": {"type": "disabled"},
  551. "enable_search": False,
  552. "search_options": {"forced_search": False},
  553. },
  554. ),
  555. )
  556. ]
  557. assert captured_payloads[0]["thinking"] == {"type": "disabled"}
  558. assert captured_payloads[0]["enable_search"] is False
  559. assert captured_payloads[0]["search_options"] == {"forced_search": False}