Skip to content
32 changes: 32 additions & 0 deletions src/prerna/reactor/agent/AgentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ private static AgentHarnessResult run(String roomId, String input, String engine
AgentConfig agentConfig = AgentConfigLoader.load(room, filePath, modelId, params, agentParams, maxTurns,
maxReflections, explicitWorkspaceId);

// List a room this run starts under its workspace, as CreateRoom does.
if (!resumeMode) {
persistWorkspaceOnEmptyRoom(room, insight, explicitWorkspaceId);
}

try {
reportSkillsNotLoaded(runId, SkillStager.stage(filePath, agentConfig.getSkills(), insight.getUser()));
} catch (Exception e) {
Expand Down Expand Up @@ -513,6 +518,33 @@ private static final class WorkspaceOverlay {
}
}

/**
* Sets {@code ROOM.WORKSPACE_ID} on a room with no messages yet so it shows in
* GetWorkspaceRooms, matching {@code CreateRoom(workspaceId)}. Options are not
* touched, so later runs can pick another agent or none. Skipped when the
* workspace is missing, disabled, or not viewable by the user.
*/
private static void persistWorkspaceOnEmptyRoom(Room room, Insight insight, String workspaceId) {
if (workspaceId == null || workspaceId.trim().isEmpty()) {
return;
}
List<?> messages = room.getMessages();
if (messages != null && !messages.isEmpty()) {
return;
}
try {
Map<String, Object> ws = ModelInferenceLogsUtils.getWorkspaceEntry(workspaceId);
if (ws == null || !Boolean.TRUE.equals(ws.get("is_active")) || insight.getUser() == null
|| !SecurityProjectUtils.userCanViewProject(insight.getUser(), workspaceId)) {
return;
}
ModelInferenceLogsUtils.setRoomWorkspaceId(room.getId(), room.getUserId(), workspaceId);
} catch (Exception e) {
classLogger.warn("AgentRunner: could not set workspace '{}' on room '{}': {}", workspaceId, room.getId(),
e.getMessage(), e);
}
}

/**
* Applies an in-memory workspace override for one run when needed.
*/
Expand Down
Loading