원클릭으로
backend-tools-declaration
How tools are declared on backend and frontend, and how to keep them in sync
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
How tools are declared on backend and frontend, and how to keep them in sync
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Install ComfyUI Assistant as a ComfyUI custom node. Use when performing or troubleshooting installation (clone, Python deps, frontend build, restart).
For complex user requests — evaluate, investigate, ask questions, propose a plan, accept modifications, then execute. Use when the request is multi-step, ambiguous, or high-impact.
Workflow execution and complete workflow generation tools (executeWorkflow, applyWorkflowJson). Use when the user wants to run a workflow or build a complete workflow from a description.
Python backend modules, chat request lifecycle, SSE format, and API endpoints
System prompt assembly from system_context, user_context, and environment sources
Generate a Product Requirements Document (PRD) for a new feature. Use when planning a feature, starting a new project, or when asked to create a PRD. Triggers on: create a prd, write prd for, plan this feature, requirements for, spec out.
| name | backend-tools-declaration |
| description | How tools are declared on backend and frontend, and how to keep them in sync |
| version | 0.0.1 |
| license | MIT |
Tools are declared in two places that must stay in sync: the Python backend (for the LLM) and the TypeScript frontend (for execution).
tools_definitions.pyTools are declared in OpenAI function calling format as a TOOLS list:
TOOLS = [
{
"type": "function",
"function": {
"name": "addNode",
"description": "Adds a node to the workflow...",
"parameters": {
"type": "object",
"properties": {
"nodeType": {"type": "string", "description": "..."},
"position": {
"type": "object",
"properties": {"x": {"type": "number"}, "y": {"type": "number"}}
}
},
"required": ["nodeType"]
}
}
},
...
]
Helper functions: get_tools() returns the list, get_tool_names() returns name strings.
Definitions (ui/src/tools/definitions/): Each tool has a Zod schema file.
// add-node.ts
export const addNodeDefinition = {
description: 'Adds a node to the workflow...',
parameters: z.object({
nodeType: z.string(),
position: z.object({ x: z.number(), y: z.number() }).optional()
})
}
Implementations (ui/src/tools/implementations/): Each tool has an execute function.
// add-node.ts
export async function executeAddNode(
params: AddNodeParams,
context: ToolContext
): Promise<ToolResult> { ... }
Registry (ui/src/tools/index.ts): createTools(context) combines definitions and implementations into a Record<string, Tool> consumed by the runtime.
Hook (ui/src/tools/useComfyTools.ts): useComfyTools() calls createTools() and registers them into the ModelContext via useAssistantTool() or similar.
| Tool | Category | Description |
|---|---|---|
addNode | Graph | Add a node to the workflow |
removeNode | Graph | Remove a node by ID |
connectNodes | Graph | Connect two nodes by slot indices |
getWorkflowInfo | Graph | Query workflow state and node details; use fullFormat: true for full frontend/API workflow |
setNodeWidgetValue | Graph | Set any widget value on a node |
fillPromptNode | Graph | Set text on a CLIPTextEncode node (shorthand) |
createSkill | Skills | Create a persistent user skill |
deleteSkill | Skills | Delete a user skill by slug |
updateSkill | Skills | Update a user skill |
refreshEnvironment | Environment | Rescan nodes, packages, models |
searchInstalledNodes | Environment | Search node types |
getAvailableModels | Environment | List models by category |
readDocumentation | Environment | Fetch docs for a topic |
executeWorkflow | Execution | Queue workflow and wait for result |
applyWorkflowJson | Execution | Load a complete API-format workflow |
Graph tools execute in the frontend against window.app. Environment/Skills tools call backend API endpoints. Execution tools interact with ComfyUI's queue API via the frontend.
Backend -- Add entry to TOOLS list in tools_definitions.py:
Frontend definition -- Create ui/src/tools/definitions/<tool-name>.ts:
description and parameters (Zod schema)Frontend implementation -- Create ui/src/tools/implementations/<tool-name>.ts:
execute<ToolName> function(params, context) => Promise<ToolResult>Registry -- Update ui/src/tools/index.ts:
createTools()System prompt (if needed) -- Update system_context/skills/ with usage guidance for the LLM
Rebuild -- cd ui && npm run build
Test -- Verify the LLM can call the tool and the frontend executes it correctly
Add a matching entry to TOOLS in tools_definitions.py with the same name, parameter names, types, and descriptions. The LLM only sees the backend definitions.
Both places: tools_definitions.py (backend) and ui/src/tools/definitions/<tool>.ts (frontend). They must match.
window.app?Same process, but the frontend implementation makes a fetch() call to a backend endpoint instead of using window.app. See refreshEnvironment or searchInstalledNodes implementations for examples.
The frontend executes the tool, wraps the result as a tool-result message part, and the runtime resubmits the full message history (including the result) to POST /api/chat. The backend converts it to an OpenAI tool role message.
backend-architecture -- backend module map and API endpointsarchitecture-overview -- end-to-end tool call flow diagram