@@ -2231,7 +2231,7 @@ def test_agent_concurrent_call_raises_exception():
22312231 {"role" : "assistant" , "content" : [{"text" : "world" }]},
22322232 ]
22332233 )
2234- agent = Agent (model = model )
2234+ agent = Agent (model = model , concurrent_invocation_mode = "throw" )
22352235
22362236 results = []
22372237 errors = []
@@ -2282,7 +2282,7 @@ def test_agent_concurrent_structured_output_raises_exception():
22822282 {"role" : "assistant" , "content" : [{"text" : "response2" }]},
22832283 ],
22842284 )
2285- agent = Agent (model = model )
2285+ agent = Agent (model = model , concurrent_invocation_mode = "throw" )
22862286
22872287 results = []
22882288 errors = []
@@ -2362,53 +2362,6 @@ def invoke():
23622362 assert len (results ) == 2 , f"Expected 2 successes, got { len (results )} "
23632363
23642364
2365- def test_agent_concurrent_invocation_mode_throw_raises_exception ():
2366- """Test that concurrent_invocation_mode='throw' maintains the default behavior."""
2367- model = SyncEventMockedModel (
2368- [
2369- {"role" : "assistant" , "content" : [{"text" : "hello" }]},
2370- {"role" : "assistant" , "content" : [{"text" : "world" }]},
2371- ]
2372- )
2373- # Explicit throw mode should behave same as default
2374- agent = Agent (model = model , concurrent_invocation_mode = "throw" )
2375-
2376- results = []
2377- errors = []
2378- lock = threading .Lock ()
2379-
2380- def invoke ():
2381- try :
2382- result = agent ("test" )
2383- with lock :
2384- results .append (result )
2385- except ConcurrencyException as e :
2386- with lock :
2387- errors .append (e )
2388-
2389- # Start first thread and wait for it to begin streaming
2390- t1 = threading .Thread (target = invoke )
2391- t1 .start ()
2392- model .started_event .wait () # Wait until first thread is in the model.stream()
2393-
2394- # Start second thread while first is still running
2395- t2 = threading .Thread (target = invoke )
2396- t2 .start ()
2397-
2398- # Give second thread time to attempt invocation and fail
2399- t2 .join (timeout = 1.0 )
2400-
2401- # Now let first thread complete
2402- model .proceed_event .set ()
2403- t1 .join ()
2404- t2 .join ()
2405-
2406- # One should succeed, one should raise ConcurrencyException
2407- assert len (results ) == 1 , f"Expected 1 success, got { len (results )} "
2408- assert len (errors ) == 1 , f"Expected 1 error, got { len (errors )} "
2409- assert "concurrent" in str (errors [0 ]).lower () and "invocation" in str (errors [0 ]).lower ()
2410-
2411-
24122365def test_agent_concurrent_invocation_mode_default_is_throw ():
24132366 """Test that the default concurrent_invocation_mode is 'throw'."""
24142367 model = MockedModelProvider ([{"role" : "assistant" , "content" : [{"text" : "hello" }]}])
0 commit comments