{"record":{"id":"351c755a0dff3216","repo":"sigoden/aichat","slug":"no-return-value-from-instructions-function","errorCode":null,"errorMessage":"No return value from '_instructions' function","messagePattern":"No return value from '_instructions' function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/agent.rs","lineNumber":322,"sourceCode":"        if self.is_dynamic_instructions() {\n            let value = match value {\n                Some(v) => v,\n                None => self.run_instructions_fn()?,\n            };\n            self.session_dynamic_instructions = Some(value);\n        }\n        Ok(())\n    }\n\n    fn run_instructions_fn(&self) -> Result<String> {\n        let value = run_llm_function(\n            self.name().to_string(),\n            vec![\"_instructions\".into(), \"{}\".into()],\n            self.variable_envs(),\n        )?;\n        match value {\n            Some(v) => Ok(v),\n            _ => bail!(\"No return value from '_instructions' function\"),\n        }\n    }\n}\n\nimpl RoleLike for Agent {\n    fn to_role(&self) -> Role {\n        let prompt = self.interpolated_instructions();\n        let mut role = Role::new(\"\", &prompt);\n        role.sync(self);\n        role\n    }\n\n    fn model(&self) -> &Model {\n        &self.model\n    }\n\n    fn temperature(&self) -> Option<f64> {\n        self.config.temperature","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/agent.rs#L304-L340","documentation":"Guard in the dynamic-instructions path: the agent's '_instructions' LLM function was invoked to generate instructions at runtime, but it returned no value (None), so there is nothing to store as the dynamic instruction text. The fault is in the agent's function definition — it fails to return any output for the empty '{}' arguments it is called with.","triggerScenarios":"Thrown at src/config/agent.rs:322 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the '_instructions' function in the agent's functions directory so it always returns a string","Test the function directly with '{}' arguments to reproduce the empty return","Add a default/fallback instruction text to use when the function yields nothing, so agent init does not hard-fail"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}