{"record":{"id":"43eb872143f6794e","repo":"n8n-io/n8n","slug":"agent-this-name-requires-a-model","errorCode":null,"errorMessage":"Agent \"${this.name}\" requires a model","messagePattern":"Agent \"(.+?)\" requires a model","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/agent.ts","lineNumber":962,"sourceCode":"\t\t\t},\n\t\t});\n\t}\n\n\tprivate async cleanupRuntime(active: ActiveRuntime): Promise<void> {\n\t\tif (!this.activeRuntimes.delete(active)) return;\n\t\tactive.bus.dispose();\n\t\tawait active.runtime.dispose();\n\t}\n\n\tprivate toMessages(input: string | AgentMessage[]): AgentMessage[] {\n\t\tif (Array.isArray(input)) return input;\n\t\treturn [{ role: 'user', content: [{ type: 'text', text: input }] }];\n\t}\n\n\t/** @internal Validate configuration and produce an AgentRuntime. Overridden by the execution engine. */\n\tprotected async build(): Promise<AgentRuntimeConfig> {\n\t\tif (!this.modelConfig) {\n\t\t\tthrow new Error(`Agent \"${this.name}\" requires a model`);\n\t\t}\n\t\tif (!this.instructionsText) {\n\t\t\tthrow new Error(`Agent \"${this.name}\" requires instructions`);\n\t\t}\n\n\t\tconst finalTools = [...this.tools];\n\t\tconst configuredDeferredTools = [...this.deferredTools];\n\n\t\tif (this.workspaceInstance) {\n\t\t\tconst wsTools = this.workspaceInstance.getTools();\n\t\t\tfinalTools.push(...wsTools);\n\t\t}\n\n\t\tconst finalStaticTools = finalTools;\n\t\tconst finalDeferredTools = configuredDeferredTools;\n\n\t\t// Validate checkpoint requirement from static tools and known MCP approval config\n\t\t// before attempting any network connections (allows fast failure).","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/agent.ts#L944-L980","documentation":"Thrown by Agent.build() when modelConfig has not been set. An agent cannot run without a language model — the model is the core engine that produces tool-call decisions and final responses. The build method validates this invariant before constructing the runtime.","triggerScenarios":"Calling agent.run() or agent.build() without first calling agent.model(modelConfig). Also possible if .model() was called with undefined or a value that did not set modelConfig.","commonSituations":"Building an agent programmatically where the model is conditionally set (e.g. based on an env var) and the condition was not met. Copying agent setup code and forgetting the model line. Passing a model provider that returns undefined for the current configuration.","solutions":["Call agent.model(yourModel) before running or building the agent.","Ensure the model configuration is set unconditionally, not behind a conditional that might be skipped.","Add a startup assertion that modelConfig is set before build."],"exampleFix":"// before\nconst agent = new Agent('my-agent').instructions('You are helpful.');\nawait agent.run('Hello');\n// after\nconst agent = new Agent('my-agent')\n  .model(myModel)\n  .instructions('You are helpful.');\nawait agent.run('Hello');","handlingStrategy":"validation","validationCode":"if (!agentModel) {\n  throw new Error('Cannot build agent without a model');\n}\nagent.model(agentModel);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call agent.model(yourModel) before run() or build().","Set the model unconditionally, not behind a conditional that might be skipped.","Add a pre-build assertion that checks modelConfig is set."],"tags":["agent","model","configuration","build"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}