Skip to content

[feat] Support agent repetition in AgentRearrange flow #1466

@kyegomez

Description

@kyegomez

Summary

Formally support repeating agents in the flow pattern (e.g., agent1 -> agent2 -> agent1) to enable iterative refinement workflows.

Background

The duplicate agent check in validate_flow() is already commented out (agent_rearrange.py lines 330-333):

# # If the length of the agents does not equal the length of the agents in flow
# if len(set(agents_in_flow)) != len(agents_in_flow):
#     raise ValueError(
#         "Duplicate agent names in the flow are not allowed."
#     )

This suggests the feature was considered but not fully implemented. Agent repetition is valuable for patterns like:

  • Iterative refinement: writer -> reviewer -> writer (revise based on feedback)
  • Multi-pass analysis: researcher -> analyst -> researcher -> analyst
  • Self-correction: coder -> tester -> coder

What needs to happen

  1. Ensure conversation context is correct — When an agent appears a second time, it should see its own prior output plus the intermediate agent's feedback, not just re-process the same input.

  2. Update team awareness_get_sequential_awareness() currently finds the first occurrence of an agent name. It should be position-aware so agent1 at step 1 knows it leads to agent2, while agent1 at step 3 knows it follows reviewer.

  3. Response dict handlingresponse_dict[agent_name] = result (line 686) overwrites prior results from the same agent. Use a list or indexed key (e.g., agent1_1, agent1_2).

  4. Document the pattern — Add examples to the docstring and docs showing iterative refinement flows.

Acceptance criteria

  • Flows like agent1 -> agent2 -> agent1 execute without error
  • Each agent invocation gets correct positional awareness
  • All outputs from repeated agents are preserved (not overwritten)
  • Documentation updated with iterative refinement examples
  • Tests cover repeated agent flows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions