Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow regular users to assign agent manually when creating sessions #2614

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2614.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow regular users to assign agent manually if `hide-agent` configuration is disabled
1 change: 0 additions & 1 deletion src/ai/backend/client/cli/session/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ def prepare_mount_arg(
type=list_expr,
help=(
"Show mapping list of tuple which mapped containers with agent. "
"When user role is Super Admin. "
"(e.g., --assign-agent agent_id_1,agent_id_2,...)"
),
)
Expand Down
1 change: 0 additions & 1 deletion src/ai/backend/client/cli/session/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def _create_cmd(docs: Optional[str] = None):
type=list_expr,
help=(
"Assign the session to specific agents. "
"This option is only applicable when the user role is Super Admin. "
"(e.g., --assign-agent agent_id_1,agent_id_2,...)"
),
)
Expand Down
49 changes: 26 additions & 23 deletions src/ai/backend/manager/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
List,
Mapping,
MutableMapping,
Optional,
Set,
Tuple,
Union,
Expand Down Expand Up @@ -654,30 +655,32 @@ async def create_from_params(request: web.Request, params: dict[str, Any]) -> we
else:
raise InvalidAPIParameters("API version not supported")
params["config"] = creation_config
if params["config"]["agent_list"] is not None and request["user"]["role"] != (
UserRole.SUPERADMIN
):
raise InsufficientPrivilege(
"You are not allowed to manually assign agents for your session."
)
if request["user"]["role"] == (UserRole.SUPERADMIN):
if not params["config"]["agent_list"]:
pass

root_ctx: RootContext = request.app["_root.context"]

agent_list = cast(Optional[list[str]], params["config"]["agent_list"])
if agent_list is not None:
if (
request["user"]["role"] != UserRole.SUPERADMIN
and root_ctx.local_config["manager"]["hide-agents"]
):
raise InsufficientPrivilege(
"You are not allowed to manually assign agents for your session."
)
agent_count = len(agent_list)
if params["cluster_mode"] == "multi-node":
if agent_count != params["cluster_size"]:
raise InvalidAPIParameters(
"For multi-node cluster sessions, the number of manually assigned"
" agents must be same to the cluster size. Note that you may specify"
" duplicate agents in the list.",
)
else:
agent_count = len(params["config"]["agent_list"])
if params["cluster_mode"] == "multi-node":
if agent_count != params["cluster_size"]:
raise InvalidAPIParameters(
"For multi-node cluster sessions, the number of manually assigned"
" agents must be same to the cluster size. Note that you may specify"
" duplicate agents in the list.",
)
else:
if agent_count != 1:
raise InvalidAPIParameters(
"For non-cluster sessions and single-node cluster sessions, "
"you may specify only one manually assigned agent.",
)
if agent_count != 1:
raise InvalidAPIParameters(
"For non-cluster sessions and single-node cluster sessions, "
"you may specify only one manually assigned agent.",
)
return await _create(request, params)


Expand Down
Loading