@@ -30,12 +30,15 @@ def get_weather(params: WeatherParams, invocation: ToolInvocation) -> ToolResult
3030 on_permission_request = PermissionHandler .approve_all , tools = [get_weather ]
3131 )
3232
33- await session .send ("What's the weather in Paris?" )
34- assistant_message = await get_final_assistant_message (session )
35- assert (
36- "sunny" in assistant_message .data .content .lower ()
37- or "72" in assistant_message .data .content
38- )
33+ try :
34+ await session .send ("What's the weather in Paris?" )
35+ assistant_message = await get_final_assistant_message (session )
36+ assert (
37+ "sunny" in assistant_message .data .content .lower ()
38+ or "72" in assistant_message .data .content
39+ )
40+ finally :
41+ await session .disconnect ()
3942
4043 async def test_should_handle_tool_result_with_failure_resulttype (self , ctx : E2ETestContext ):
4144 @define_tool ("check_status" , description = "Checks the status of a service" )
@@ -50,12 +53,15 @@ def check_status(invocation: ToolInvocation) -> ToolResult:
5053 on_permission_request = PermissionHandler .approve_all , tools = [check_status ]
5154 )
5255
53- answer = await session .send_and_wait (
54- "Check the status of the service using check_status."
55- " If it fails, say 'service is down'."
56- )
57- assert answer is not None
58- assert "service is down" in answer .data .content .lower ()
56+ try :
57+ answer = await session .send_and_wait (
58+ "Check the status of the service using check_status."
59+ " If it fails, say 'service is down'."
60+ )
61+ assert answer is not None
62+ assert "service is down" in answer .data .content .lower ()
63+ finally :
64+ await session .disconnect ()
5965
6066 async def test_should_preserve_tooltelemetry_and_not_stringify_structured_results_for_llm (
6167 self , ctx : E2ETestContext
@@ -78,14 +84,19 @@ def analyze_code(params: AnalyzeParams, invocation: ToolInvocation) -> ToolResul
7884 on_permission_request = PermissionHandler .approve_all , tools = [analyze_code ]
7985 )
8086
81- await session .send ("Analyze the file main.ts for issues." )
82- assistant_message = await get_final_assistant_message (session )
83- assert "no issues" in assistant_message .data .content .lower ()
84-
85- # Verify the LLM received just textResultForLlm, not stringified JSON
86- traffic = await ctx .get_exchanges ()
87- last_conversation = traffic [- 1 ]
88- tool_results = [m for m in last_conversation ["request" ]["messages" ] if m ["role" ] == "tool" ]
89- assert len (tool_results ) == 1
90- assert "toolTelemetry" not in tool_results [0 ]["content" ]
91- assert "resultType" not in tool_results [0 ]["content" ]
87+ try :
88+ await session .send ("Analyze the file main.ts for issues." )
89+ assistant_message = await get_final_assistant_message (session )
90+ assert "no issues" in assistant_message .data .content .lower ()
91+
92+ # Verify the LLM received just textResultForLlm, not stringified JSON
93+ traffic = await ctx .get_exchanges ()
94+ last_conversation = traffic [- 1 ]
95+ tool_results = [
96+ m for m in last_conversation ["request" ]["messages" ] if m ["role" ] == "tool"
97+ ]
98+ assert len (tool_results ) == 1
99+ assert "toolTelemetry" not in tool_results [0 ]["content" ]
100+ assert "resultType" not in tool_results [0 ]["content" ]
101+ finally :
102+ await session .disconnect ()
0 commit comments