This commit is contained in:
Timothy Jaeryang Baek
2026-03-29 19:42:10 -05:00
parent edb8971c7d
commit 1b1d85fe2e
2 changed files with 31 additions and 21 deletions
+29 -19
View File
@@ -393,7 +393,8 @@ async def execute_code(
if CODE_INTERPRETER_BLOCKED_MODULES: if CODE_INTERPRETER_BLOCKED_MODULES:
import textwrap import textwrap
blocking_code = textwrap.dedent(f""" blocking_code = textwrap.dedent(
f"""
import builtins import builtins
BLOCKED_MODULES = {CODE_INTERPRETER_BLOCKED_MODULES} BLOCKED_MODULES = {CODE_INTERPRETER_BLOCKED_MODULES}
@@ -409,7 +410,8 @@ async def execute_code(
return _real_import(name, globals, locals, fromlist, level) return _real_import(name, globals, locals, fromlist, level)
builtins.__import__ = restricted_import builtins.__import__ = restricted_import
""") """
)
code = blocking_code + '\n' + code code = blocking_code + '\n' + code
engine = getattr(__request__.app.state.config, 'CODE_INTERPRETER_ENGINE', 'pyodide') engine = getattr(__request__.app.state.config, 'CODE_INTERPRETER_ENGINE', 'pyodide')
@@ -2342,7 +2344,7 @@ class TaskItem(BaseModel):
status: Literal['pending', 'in_progress', 'completed', 'cancelled'] = Field('pending', description="Task status.") status: Literal['pending', 'in_progress', 'completed', 'cancelled'] = Field('pending', description="Task status.")
async def update_tasks( async def tasks(
tasks: list[TaskItem], tasks: list[TaskItem],
overwrite: bool = True, overwrite: bool = True,
__chat_id__: str = None, __chat_id__: str = None,
@@ -2352,14 +2354,21 @@ async def update_tasks(
__user__: dict = None, __user__: dict = None,
) -> str: ) -> str:
""" """
Create or update tasks for the current chat. By default replaces the Create or update a checklist of tasks tied to this chat.
entire task list. Set overwrite=false to update individual tasks by id Useful whenever a request involves multiple pieces of work that
while preserving the rest. should be tracked individually.
Only ONE task should be in_progress at a time. Mark tasks completed By default the entire list is replaced (overwrite=true). Set
immediately when done. overwrite=false to patch specific items by id without discarding
the rest.
:param tasks: List of task items. Each must have: id (string, unique identifier), content (string, task description — required for new tasks), status (one of: pending, in_progress, completed, cancelled). Each item carries an id, content string, and a status field
(pending, in_progress, completed, or cancelled). Order reflects
priority. Only one item should be in_progress at a time; mark
it completed before moving on, or cancel and replace it if the
approach changes.
:param tasks: List of task items. Each must have: id (string, unique identifier), content (string, task description, required for new tasks), status (one of: pending, in_progress, completed, cancelled).
:param overwrite: If true (default), replaces the entire task list. If false, updates/adds tasks by id while keeping existing ones. :param overwrite: If true (default), replaces the entire task list. If false, updates/adds tasks by id while keeping existing ones.
:return: JSON with the full task list and summary counts :return: JSON with the full task list and summary counts
""" """
@@ -2367,6 +2376,7 @@ async def update_tasks(
return json.dumps({'error': 'Chat context not available'}) return json.dumps({'error': 'Chat context not available'})
try: try:
def _to_dict(task) -> dict: def _to_dict(task) -> dict:
"""Convert TaskItem or dict to plain dict.""" """Convert TaskItem or dict to plain dict."""
if hasattr(task, 'model_dump'): if hasattr(task, 'model_dump'):
@@ -2391,7 +2401,7 @@ async def update_tasks(
return item_id if item_id else str(idx + 1) return item_id if item_id else str(idx + 1)
if overwrite: if overwrite:
# Full replacement — validate and write # Full replacement - validate and write
all_tasks = [] all_tasks = []
for idx, task in enumerate(tasks): for idx, task in enumerate(tasks):
d = _to_dict(task) d = _to_dict(task)
@@ -2404,13 +2414,15 @@ async def update_tasks(
if status not in VALID_TASK_STATUSES: if status not in VALID_TASK_STATUSES:
status = 'pending' status = 'pending'
all_tasks.append({ all_tasks.append(
'id': item_id, {
'content': content, 'id': item_id,
'status': status, 'content': content,
}) 'status': status,
}
)
else: else:
# Partial update — merge by id # Partial update - merge by id
existing_tasks = Chats.get_chat_tasks_by_id(__chat_id__) existing_tasks = Chats.get_chat_tasks_by_id(__chat_id__)
existing_by_id = {t['id']: t for t in existing_tasks} existing_by_id = {t['id']: t for t in existing_tasks}
@@ -2486,7 +2498,5 @@ async def update_tasks(
ensure_ascii=False, ensure_ascii=False,
) )
except Exception as e: except Exception as e:
log.exception(f'update_tasks error: {e}') log.exception(f'tasks error: {e}')
return json.dumps({'error': str(e)}) return json.dumps({'error': str(e)})
+2 -2
View File
@@ -85,7 +85,7 @@ from open_webui.tools.builtin import (
view_file, view_file,
view_knowledge_file, view_knowledge_file,
view_skill, view_skill,
update_tasks, tasks,
) )
import copy import copy
@@ -506,7 +506,7 @@ def get_builtin_tools(
# Task management - break down complex work into trackable steps # Task management - break down complex work into trackable steps
if is_builtin_tool_enabled('tasks'): if is_builtin_tool_enabled('tasks'):
builtin_functions.append(update_tasks) builtin_functions.append(tasks)
for func in builtin_functions: for func in builtin_functions:
callable = get_async_tool_function_and_apply_extra_params( callable = get_async_tool_function_and_apply_extra_params(