Skip to content

Commit 6635272

Browse files
authored
De-flake Prefect test by enforcing sequential tool calls for test (#3177)
1 parent db13fd0 commit 6635272

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/test_prefect.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ async def test_complex_agent_run_in_flow(allow_model_requests: None, capfire: Ca
208208

209209
@flow(name='test_complex_agent_run_in_flow')
210210
async def run_complex_agent() -> Response:
211-
result = await complex_prefect_agent.run(
212-
'Tell me: the capital of the country; the weather there; the product name', deps=Deps(country='Mexico')
213-
)
211+
# Use sequential tool calls to avoid flaky test due to non-deterministic ordering
212+
with Agent.sequential_tool_calls():
213+
result = await complex_prefect_agent.run(
214+
'Tell me: the capital of the country; the weather there; the product name', deps=Deps(country='Mexico')
215+
)
214216
return result.output
215217

216218
# Prefect sets the `traceparent` header, so we explicitly disable distributed tracing for the tests to avoid the warning,
@@ -364,9 +366,12 @@ async def run_complex_agent() -> Response:
364366
content='running 2 tools',
365367
children=[
366368
BasicSpan(
367-
content='running tool: get_product_name',
369+
content='running tool: get_weather',
368370
children=[
369-
BasicSpan(content=IsStr(regex=r'Call MCP Tool: get_product_name-\w+'))
371+
BasicSpan(
372+
content=IsStr(regex=r'Call Tool: get_weather-\w+'),
373+
children=[BasicSpan(content=IsStr(regex=r'get_weather-\w+'))],
374+
)
370375
],
371376
),
372377
BasicSpan(
@@ -375,18 +380,15 @@ async def run_complex_agent() -> Response:
375380
BasicSpan(content='ctx.run_step=2'),
376381
BasicSpan(
377382
content=IsStr(
378-
regex=r'\{"result":\{"tool_name":"get_product_name","content":"Pydantic AI","tool_call_id":"call_SkGkkGDvHQEEk0CGbnAh2AQw","metadata":null,"timestamp":"[^"]+","part_kind":"tool-return"\},"content":null,"event_kind":"function_tool_result"\}'
383+
regex=r'\{"result":\{"tool_name":"get_weather","content":"sunny","tool_call_id":"call_NS4iQj14cDFwc0BnrKqDHavt","metadata":null,"timestamp":"[^"]+","part_kind":"tool-return"\},"content":null,"event_kind":"function_tool_result"\}'
379384
)
380385
),
381386
],
382387
),
383388
BasicSpan(
384-
content='running tool: get_weather',
389+
content='running tool: get_product_name',
385390
children=[
386-
BasicSpan(
387-
content=IsStr(regex=r'Call Tool: get_weather-\w+'),
388-
children=[BasicSpan(content=IsStr(regex=r'get_weather-\w+'))],
389-
)
391+
BasicSpan(content=IsStr(regex=r'Call MCP Tool: get_product_name-\w+'))
390392
],
391393
),
392394
BasicSpan(
@@ -395,7 +397,7 @@ async def run_complex_agent() -> Response:
395397
BasicSpan(content='ctx.run_step=2'),
396398
BasicSpan(
397399
content=IsStr(
398-
regex=r'\{"result":\{"tool_name":"get_weather","content":"sunny","tool_call_id":"call_NS4iQj14cDFwc0BnrKqDHavt","metadata":null,"timestamp":"[^"]+","part_kind":"tool-return"\},"content":null,"event_kind":"function_tool_result"\}'
400+
regex=r'\{"result":\{"tool_name":"get_product_name","content":"Pydantic AI","tool_call_id":"call_SkGkkGDvHQEEk0CGbnAh2AQw","metadata":null,"timestamp":"[^"]+","part_kind":"tool-return"\},"content":null,"event_kind":"function_tool_result"\}'
399401
)
400402
),
401403
],

0 commit comments

Comments
 (0)