pltbkd commented on code in PR #1397:
URL: https://github.com/apache/flink-agents/pull/1397#discussion_r4665219161


##########
api/src/main/java/org/apache/flink/agents/api/agents/ReActAgent.java:
##########
@@ -119,10 +119,20 @@ public ReActAgent(
             @Nullable Prompt prompt,
             @Nullable Object outputSchema,
             @Nullable List<String> skills) {
+        this(descriptor, prompt, outputSchema, skills, null);
+    }
+
+    public ReActAgent(

Review Comment:
   Could we introduce a `ReActAgent` builder and expose the budget option 
there? The growing set of constructor overloads makes the API easy to misuse, 
especially when callers pass `null` for optional arguments. For example, the 
documented call is ambiguous because the fourth argument matches both 
`List<String>` and `Skills`. Named builder methods would make those choices 
explicit.



##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ReActLoopBudgetUtils.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.
+ */
+package org.apache.flink.agents.plan.actions;
+
+import org.apache.flink.agents.api.agents.AgentExecutionOptions;
+import org.apache.flink.agents.api.agents.ReActLoopBudget;
+import org.apache.flink.agents.api.chat.messages.ChatResult;
+import org.apache.flink.agents.api.chat.messages.TokenUsage;
+import org.apache.flink.agents.api.context.DurableCallable;
+import org.apache.flink.agents.api.context.MemoryObject;
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.agents.api.event.ChatRequestEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/** Request-scoped loop progress stored in sensory memory as checkpoint-safe 
values. */
+final class ReActLoopBudgetUtils {
+    private ReActLoopBudgetUtils() {}
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ReActLoopBudgetUtils.class);
+    static final String LOOP_BUDGET_CONTEXT = "_LOOP_BUDGET_CONTEXT";
+
+    static void initialize(RunnerContext ctx, ChatRequestEvent event) throws 
Exception {
+        if (getBudgetState(ctx.getSensoryMemory(), event.getId()) != null) 
return;
+        ReActLoopBudget limits = event.getBudget();
+        if (limits == null && ctx.getConfig() != null) {

Review Comment:
   Could we validate the job-level budget defaults at job submission? The 
existing validation runs when a chat first uses those defaults. Moving it to 
the shared submission path would surface configuration errors before the job 
starts processing requests.



##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ChatModelAction.java:
##########
@@ -460,6 +495,9 @@ static Object generateStructuredOutputWithReport(
 
     private static void processChatRequest(ChatRequestEvent event, 
RunnerContext ctx)
             throws Exception {
+        ReActLoopBudgetUtils.initialize(ctx, event);
+        String reason = 
ReActLoopBudgetUtils.tryStartTurn(ctx.getSensoryMemory(), event.getId());

Review Comment:
   Nit — Both the sync and async model calls can replay a persisted result. If 
recovery happens after the deadline, the wall-clock admission check can take 
the timeout branch before replay reaches that result. Could we use 
`durableExecute` to record the admission, for example by recording the 
timestamp, when a time budget is configured? The same turn would replay the 
recorded admission, and each new turn would still check the current time.



-- 
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