Summary
any_to_str(current_task) is called on every agent response in _run_sequential_workflow (line 577) even though agent.run() already returns a string in the common path. Check type first to skip the conversion.
Problem
current_task = agent.run(task=self.conversation.get_str(), img=img)
current_task = any_to_str(current_task) # Redundant when already a string
any_to_str() handles arbitrary types (dicts, lists, objects), but in practice agent.run() returns a string. The extra function call and type inspection on every agent step is wasted work.
Proposed solution
current_task = agent.run(task=self.conversation.get_str(), img=img)
if not isinstance(current_task, str):
current_task = any_to_str(current_task)
Simple isinstance check is near-zero cost and skips the function call overhead in the common case.
Acceptance criteria
Summary
any_to_str(current_task)is called on every agent response in_run_sequential_workflow(line 577) even thoughagent.run()already returns a string in the common path. Check type first to skip the conversion.Problem
any_to_str()handles arbitrary types (dicts, lists, objects), but in practiceagent.run()returns a string. The extra function call and type inspection on every agent step is wasted work.Proposed solution
Simple
isinstancecheck is near-zero cost and skips the function call overhead in the common case.Acceptance criteria
any_to_str()withisinstance(current_task, str)check