diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py
index 0b6ae4b249..ae324f0aa6 100644
--- a/backend/open_webui/config.py
+++ b/backend/open_webui/config.py
@@ -2088,6 +2088,10 @@ VIEW_CHAT_MAX_CHARS = int(os.environ['VIEW_CHAT_MAX_CHARS']) if os.getenv('VIEW_
if VIEW_CHAT_MAX_CHARS is not None and VIEW_CHAT_MAX_CHARS <= 0:
raise ValueError('VIEW_CHAT_MAX_CHARS must be a positive integer or unset')
+TOOL_OUTPUT_MAX_CHARS = int(os.environ['TOOL_OUTPUT_MAX_CHARS']) if os.getenv('TOOL_OUTPUT_MAX_CHARS') else None
+if TOOL_OUTPUT_MAX_CHARS is not None and TOOL_OUTPUT_MAX_CHARS <= 0:
+ raise ValueError('TOOL_OUTPUT_MAX_CHARS must be a positive integer or unset')
+
ENABLE_CHANNELS = os.getenv('ENABLE_CHANNELS', 'False').lower() == 'true'
ENABLE_ENCRYPTED_CHANNELS = os.getenv('ENABLE_ENCRYPTED_CHANNELS', 'False').lower() == 'true'
@@ -2971,6 +2975,7 @@ DEFAULT_CONFIG = {
'skills.content_max_chars': SKILL_CONTENT_MAX_CHARS,
'skills.preview_max_chars': SKILL_PREVIEW_MAX_CHARS,
'chats.view_max_chars': VIEW_CHAT_MAX_CHARS,
+ 'tools.output_max_chars': TOOL_OUTPUT_MAX_CHARS,
'ollama.enable': ENABLE_OLLAMA_API,
'ollama.base_urls': OLLAMA_BASE_URLS,
'ollama.api_configs': OLLAMA_API_CONFIGS,
diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py
index b26d785b2d..a35ea0d88c 100644
--- a/backend/open_webui/routers/auths.py
+++ b/backend/open_webui/routers/auths.py
@@ -144,6 +144,7 @@ ADMIN_CONFIG_KEYS = {
'SKILL_CONTENT_MAX_CHARS': 'skills.content_max_chars',
'SKILL_PREVIEW_MAX_CHARS': 'skills.preview_max_chars',
'VIEW_CHAT_MAX_CHARS': 'chats.view_max_chars',
+ 'TOOL_OUTPUT_MAX_CHARS': 'tools.output_max_chars',
'ENABLE_NOTES': 'notes.enable',
'ENABLE_USER_WEBHOOKS': 'ui.enable_user_webhooks',
'ENABLE_USER_STATUS': 'users.enable_status',
@@ -1196,6 +1197,7 @@ class AdminConfig(MfaConfigForm):
SKILL_CONTENT_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
SKILL_PREVIEW_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
VIEW_CHAT_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
+ TOOL_OUTPUT_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
ENABLE_NOTES: bool
ENABLE_USER_WEBHOOKS: bool
ENABLE_USER_STATUS: bool
@@ -1256,6 +1258,8 @@ async def update_admin_config(request: Request, form_data: AdminConfig, user=Dep
updates.pop('skills.preview_max_chars', None)
if 'VIEW_CHAT_MAX_CHARS' not in form_data.model_fields_set:
updates.pop('chats.view_max_chars', None)
+ if 'TOOL_OUTPUT_MAX_CHARS' not in form_data.model_fields_set:
+ updates.pop('tools.output_max_chars', None)
updates['ui.default_interface_settings'] = form_data.DEFAULT_INTERFACE_SETTINGS or {}
updates['folders.max_file_count'] = int(form_data.FOLDER_MAX_FILE_COUNT) if form_data.FOLDER_MAX_FILE_COUNT else ''
updates['automations.max_count'] = int(form_data.AUTOMATION_MAX_COUNT) if form_data.AUTOMATION_MAX_COUNT else ''
diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py
index f08ac45f9a..1d212ec81a 100644
--- a/backend/open_webui/utils/middleware.py
+++ b/backend/open_webui/utils/middleware.py
@@ -947,6 +947,10 @@ async def process_tool_result(
else:
tool_result = str(tool_result)
+ max_chars = await Config.get('tools.output_max_chars')
+ if max_chars and tool_result and len(tool_result) > max_chars:
+ tool_result = f'{tool_result[:max_chars]}\n\n[Truncated: {len(tool_result)} characters, limit {max_chars}]'
+
return tool_result, tool_result_files, tool_result_embeds
diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte
index 25b3fa89b9..3bd2048596 100644
--- a/src/lib/components/admin/Settings/General.svelte
+++ b/src/lib/components/admin/Settings/General.svelte
@@ -65,6 +65,7 @@
SKILL_CONTENT_MAX_CHARS: $i18n.t('settings.admin.general.skillContentMaxChars.label'),
SKILL_PREVIEW_MAX_CHARS: $i18n.t('settings.admin.general.skillPreviewMaxChars.label'),
VIEW_CHAT_MAX_CHARS: $i18n.t('settings.admin.general.viewChatMaxChars.label'),
+ TOOL_OUTPUT_MAX_CHARS: $i18n.t('settings.admin.general.toolOutputMaxChars.label'),
ENABLE_NOTES: $i18n.t('settings.admin.general.notes.label'),
ENABLE_COMMENTS: $i18n.t('settings.admin.general.comments.label'),
ENABLE_NOTIFICATIONS: $i18n.t('settings.admin.general.notifications.label'),
@@ -124,6 +125,7 @@
SKILL_CONTENT_MAX_CHARS: adminConfig.SKILL_CONTENT_MAX_CHARS ?? null,
SKILL_PREVIEW_MAX_CHARS: adminConfig.SKILL_PREVIEW_MAX_CHARS ?? null,
VIEW_CHAT_MAX_CHARS: adminConfig.VIEW_CHAT_MAX_CHARS ?? null,
+ TOOL_OUTPUT_MAX_CHARS: adminConfig.TOOL_OUTPUT_MAX_CHARS ?? null,
DEFAULT_INTERFACE_SETTINGS: defaultInterfaceSettings,
I18N: cleaned
});
@@ -435,6 +437,21 @@
bind:value={adminConfig.VIEW_CHAT_MAX_CHARS}
/>
+
+
+