{"record":{"id":"00645965eff5bffa","repo":"sigoden/aichat","slug":"please-enable-function-calling-before-using-the-ag","errorCode":null,"errorMessage":"Please enable function calling before using the agent.","messagePattern":"Please enable function calling before using the agent\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1495,"sourceCode":"    pub fn rag_template(&self, embeddings: &str, text: &str) -> String {\n        if embeddings.is_empty() {\n            return text.to_string();\n        }\n        self.rag_template\n            .as_deref()\n            .unwrap_or(RAG_TEMPLATE)\n            .replace(\"__CONTEXT__\", embeddings)\n            .replace(\"__INPUT__\", text)\n    }\n\n    pub async fn use_agent(\n        config: &GlobalConfig,\n        agent_name: &str,\n        session_name: Option<&str>,\n        abort_signal: AbortSignal,\n    ) -> Result<()> {\n        if !config.read().function_calling {\n            bail!(\"Please enable function calling before using the agent.\");\n        }\n        if config.read().agent.is_some() {\n            bail!(\"Already in a agent, please run '.exit agent' first to exit the current agent.\");\n        }\n        let agent = Agent::init(config, agent_name, abort_signal).await?;\n        let session = session_name.map(|v| v.to_string()).or_else(|| {\n            if config.read().macro_flag {\n                None\n            } else {\n                agent.agent_prelude().map(|v| v.to_string())\n            }\n        });\n        config.write().rag = agent.rag();\n        config.write().agent = Some(agent);\n        if let Some(session) = session {\n            config.write().use_session(Some(&session))?;\n        } else {\n            config.write().init_agent_shared_variables()?;","sourceCodeStart":1477,"sourceCodeEnd":1513,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1477-L1513","documentation":"Thrown by the agent-entry function in src/config/mod.rs:1495 when `config.read().function_calling` is false. Agents rely on function/tool calling to operate, so the library requires the global `function_calling` flag to be enabled before `Agent::init` is attempted. This is a preflight capability check, not a model-side failure.","triggerScenarios":"Calling the agent entry function (CLI `.agent <name>` or its Rust wrapper) with a config where the `function_calling` option is disabled/unset — typically a model or provider config that lacks tool-calling support or has the flag explicitly off.","commonSituations":"Users on models/providers without function-calling support trying to use agents; configs migrated from older versions where the flag defaulted differently; users who disabled function calling globally for cost/compat reasons and forgot.","solutions":["Enable function calling in the config (set the `function_calling` option to true) and retry","Switch to a model/provider that supports function calling","If function calling cannot be enabled, avoid agent mode and use plain chat/rag workflows"],"exampleFix":"// before (function_calling disabled)\nconfig.use_agent(\"my-agent\", None, signal).await?;\n// after\nif !config.read().function_calling {\n    config.write().function_calling = true; // or fix the config file\n}\nconfig.use_agent(\"my-agent\", None, signal).await?;","handlingStrategy":"validation","validationCode":"if !config.read().function_calling {\n    bail!(\"Enable function calling in your config before using agents\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = config.use_agent(name, session, signal).await {\n    if e.to_string().contains(\"enable function calling\") {\n        eprintln!(\"Set function_calling=true (or switch to a tool-capable model)\");\n        return Ok(());\n    }\n    return Err(e.into());\n}","preventionTips":["Set `function_calling: true` in the config when agents are part of your workflow","Choose models/providers that support tool calling for agent use","Validate the config (function_calling flag + model capability) at startup"],"tags":["agent","function-calling","feature-flag","config"],"backgroundTag":"feature-not-enabled","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"}