Agent Loop
Concepts: What is an AI agent? explains the loop in plain words, and supervisor and worker agents covers the worker port. Agent memory covers session memory and the session tool cache. Glossary: agent loopAgent loop: The cycle an AI agent repeats: call the model, run the tools it asks for, add the results to the conversation, then call the model again until it answers., context windowContext window: The most text, counted in tokens, that a model can take into account in one call: system prompt, conversation, tool definitions and tool results, plus the answer it writes., supervisor agentSupervisor agent: An agent whose tools include other agents: it splits a task, hands each part to a worker agent, and combines the answers into one reply.. Too many tools covers keeping the tool list short.
Execution model
Agent orchestration is iterative, not one-shot.
- Collect messages (
system_prompt,user_prompt, optional memory context) - Collect attached tool metadata from
mcp_toolandworkflow_toolnodes - Call model with tool definitions
- If model returns tool calls:
- execute tool(s)
- append tool outputs to conversation
- call model again
- Stop on final answer or
maxIterations
Attachment ports
chat_model: attach model node- supported:
openai_chat_model,anthropic_chat_model,ollama_chat_model,openai_compatible_chat_model,ai_gateway_chat_model,azure_openai_chat_model,google_gemini_chat_model,llm_call
- supported:
memory: attachlocal_memorytool: attach one or moremcp_tool(any MCP server, or a built-in tool) orworkflow_tool(another workflow as one tool, see Workflow Tool)worker: attach worker agents (Supervisor node only). Connected workers (Agent OrchestratororSupervisornodes) are exposed to the parent as tool calls, so a Supervisor can delegate downstream recursively. An A2A Agent node on this port makes a remote agent a worker too.
These attachment edges are not part of linear DAG execution. The chat_model attachment is required, and the runtime always uses that node's provider config. Attachment-only helper nodes are marked as skipped in execution traces because the agent runtime consumes them instead of running them as steps.
In the visual editor, use the + button below an Agent port to open a filtered drawer for compatible Language Model, Memory, or Tool nodes. Clicking an item creates and attaches it automatically.
An optional Think Tool toggle on the agent adds a think scratchpad tool; see Built-in agent tools.
Tool names the model sees
An MCP server's tool reaches the model as <adapter>__<tool>, for example http_mcp__search. When two or more MCP servers on one agent serve a tool with the same name (two registered servers that both offer search, or two MCP Tool nodes with different endpoints in all-tools mode), every one of them is renamed <adapter>_<hash>__<tool>, for example http_mcp_3f9a1c__search. The six-character hash comes from the server: its registry id, or the secret and connection of an inline node. So the name stays the same between runs and in replays. The description starts with the server's name ([http_mcp: Docs search] ...), so the model can tell the copies apart. Names stay within 64 characters: a longer tool part is cut and ends in a hash of the full tool name.
- Each call runs on its own server. Tool rules, the write-tool gate, data labels and content rules judge that server and the original tool name, so a rule on server B's
searchstill applies after the rename. - A name only one server serves keeps its plain form. Adding a third server that also serves
searchrenames the first two once; after that their names stay the same. - A copy that a tool rule or No write tools hides does not count, so the visible copy keeps its plain name.
- Names you choose still have to be unique, and the agent node fails while they repeat: two Workflow Tools with the same tool name, two built-in tool nodes of one provider, or two workers with the same name. The error names the nodes, and validation reports
duplicate_agent_tool_namewhen the workflow shows the clash.
How the context is kept small
The runtime trims what it sends the model on every call. The limits are fixed in the agent runtime unless a row says otherwise.
Tool definitions (every MCP, Workflow Tool and worker tool the model is offered):
| What | Limit |
|---|---|
| Description | 280 characters; the rest is cut and marked ...[truncated N chars] |
| Arguments | The first 8 top-level properties of the input schema, each kept with its type, description (120 characters), required and the first 10 enum values; nested properties and array item shapes below them are dropped |
required list | The first 8 names |
Which tools are offered. With an MCP Tool or Workflow Tool node on the tool port, the model is offered every tool those nodes expose, trimmed as above; to keep a large server's tool list short, pick the tools on the MCP Tool node (Select multiple tools). Only an agent with no tool nodes, whose tools come from its inline mcpServers config, gets a keyword shortlist: tools are ranked by how many words from the user prompt (runs of four or more letters, digits or underscores) appear in their name and description, and the model gets up to 6 that match (only the best-matching ones when a tool matches two or more words) or, when none match, the first 8, within about 18,000 characters of tool definitions. Workers on the worker port and the runtime's own tools (agent_clarify always, the session cache tools with a session_id, think when it is turned on) are offered whenever they are present and never shortlisted.
Messages:
| What | Limit |
|---|---|
| System prompt | 8,000 characters |
| User prompt, each remembered message and each model reply kept in the conversation | 3,000 characters |
| Tool result | toolMessageMaxChars (default 6,000, at least 500). A longer result is compacted first: toolPayloadMaxDepth (8) levels, toolPayloadMaxObjectKeys (64) keys per object, toolPayloadMaxArrayItems (64) items per array and toolPayloadMaxStringChars (1,024) characters per string, marked _meta.truncated; if it is still too long, the model gets a preview |
The tool-result limits are fields on the Agent node (see the node reference). The full tool output is kept in the session tool cache when a session_id is set.
Starting values for large-context local models
For a local model with about 92k tokens of available context, a reasonable starting point on the Agent node's Tool Output Limits (Advanced) is:
toolMessageMaxChars:90000toolPayloadMaxDepth:8toolPayloadMaxObjectKeys:256toolPayloadMaxArrayItems:256toolPayloadMaxStringChars:4096
These values are passed to the runtime and validated server-side. If you still hit provider context errors, reduce them first (especially toolMessageMaxChars), then reduce the number of attached tools.
Simple Memory
Simple Memory (local_memory) is database-backed session memory. Its config:
namespace: the memory bucket key (defaultdefault)sessionIdTemplate: defaults tomaxMessages: the maximum persisted turns keptpersistToolMessages: whether tool messages are saved in memory
Memory is stored in the session_memory table (namespace, session_id, messages_json, created_at, updated_at). The session tool cache below is stored in session_tool_cache (id, namespace, session_id, tool_name, tool_call_id, args_json, output_json, error, summary_json, created_at).
Common failure causes
- No model node attached to
chat_model - Tool definitions too large for model context
- Missing credential secret refs
- Max iterations too low for required task depth
Reliability guidance
- Keep tool schema concise
- Restrict tool set to task-relevant tools
- Set explicit max iterations
- Ensure upstream nodes provide stable prompt fields
Session tool cache (multi-turn reuse)
The runtime persists full MCP tool outputs outside prompt context and exposes cache tools back to the model for follow-up turns.
Behavior:
- External MCP tool call completes.
- Runtime stores full args/output by
namespace + session_id. - Runtime gives the model compact in-context tool messages.
- On later turns, model can call:
session_cache_listsession_cache_get
- Model reuses prior fetched data instead of repeating expensive MCP calls.
Notes:
- Cache tools are injected automatically when
session_idis present. - Reuse depends on stable
session_idand memory namespace. - Memory, cached tool calls and session artifacts are stored per project, so workflows in different projects never share them even with the same namespace and
session_id. - Cached payloads are stored in SQLite table
session_tool_cache.
Mid-turn clarification (agent_clarify)
The runtime exposes a third built-in tool — agent_clarify — that the agent can call whenever it needs information only the user can provide. It's always available, regardless of whether a session_id is set.
How it works
- The agent decides it can't proceed without more info and calls
agent_clarify({ question, reason? }). - The runtime breaks out of the iteration loop before invoking the tool body. The assistant's tool-call message is saved to session memory.
run()returns withstopReason: "clarification_requested"and aclarificationfield containing the question, optional reason, and the tool call id.- The
agent_orchestratornode surfaces the clarification on its output. The workflow's top-level result also carries aclarificationfield so chat UIs and webhook callers don't have to dig intonodeResults.
Resume
On the next run() call with the same sessionId and a non-empty userPrompt:
- The runtime loads session memory, sees the orphaned
agent_clarifytool call. - It injects the new
userPromptas the tool result for that call (not as a fresh user message) — so the LLM sees a clean tool-call → tool-result exchange in the standard tool-calling protocol. - The agent loop continues from there. The next assistant turn is the answer.
For chat triggers this happens automatically — every chat message in the same session reuses the same session_id, so the next user reply resumes naturally.
For non-chat triggers (webhook, schedule), the workflow caller inspects result.clarification and re-invokes the workflow with the reply as user_prompt.
What gets persisted
Tool results are normally filtered from session memory (the in-context tool message has the full output), and the assistant's tool-call requests go with them: a call whose result is not stored is dropped from the saved message. The agent_clarify tool result is the exception — it's always persisted, so the resume-detection on subsequent runs sees the question as answered and doesn't re-resume.
When to use it
- ✅ The user said "send him an email" without specifying who.
- ✅ The user asked for "the report" without saying which one.
- ❌ Don't use it as a confirmation gate. If the request is clear, just do it.
- ❌ Don't use it to ask the user to fix the user's own typo — make the best reasonable inference.
Chat UI
When the workflow result carries clarification, the chat bubble renders with a "?" badge labeled "Assistant is asking", the question as the body, and the optional reason below it as italic context. The bubble looks different enough from a regular answer that users can tell at a glance "the agent is waiting on me."
Sample workflow: samples/workflows/agent-clarify-flow.json.