ComfyUI Node

AgentNode

The completion node that keeps going until the answer is actually good

By Hopping-Mad-Games·Created 2 years ago·Updated 11 months ago· 7
AgentNode
  • model
  • List_prompts
  • image
  • messages
  • memory_provider
  • recursion_filter
  • Model
  • Messages
  • Completion
  • List_Completions
  • List_messages
  • Usage
max_tokens250
temperature0.50
top_p0.50
frequency_penalty0.00
presence_penalty0.00
promptHello World!
reasoning_effortlow
taskcompletion
max_iterations2
use_last_responsefalse

A single LLM call is dumb. It reads the prompt once, says whatever it says, and moves on. AgentNode is the pack's answer to that: an iterative completion node that runs the same prompt over and over, optionally feeding each answer through a "filter" that improves it, and optionally pulling in external context between rounds. It's less a chatbot and more a completion pipeline - the README literally suggests the display name should be "Iterative Completion Agent," which is a fair description.

If you just want one prompt answered, use LiteLLMCompletion. Reach for this when you want the loop: draft, revise, reconsider, repeat, until either you've hit max_iterations or the result is good enough. That's the pattern behind the reflection filters in this pack - and behind most "agentic" workflows people build on top of these nodes.

How it works

Each iteration, for each prompt, the node does three steps:

  1. Memory - if a memory_provider is connected, it's called with your prompt and returns a list of context strings, which get wrapped in <SYSTEM_RAG> tags and prepended to the prompt. This is how you bolt retrieval (or any external context) onto the loop.
  2. Recursion - if a recursion_filter is connected, the previous completion is run through it, and the result is appended to the conversation as an assistant message.
  3. Completion - the whole thing goes through the underlying LitellmCompletionV2 handler, which is just an LLM call with your sampling settings.

Responses are cached by an input hash in ComfyUI/data/agent_response_cache, so use_last_response can replay a finished run - invaluable while you're iterating on the workflow and paying per call.

The inputs that matter

  • model - from a provider node. Required; the node throws a clear error if you forget it.
  • prompt or List_prompts - a single prompt, or a list to process (the list path runs prompts in parallel and returns per-prompt completions).
  • max_iterations (default 2) - loop count. This is your cost dial.
  • memory_provider (optional) - a function returning a list of context strings. Expected to be cheap; it runs every iteration.
  • recursion_filter (optional) - from BasicRecursionFilterNode or DocumentChunkRecursionFilterNode.
  • use_last_response (optional) - replay the cached run.
  • Plus the standard completion dials: max_tokens, temperature, top_p, the penalties, reasoning_effort, an optional image, and messages for conversation continuity.

Outputs are the good stuff: Completion (final text), Messages (final conversation), List_Completions and List_messages (everything from every iteration), Model, and Usage.

Installing

ComfyUI Manager, search "ComfyUI_LiteLLM", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Hopping-Mad-Games/ComfyUI_LiteLLM
cd ComfyUI_LiteLLM
pip install -r requirements.txt

Restart, set a provider key in your environment, and the node is under ETK/LLM/LiteLLM (the agents also register their own display names).

Where people get burned

Costs are the big one. max_iterations multiplies everything: a List_prompts of 5 prompts at max_iterations of 10 is 50 LLM calls, minimum, before any memory or filter calls. The node itself prints a warning above 10 iterations - trust it. Second, the recursion_filter and memory_provider inputs are typed CALLABLE-ish custom types (LLLM_AGENT_RECURSION_FILTER, LLLM_AGENT_MEMORY_PROVIDER); if you see type errors, you're probably connecting the wrong output - a raw completion output won't fit where a filter is expected. And the caching is keyed on inputs, so if you change the prompt you get a new hash and a fresh call - that's intended, but it surprises people who expect "cache" to mean "forever." Keep iterations low while developing, flip use_last_response on, and only then let it run loose.

Categorysd

Inputs (16)

NameTypeDefaultDescription
modelLITELLM_MODELanthropic/claude-3-haiku-20240307
max_tokensINT2501–10000000000
temperatureFLOAT0.500–1
top_pFLOAT0.500–1
frequency_penaltyFLOAT0.00
presence_penaltyFLOAT0.00
promptSTRINGHello World!
reasoning_effortCOMBOlow3 options: low, medium, high
taskCOMBOcompletion7 options: transcription, classification, completion, translation, summarization, image_captioning, +1
max_iterationsINT2
List_promptsLIST
imageoptIMAGE
messagesoptLLLM_MESSAGES
memory_provideroptLLLM_AGENT_MEMORY_PROVIDER
recursion_filteroptLLLM_AGENT_RECURSION_FILTER
use_last_responseoptBOOLEANfalse

Outputs (6)

NameTypeDescription
ModelLITELLM_MODEL
MessagesLLLM_MESSAGES
CompletionSTRING
List_CompletionsLIST
List_messagesLIST
UsageSTRING