langgenius/dify · error · ValueError
invalid_param
invalid_param
Error message
Original app model config not found
What it means
A raw ValueError('Original app model config not found') raised in AppModelConfigApi.post when an AGENT_CHAT (or agent-with-session) app has no existing AppModelConfig row (api/controllers/console/app/model_config.py:117-119). The handler needs the original config to decrypt/migrate agent tool parameters; without it, it cannot safely produce the new config. Flask translates the ValueError into a 400 with code invalid_param.
Source
Thrown at api/controllers/console/app/model_config.py:119
# validate config
model_configuration = AppModelConfigService.validate_configuration(
tenant_id=current_tenant_id,
config=cast(dict, request.json),
app_mode=AppMode.value_of(app_model.mode),
session=session,
)
new_app_model_config = AppModelConfig(
app_id=app_model.id,
created_by=current_user_id,
updated_by=current_user_id,
)
new_app_model_config = new_app_model_config.from_model_config_dict(model_configuration)
if app_model.mode == AppMode.AGENT_CHAT or app_model.is_agent_with_session(session=session):
original_app_model_config = app_model.app_model_config_with_session(session=session)
if original_app_model_config is None:
raise ValueError("Original app model config not found")
agent_mode = original_app_model_config.agent_mode_dict
# decrypt agent tool parameters if it's secret-input
parameter_map = {}
masked_parameter_map = {}
tool_map = {}
for tool in agent_mode.get("tools") or []:
if not isinstance(tool, dict) or len(tool.keys()) <= 3:
continue
agent_tool_entity = AgentToolEntity.model_validate(tool)
# get tool
try:
tool_runtime = ToolManager.get_agent_tool_runtime(
tenant_id=current_tenant_id,
app_id=app_model.id,
agent_tool=agent_tool_entity,
user_id=current_user_id,
)View on GitHub (pinned to ef8544b173)
Solutions
- Initialize the app's AppModelConfig before updating — create a default config row or use the app-setup flow that bootstraps it.
- Verify app_model.app_model_config_id is non-null and points to an existing AppModelConfig row in the DB.
- If the row was accidentally deleted, restore from a backup or recreate via AppModelConfig.from_model_config_dict with the default agent template.
- Avoid manually mutating the apps/app_model_configs tables; use the console API to manage configs.
Defensive patterns
Strategy: validation
Validate before calling
// Before POSTing a config update for an agent-chat app, confirm a config exists
const app = await fetch(`/console/apps/${appId}`).then(r=>r.json())
if (app.mode === 'AGENT_CHAT' && !app.app_model_config_id) {
await initAppConfig(appId) // bootstrap a default config first
}
await updateModelConfig(appId, config) Try / catch
try {
await updateModelConfig(appId, config)
} catch (e) {
if (e.code === 'invalid_param' && /Original app model config/.test(e.message)) {
await initAppConfig(appId); return updateModelConfig(appId, config)
}
throw e
} Prevention
- Never manually delete AppModelConfig rows.
- Ensure app-creation flows initialize the config for agent-chat apps.
- Audit app_model_config_id is non-null after migrations.
When it happens
Trigger: POSTing an updated model config to an AGENT_CHAT app that has no AppModelConfig attached — e.g. the app was created but its config row was never initialized, was deleted, or the app is mid-migration. The check is `app_model.app_model_config_with_session(session)` returning None.
Common situations: App created via a path that skipped config initialization; manual DB edit deleted the config row; migration/import left the app in a partial state; agent chat app whose app_model_config_id is null.
Related errors
- invalid_param
- completion_request_error
- app_suggested_questions_after_answer_disabled
- The server encountered an internal error and was unable to c
- trace_config_is_exist
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/b29a5f780a162cc0.
Report an issue: GitHub.