{"record":{"id":"0cb261f932cb4232","repo":"dagger/dagger","slug":"object-q-function-q-is-marked-agent-but-does-no","errorCode":null,"errorMessage":"object %q function %q is marked @agent but does not return LLM!; @agent functions must have the agent(base: LLM!): LLM! shape","messagePattern":"object %q function %q is marked @agent but does not return LLM!; @agent functions must have the agent\\(base: LLM!\\): LLM! shape","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/module.go","lineNumber":243,"sourceCode":"\t}\n\tfor _, argRes := range fn.Args {\n\t\targ := argRes.Self()\n\t\tif argRequired(arg) {\n\t\t\treturn fmt.Errorf(\"object %q function %q is marked @generate but declares required argument %q; @generate functions must be callable with no arguments\",\n\t\t\t\tobj.OriginalName, fn.OriginalName, arg.OriginalName)\n\t\t}\n\t}\n\treturn nil\n}\n\n// validateAgentFunction enforces the @agent middleware contract (hack/designs/workspace-agents.md\n// §3): the function must return LLM! and must declare exactly one required\n// argument, an LLM! (the base the compose fold supplies, whatever it is\n// named). A non-LLM! return, a missing base, or any other required argument is\n// a hard error at module load.\nfunc validateAgentFunction(obj *ObjectTypeDef, fn *Function) error {\n\tif !returnsCoreObject(fn, \"LLM\") {\n\t\treturn fmt.Errorf(\"object %q function %q is marked @agent but does not return LLM!; @agent functions must have the agent(base: LLM!): LLM! shape\",\n\t\t\tobj.OriginalName, fn.OriginalName)\n\t}\n\tbaseExempted := false\n\tfor _, argRes := range fn.Args {\n\t\targ := argRes.Self()\n\t\tif !argRequired(arg) {\n\t\t\tcontinue\n\t\t}\n\t\tif !baseExempted && isCoreLLMArg(arg) {\n\t\t\tbaseExempted = true\n\t\t\tcontinue\n\t\t}\n\t\treturn fmt.Errorf(\"object %q function %q is marked @agent but declares required argument %q; an @agent function may only require a single LLM! argument (the base the compose fold supplies)\",\n\t\t\tobj.OriginalName, fn.OriginalName, arg.OriginalName)\n\t}\n\tif !baseExempted {\n\t\treturn fmt.Errorf(\"object %q function %q is marked @agent but does not declare a required LLM! argument; @agent functions must have the agent(base: LLM!): LLM! shape (the base the compose fold supplies)\",\n\t\t\tobj.OriginalName, fn.OriginalName)","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/module.go#L225-L261","documentation":"An @agent function must have the exact shape agent(base: LLM!): LLM! — it is invoked by a compose fold that supplies an LLM base and expects a new LLM back. validateAgentFunction rejects any @agent function whose return type is not the core LLM object (core/module.go:243), failing module load.","triggerScenarios":"Decorating a function with @agent that returns String, Void, a custom object, or nullable LLM instead of core LLM!.","commonSituations":"Authoring an agent step that returns a final answer string instead of the composed LLM; adapting an ordinary helper into an @agent function without adjusting its signature.","solutions":["Change the return type to the core LLM! type and return the composed LLM","Return the base LLM with the prompt/step applied (e.g. base.withPrompt(...))","Remove the @agent pragma if the function is not part of an agent compose fold"],"exampleFix":"// before\n@agent()\nanswer(base: LLM): string { return base.query(\"...\"); }\n// after\n@agent()\nanswer(base: LLM): LLM { return base.withPrompt(\"...\"); }","handlingStrategy":"validation","validationCode":"if (fn.pragmas.includes(\"agent\") && !(fn.returnType === \"LLM\" && fn.returnNonNull)) {\n  throw new Error(`@agent ${fn.name} must return LLM!, got ${fn.returnType}`);\n}","typeGuard":"const returnsLLM = (fn) => fn.returnType === \"LLM\" && fn.returnNonNull === true;","tryCatchPattern":null,"preventionTips":["Use the exact agent(base: LLM!): LLM! shape","Return base.withPrompt(...)/composed LLM, not extracted values","Validate module schema after adding @agent"],"tags":["dagger","module-validation","agent-pragma","llm"],"backgroundTag":"agent-function-wrong-return-type","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}