@@ -105,7 +105,8 @@ def _merge_reusable_task(
105105 if reusable_doc is None :
106106 raise ValueError (f"No such reusable taskflow: { task .uses } " )
107107 if len (reusable_doc .taskflow ) > 1 :
108- raise ValueError ("Reusable taskflows can only contain 1 task" )
108+ msg = "Reusable taskflows can only contain 1 task"
109+ raise ValueError (msg )
109110 parent_task = reusable_doc .taskflow [0 ].task
110111 merged : dict [str , Any ] = parent_task .model_dump (by_alias = True , exclude_defaults = True )
111112 current : dict [str , Any ] = task .model_dump (by_alias = True , exclude_defaults = True )
@@ -198,14 +199,16 @@ async def _build_prompts_to_run(
198199 raise
199200 except json .JSONDecodeError as exc :
200201 logging .critical (f"Could not parse tool result as JSON: { last_mcp_tool_results [- 1 ][:200 ]} " )
201- raise ValueError ("Tool result is not valid JSON" ) from exc
202+ msg = "Tool result is not valid JSON"
203+ raise ValueError (msg ) from exc
202204
203205 text = last_result .get ("text" , "" )
204206 try :
205207 iterable_result = json .loads (text )
206208 except json .JSONDecodeError as exc :
207209 logging .critical (f"Could not parse result text: { text } " )
208- raise ValueError ("Result text is not valid JSON" ) from exc
210+ msg = "Result text is not valid JSON"
211+ raise ValueError (msg ) from exc
209212 try :
210213 iter (iterable_result )
211214 except TypeError :
@@ -403,7 +406,8 @@ async def _run_streamed() -> None:
403406 max_retry -= 1
404407 except RateLimitError :
405408 if rate_limit_backoff == MAX_RATE_LIMIT_BACKOFF :
406- raise APITimeoutError ("Max rate limit backoff reached" )
409+ msg = "Max rate limit backoff reached"
410+ raise APITimeoutError (msg )
407411 if rate_limit_backoff > MAX_RATE_LIMIT_BACKOFF :
408412 rate_limit_backoff = MAX_RATE_LIMIT_BACKOFF
409413 else :
@@ -556,7 +560,8 @@ async def on_handoff_hook(context: RunContextWrapper[TContext], agent: Agent[TCo
556560 inputs = task .inputs or {}
557561 task_prompt = task .user_prompt or ""
558562 if run and task_prompt :
559- raise ValueError ("shell task and prompt task are mutually exclusive!" )
563+ msg = "shell task and prompt task are mutually exclusive!"
564+ raise ValueError (msg )
560565 must_complete = task .must_complete
561566 max_turns = task .max_steps or DEFAULT_MAX_TURNS
562567 toolboxes_override = task .toolboxes or []
@@ -615,10 +620,11 @@ async def run_prompts(async_task: bool = False, max_concurrent_tasks: int = 5) -
615620 resolved_agents [agent_name ] = personality
616621
617622 if not resolved_agents :
618- raise ValueError (
623+ msg = (
619624 "No agents resolved for this task. "
620625 "Specify a personality with -p or provide an agents list."
621626 )
627+ raise ValueError (msg )
622628
623629 async def _deploy (ra : dict , pp : str ) -> bool :
624630 async with semaphore :
0 commit comments