Nodes/comfyui_LLM_party/Code Execution Tool
ComfyUI Node

Code Execution Tool

Give your LLM its own Python interpreter

By heshengtao·Created 2 years ago·Updated 6 days ago· 2,321
Code Execution Tool
    • tool
    is_enabletrue

    This is the same idea as OpenAI's Code Interpreter / Advanced Data Analysis feature, just self-hosted inside your own ComfyUI graph: hand the LLM a tool that lets it write and run Python whenever it decides it needs to actually compute something - math it shouldn't eyeball, parsing a blob of text, whatever a language model is bad at doing purely by "thinking."

    Notice there's no code field on this node anywhere in its schema. That's the key difference from its sibling, interpreter_function: there, you write fixed code as the graph author. Here, the LLM writes the code itself, at call time, based on what it decides it needs - this node just registers the capability.

    How it works

    Wire the tool output into this pack's LLM/agent node's tool-list input. During the conversation, if the model decides code execution would help, it writes Python, the tool runs it, and the result flows back into the conversation for the model to use in its answer - the same tool-calling loop every LLM/agent node in this pack follows.

    The inputs and outputs that matter

    • is_enable - the only real input, the standard bypass toggle.

    Output: tool (STRING) - the serialized tool definition. Not meant to be read directly; it's meant to be wired into the agent node's tool-list input, exactly like this pack's other tool nodes (GeocodeTool, the KG toolkit nodes).

    How to install it

    Via ComfyUI Manager: search comfyui_LLM_party, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/heshengtao/comfyui_LLM_party.git
    

    Then pip install -r requirements.txt from inside the pack folder using ComfyUI's own Python, and restart. No API keys of its own - it needs whatever LLM node you've already got configured for API access, since the LLM is what actually decides to use this tool.

    Common issues & troubleshooting

    Take this one seriously before handing it to an agent. This is a bigger risk than interpreter_function, not a smaller one - there, you control what code runs; here, an LLM does, based on whatever instructions and user input reach it. Don't wire this tool into an agent whose prompt or inputs come from untrusted users. ComfyUI's custom-node ecosystem already runs arbitrary Python with no sandbox by design; this node adds an LLM deciding what that Python does.

    The LLM never uses the tool. Same as any tool-calling setup - the model needs a reason to reach for it. If your agent's instructions don't mention it can execute code, or the conversation never calls for computation, it may just answer directly instead.

    The LLM tries to use it and the call fails. Check that the LLM node you've wired this tool into actually supports tool/function calling - not every model or every API configuration does, and a model that can't call tools will either ignore this one or hallucinate a result instead of actually running code.

    Category大模型派对(llm_party)/工具(tools)/实用(Utility)

    Inputs (1)

    NameTypeDefaultDescription
    is_enableBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    toolSTRING