gupta-sahil01 commented on code in PR #6436:
URL: https://github.com/apache/texera/pull/6436#discussion_r4596294861


##########
agent-service/src/server.ts:
##########
@@ -388,6 +390,45 @@ const agentsRouter = new Elysia({ prefix: "/agents" })
     }
   );
 
+// Stateless ambient operator recommender (apache/texera#5240). Given the
+// operator a user just added, returns a short ranked list of likely next
+// operators for the canvas to render as suggestions. Version 1 uses a
+// hardcoded rule table with no LLM call, so it needs no user token and no
+// per-request model configuration; it only reads the process-wide operator
+// catalog to validate and label its suggestions.
+const recommendRouter = new Elysia({ prefix: "/recommend" })
+  // Local-scoped error handler, mirroring agentsRouter: body-schema and
+  // malformed-JSON failures are client errors (400), not 500s.
+  .onError(({ code, error, set }) => {
+    log.error({ err: error }, "recommend request error");
+    const errorMessage = error instanceof Error ? error.message : 
String(error);
+    if (code === "VALIDATION" || code === "PARSE") {
+      set.status = 400;
+      return { error: errorMessage || "Invalid request body" };
+    }
+    set.status = 500;
+    return { error: errorMessage || "Internal server error" };
+  })
+  .post(
+     "/",
+     ({ body, set }) => {
+       const req = body as RecommendationRequest;
+       const operatorType = req.operatorType.trim();
+       if (!operatorType) {
+         set.status = 400;
+         return { error: "operatorType must be a non-empty string" };
+       }
+       return recommendOperators({ ...req, operatorType }, 
WorkflowSystemMetadata.getInstance());

Review Comment:
   Done in 1a2fd8231. When the catalog is not initialized, the handler loads it 
before ranking. Concurrent requests share one load, and a failed load is logged 
and retried on the next request. The route spec covers a request while the 
backend returns 503 followed by one after it recovers.
   



##########
agent-service/src/operator-recommendation/operator-recommendation-types.ts:
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Wire types for the ambient operator recommender (discussion 
apache/texera#5240).
+ *
+ * The recommender is a stateless endpoint that, given the operator a user just
+ * added to the canvas, returns a short ranked list of likely "next" operators
+ * to render as suggestion chips on the output port.
+ *
+ * Version 1 (this file's consumer, `recommendOperators`) produces suggestions
+ * from a hardcoded rule table — no LLM call, no persistent state — so it can
+ * ship and validate the full canvas pipeline at zero API cost. Version 2 will
+ * swap the ranking strategy for a small LLM behind the same request/response
+ * shape; the `strategy` discriminator on the response lets clients tell the 
two
+ * apart without a breaking change.
+ */
+
+/** Ranking strategy that produced a response. `llm` is reserved for V2. */
+export type RecommendationStrategy = "hardcoded" | "llm";
+
+/** Hard ceiling on how many suggestions a single request may ask for. */
+export const MAX_RECOMMENDATION_LIMIT = 5;
+
+/** Default number of suggestions when the request does not specify a limit. */
+export const DEFAULT_RECOMMENDATION_LIMIT = 3;
+
+export interface RecommendationRequest {
+  /**
+   * The operator type that was just added and whose output port we are
+   * suggesting successors for (e.g. `"CSVFileScan"`). Primary ranking signal.
+   */
+  operatorType: string;

Review Comment:
   Added in 1a2fd8231. The request takes an optional `sourcePortID` (canvas 
format `output-<n>`, default `output-0`), and a port the operator does not have 
yields no suggestions. Each suggestion carries a `targetPortID` (`input-<n>`): 
a trained model goes to the target's "model" port, and other data goes to the 
first port that does not take a model. After a trainer, Sklearn Prediction is 
targeted at `input-0`; from a data operator it would be `input-1`.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to