Skip to content

[perf] Drop redundant any_to_str() calls in AgentRearrange #1462

@kyegomez

Description

@kyegomez

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

  • Guard any_to_str() with isinstance(current_task, str) check
  • Existing tests pass unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    FEATNew Feature requestenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions