sigoden/aichat · error
Please enable function calling before using the agent.
Error message
Please enable function calling before using the agent.
What it means
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.
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
Example fix
// before (function_calling disabled)
config.use_agent("my-agent", None, signal).await?;
// after
if !config.read().function_calling {
config.write().function_calling = true; // or fix the config file
}
config.use_agent("my-agent", None, signal).await?; Defensive patterns
Strategy: validation
Validate before calling
if !config.read().function_calling {
bail!("Enable function calling in your config before using agents");
} Try / catch
if let Err(e) = config.use_agent(name, session, signal).await {
if e.to_string().contains("enable function calling") {
eprintln!("Set function_calling=true (or switch to a tool-capable model)");
return Ok(());
}
return Err(e.into());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/00645965eff5bffa.
Report an issue: GitHub.
Appendix: source
Thrown at src/config/mod.rs:1495
pub fn rag_template(&self, embeddings: &str, text: &str) -> String {
if embeddings.is_empty() {
return text.to_string();
}
self.rag_template
.as_deref()
.unwrap_or(RAG_TEMPLATE)
.replace("__CONTEXT__", embeddings)
.replace("__INPUT__", text)
}
pub async fn use_agent(
config: &GlobalConfig,
agent_name: &str,
session_name: Option<&str>,
abort_signal: AbortSignal,
) -> Result<()> {
if !config.read().function_calling {
bail!("Please enable function calling before using the agent.");
}
if config.read().agent.is_some() {
bail!("Already in a agent, please run '.exit agent' first to exit the current agent.");
}
let agent = Agent::init(config, agent_name, abort_signal).await?;
let session = session_name.map(|v| v.to_string()).or_else(|| {
if config.read().macro_flag {
None
} else {
agent.agent_prelude().map(|v| v.to_string())
}
});
config.write().rag = agent.rag();
config.write().agent = Some(agent);
if let Some(session) = session {
config.write().use_session(Some(&session))?;
} else {
config.write().init_agent_shared_variables()?;View on GitHub (pinned to 82976d349a)