@@ -143,6 +143,77 @@ def test_generation_config_thinking_config_used_when_think_is_none(self):
143143
144144class TestJudgeAgentPlanner :
145145
146+ @pytest .mark .asyncio
147+ async def test_judge_agent_closes_its_agent_run (self ):
148+ captured = {"closed" : False }
149+
150+ class _FakeAgentRun :
151+
152+ def __aiter__ (self ):
153+ return self
154+
155+ async def __anext__ (self ):
156+ raise StopAsyncIteration
157+
158+ async def aclose (self ):
159+ captured ["closed" ] = True
160+
161+ agent_run = _FakeAgentRun ()
162+
163+ class _FakeLlmAgent :
164+
165+ def __init__ (self , ** kwargs ):
166+ pass
167+
168+ def run_async (self , ctx ):
169+ return agent_run
170+
171+ class _FakeInvocationContext :
172+
173+ def __init__ (self , ** kwargs ):
174+ pass
175+
176+ with patch ("trpc_agent_sdk.evaluation._llm_judge.LlmAgent" , _FakeLlmAgent ), patch (
177+ "trpc_agent_sdk.evaluation._llm_judge.InvocationContext" , _FakeInvocationContext ):
178+ judge = _JudgeAgent (
179+ model = object (),
180+ config = None ,
181+ system_prompt = "sp" ,
182+ )
183+ await judge .get_response ("evaluate this response" )
184+
185+ assert captured ["closed" ] is True
186+
187+ @pytest .mark .asyncio
188+ async def test_judge_agent_disables_model_streaming (self ):
189+ captured : dict [str , Any ] = {}
190+
191+ class _FakeLlmAgent :
192+
193+ def __init__ (self , ** kwargs ):
194+ captured .update (kwargs )
195+
196+ async def run_async (self , ctx ):
197+ captured ["run_config" ] = ctx .run_config
198+ if False : # pragma: no cover - makes this an async generator
199+ yield None
200+
201+ class _FakeInvocationContext :
202+
203+ def __init__ (self , ** kwargs ):
204+ self .run_config = kwargs ["run_config" ]
205+
206+ with patch ("trpc_agent_sdk.evaluation._llm_judge.LlmAgent" , _FakeLlmAgent ), patch (
207+ "trpc_agent_sdk.evaluation._llm_judge.InvocationContext" , _FakeInvocationContext ):
208+ judge = _JudgeAgent (
209+ model = object (),
210+ config = None ,
211+ system_prompt = "sp" ,
212+ )
213+ await judge .get_response ("evaluate this response" )
214+
215+ assert captured ["run_config" ].streaming is False
216+
146217 def test_judge_agent_accepts_planner_and_forwards_to_llm_agent (self ):
147218 captured : dict [str , Any ] = {}
148219
0 commit comments