Skip to content

Refinement in loop

The same agent passes through the text three times, improving each round, and only then a second agent presents the result.

Updated on Sep 02, 2026

Asking "improve this text" once gives an improvement. Asking three times, each one on the previous version, gives something else — it's the same trick as someone rewriting a paragraph until it's good.

The While Loop card repeats a section of the flow while the condition is true, with a safety cap (max_iterations) so no agent runs forever.

How to import

On the platform: Agents → Import, choose the downloaded file. It enters as a new draft (nothing existing is changed), with refreshed observability IDs. Then fill in what belongs to your environment — credentials, URLs, and knowledge bases — and publish.

The file

refine-loop.hinow-agent.jsonjson
{
 "format": "hinow.agent",
 "version": 1,
 "exported_at": "2026-09-01T00:00:00Z",
 "credentials_included": false,
 "agent": {
  "name": "Refinamento em laço",
  "description": "O texto passa três vezes pelo mesmo agente, melhorando a cada rodada, e só depois é apresentado.",
  "avatar": null,
  "model": "hinow/hicode",
  "system_prompt": null,
  "config": {},
  "tools": null,
  "workflow": {
   "nodes": [
    {
     "id": "start",
     "type": "start",
     "position": {
      "x": 300,
      "y": 0
     },
     "data": {
      "label": "Início",
      "variables": []
     }
    },
    {
     "id": "loop-1",
     "type": "while",
     "position": {
      "x": 285,
      "y": 150
     },
     "data": {
      "name": "3 rodadas",
      "loop_condition": "{{round}} <= 3",
      "max_iterations": 4
     }
    },
    {
     "id": "agent-melhora",
     "type": "agent",
     "position": {
      "x": 560,
      "y": 150
     },
     "data": {
      "name": "lapidador",
      "model": "hinow/hicode",
      "system_prompt": "Melhore o texto mais recente da conversa (o do usuário na 1ª vez; depois, a sua última versão): mais claro, mais forte, mais conciso. Responda SÓ com a nova versão, prefixada por 'v{{round}}: '.",
      "config": {}
     }
    },
    {
     "id": "agent-final",
     "type": "agent",
     "position": {
      "x": 275,
      "y": 340
     },
     "data": {
      "name": "apresentador",
      "model": "hinow/hicode",
      "system_prompt": "Apresente a versão final do texto lapidado e, em 1 frase, o que evoluiu desde o original.",
      "config": {}
     }
    },
    {
     "id": "end-1",
     "type": "end",
     "position": {
      "x": 305,
      "y": 500
     },
     "data": {
      "label": "Fim"
     }
    }
   ],
   "edges": [
    {
     "id": "e-start-loop-1-d",
     "source": "start",
     "target": "loop-1"
    },
    {
     "id": "e-loop-1-agent-melhora-loop",
     "source": "loop-1",
     "target": "agent-melhora",
     "sourceHandle": "loop"
    },
    {
     "id": "e-agent-melhora-loop-1-d",
     "source": "agent-melhora",
     "target": "loop-1"
    },
    {
     "id": "e-loop-1-agent-final-exit",
     "source": "loop-1",
     "target": "agent-final",
     "sourceHandle": "exit"
    },
    {
     "id": "e-agent-final-end-1-d",
     "source": "agent-final",
     "target": "end-1"
    }
   ]
  }
 }
}

Card by card

CardWhy it's hereWhat it does
**While Loop**Controlled repetition.Condition {{round}} <= 3 and max_iterations: 4. Two exits: LOOP (repeat) and EXIT (continue).
**Agent polisher**The work that repeats.Improves the last version and prefixes with v{{round}} — you can see the evolution round by round.
**The loop back**It's what closes the cycle.The agent's connection **back** to the While is what makes the next round happen. Without it, the loop runs only once.
**Agent presenter**Separate iterating from delivering.Exits via EXIT and presents the final version, saying in one sentence what evolved.

Always with a cap

max_iterations is the safety belt: if the condition never becomes false (variable that doesn't increment, poorly written condition), it's what stops the loop. A loop without a cap is the fastest way to burn tokens.

How to adapt to your case

  • Until it passes the criterion, not until count 3: swap the condition for a variable that an evaluator agent sets ({{approved}} == false) — the loop stops when quality arrives, not when the counter runs out.
  • Reprocess a queue: the loop consumes a collection declared at Start, one item per round.
  • Retry with backoff: a loop around a Webhook that sometimes fails, with the agent deciding whether to try again.

All ready-made flows

Other complete agents to import and adapt.