Free Intro Class
    Botspot Logo

    agenthub · agent.loop

    Agent Loop

    Give the model a goal and let it work. It plans, calls the tools bound to it, reads the results and keeps going — saving its progress after every turn, so a long run survives a restart.

    category AIin goal · messages · contextout text · message · usage · leg_costs · stopped · iterationsexecution asyncmodel cost model tokens

    Why the node earns its place

    The LLM node already runs a tool loop, but as an implementation detail of one chat turn: capped at eight turns, with the working history thrown away the moment the node returns. Right for a reply, useless for an agent — a run that dies on turn seventeen would start again at turn one, having already paid for sixteen.

    This node is the same loop under a durable contract. Its input is an objective rather than a conversation, its real bound is the wallet rather than a turn count, and its scratchpad is checkpointed after every turn so an interruption costs one turn instead of the whole run.

    How it works at run time

    1. 1
      Take the goal from the wired goal port, or from config when nothing is wired.
    2. 2
      Plan, call bound tools, read results, continue — the same loop body the LLM node uses.
    3. 3
      Checkpoint the scratchpad into durable run state after every turn. A resume picks the history back up mid-plan.
    4. 4
      Stop when the model says it is done, when the budget is exhausted, or at the max_iterations backstop.

    What comes out

    text        what the agent concluded
    stopped     why it stopped — done, budget, or cap
    iterations  turns used, counted across resumes
    usage / leg_costs   what it spent

    What you wire

    Inputs

    • goal
      string
    • messages
      array
    • context
      object

    Outputs

    • text
      string
    • message
      object
    • usage
      object
    • leg_costs
      array
    • stopped
      string
    • iterations
      number

    Configuration

    KeyTypeDefault & optionsWhat it does
    provider *stringchoices from model-library:providers
    model *stringchoices from model-library:models
    goalstringWhat the agent should accomplish. Overridden by the `goal` input port when one is wired.
    system_promptstringHow the agent should work — its role, limits and style.
    temperaturenumberdefault 0.3
    max_tokensnumber
    max_iterationsnumberdefault 40Safety backstop on total turns, counted across resumes. The real limit is the run's BICS budget.

    What usually goes wrong

    Watch for this

    Treating max_iterations as the cost control. It is a safety backstop; the real bound is the run's budget, enforced per model call. Budget exhaustion stops the loop gracefully and keeps the work so far rather than discarding a run that did fifteen useful turns — so check stopped before assuming a short result means failure.

    Behaviour & provenance

    buildersChat & voice agents, Automations
    routesno
    side effectsdelegated
    replay safetydelegated
    talks toa model, the tool gateway, durable run state
    holdsworkspace runtime token, the caller's own identity