Skip to content

Commit 2bd0090

Browse files
allow multiple ids for out of scope (#3789)
Co-authored-by: Théo Monnom <theo.8bits@gmail.com>
1 parent 115a27e commit 2bd0090

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

livekit-agents/livekit/agents/beta/workflows/task_group.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class TaskGroupResult:
2525

2626

2727
class _OutOfScopeError(ToolError):
28-
def __init__(self, target_task_id: str) -> None:
29-
self.target_task_id = target_task_id
28+
def __init__(self, target_task_ids: list) -> None:
29+
self.target_task_ids = target_task_ids
3030

3131

3232
class TaskGroup(AgentTask[TaskGroupResult]):
@@ -73,7 +73,8 @@ async def on_enter(self):
7373
task_results[task_id] = res
7474
except _OutOfScopeError as e:
7575
task_stack.insert(0, task_id)
76-
task_stack.insert(0, e.target_task_id)
76+
for task_id in reversed(e.target_task_ids):
77+
task_stack.insert(0, task_id)
7778
continue
7879
except Exception as e:
7980
self.complete(e)
@@ -104,28 +105,27 @@ def _build_out_of_scope_tool(self, *, active_task_id: str) -> FunctionTool | Non
104105
}
105106

106107
description = (
107-
"Call to regress to another task according to what the user requested to modify, return the corresponding task id, "
108+
"Call to regress to other tasks according to what the user requested to modify, return the corresponding task ids. "
108109
'For example, if the user wants to change their email and there is a task with id "email_task" with a description of "Collect the user\'s email", return the id ("get_email_task").'
110+
"If the user requests to regress to multiple tasks, such as changing their phone number and email, return both task ids in the order they were requested."
109111
f"The following are the IDs and their corresponding task description. {json.dumps(task_repr)}"
110112
)
111113

112114
@function_tool(description=description, flags=ToolFlag.IGNORE_ON_ENTER)
113115
async def out_of_scope(
114-
task_id: Annotated[
115-
str,
116+
task_ids: Annotated[
117+
list[str],
116118
Field(
117-
description="The ID of the task requested",
118-
json_schema_extra={"enum": list(task_ids)},
119+
description="The IDs of the tasks requested",
120+
json_schema_extra={"items": {"enum": list(task_ids)}},
119121
),
120122
],
121123
):
122-
if (
123-
task_id not in self._registered_factories
124-
or task_id not in self._visited_tasks
125-
):
126-
raise ToolError("unable to regress, invalid task id")
124+
for task_id in task_ids:
125+
if task_id not in self._registered_factories or task_id not in self._visited_tasks:
126+
raise ToolError(f"unable to regress, invalid task id {task_id}")
127127

128128
if not self._current_task.done():
129-
self._current_task.complete(_OutOfScopeError(target_task_id=task_id))
129+
self._current_task.complete(_OutOfScopeError(target_task_ids=task_ids))
130130

131131
return out_of_scope

0 commit comments

Comments
 (0)