AgentNode
The completion node that keeps going until the answer is actually good
- model
- List_prompts
- image
- messages
- memory_provider
- recursion_filter
- Model
- Messages
- Completion
- List_Completions
- List_messages
- Usage
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:
- Memory - if a
memory_provideris 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. - Recursion - if a
recursion_filteris connected, the previous completion is run through it, and the result is appended to the conversation as an assistant message. - Completion - the whole thing goes through the underlying
LitellmCompletionV2handler, 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.promptorList_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) - fromBasicRecursionFilterNodeorDocumentChunkRecursionFilterNode.use_last_response(optional) - replay the cached run.- Plus the standard completion dials:
max_tokens,temperature,top_p, the penalties,reasoning_effort, an optionalimage, andmessagesfor 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.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| model | LITELLM_MODEL | anthropic/claude-3-haiku-20240307 | — |
| max_tokens | INT | 2501–10000000000 | — |
| temperature | FLOAT | 0.500–1 | — |
| top_p | FLOAT | 0.500–1 | — |
| frequency_penalty | FLOAT | 0.00 | — |
| presence_penalty | FLOAT | 0.00 | — |
| prompt | STRING | Hello World! | — |
| reasoning_effort | COMBO | low | 3 options: low, medium, high |
| task | COMBO | completion | 7 options: transcription, classification, completion, translation, summarization, image_captioning, +1 |
| max_iterations | INT | 2 | — |
| List_prompts | LIST | — | |
| imageopt | IMAGE | — | |
| messagesopt | LLLM_MESSAGES | — | |
| memory_provideropt | LLLM_AGENT_MEMORY_PROVIDER | — | |
| recursion_filteropt | LLLM_AGENT_RECURSION_FILTER | — | |
| use_last_responseopt | BOOLEAN | false | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| Model | LITELLM_MODEL | — |
| Messages | LLLM_MESSAGES | — |
| Completion | STRING | — |
| List_Completions | LIST | — |
| List_messages | LIST | — |
| Usage | STRING | — |