eemario commented on code in PR #1397:
URL: https://github.com/apache/flink-agents/pull/1397#discussion_r4676491033
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ChatModelAction.java:
##########
@@ -375,19 +405,33 @@ private static void chat(
ChatModelInvoker.chatWithRetries(
initialRequestId,
candidate,
- selection.durableChatCallId(candidate),
- messages,
+ selection.durableChatCallId(candidate)
+ + (closing ?
BUDGET_FINALIZATION_SUFFIX : ""),
+ closing ? closingMessages(messages) : messages,
Review Comment:
Done in 60b8af237. Request cleanup includes routing metadata, closing
messages are prepared before the candidate loop, and Python wraps
soft-finalization failures once in the outer handler.
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ChatModelInvoker.java:
##########
@@ -179,6 +179,31 @@ public static ChatAttemptResult chatWithRetries(
int numRetries,
long retryWaitMillis)
throws ChatAttemptFailed, Exception {
+ return chatWithRetries(
+ initialRequestId,
+ model,
+ durableCallId,
+ messages,
+ promptArgs,
+ outputSchema,
+ ctx,
+ numRetries,
+ retryWaitMillis,
+ false);
+ }
+
+ static ChatAttemptResult chatWithRetries(
Review Comment:
Removed the budget-specific forwarding overload in 60b8af237. After
rebasing, retained the two upstream overloads introduced for deferOutputSchema;
only the full overload takes finalTurn. The existing convenience overload
supplies false for both flags.
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ChatModelInvoker.java:
##########
@@ -240,8 +265,12 @@ public Class<InvocationOutcome> getResultClass() {
@Override
public InvocationOutcome call() throws Exception {
try {
- return new InvocationOutcome(
- chatModel.chat(messages, promptArgs,
Map.of()), null);
+ ChatResult response =
+ closing
+ ? chatModel.chatWithoutTools(
Review Comment:
Done in 60b8af237. Both paths share finalization with prepared messages,
optional native schema, and no tools. Soft finalization avoids a separate
conversion call. Renamed the invocation flag to finalTurn and unified the
durable suffix as :final, with Java/Python and recovery tests updated.
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/ChatModelAction.java:
##########
@@ -361,8 +389,10 @@ private static void chat(
Map<String, Object> promptArgs,
@Nullable Object outputSchema,
@Nullable Map<String, Object> userContext,
- RunnerContext ctx)
+ RunnerContext ctx,
+ @Nullable String reason)
throws Exception {
+ boolean closing = reason != null;
Review Comment:
Done in 60b8af237: the action uses budgetExhausted, while the invoker uses
finalTurn.
##########
plan/src/main/java/org/apache/flink/agents/plan/AgentConfiguration.java:
##########
@@ -107,7 +107,7 @@ public <T> void set(ConfigOption<T> option, T value) {
confData.put(option.getKey(), DurationUtils.format(parsed));
return;
}
- confData.put(option.getKey(), value);
+ confData.put(option.getKey(), value instanceof Enum<?> ? ((Enum<?>)
value).name() : value);
Review Comment:
Agreed; the conversion was redundant and has been removed in 60b8af237.
Existing enum handling and Jackson serialization cover this path.
##########
e2e-test/flink-agents-end-to-end-tests-resource-cross-language/src/test/java/org/apache/flink/agents/resource/test/ReActLoopBudgetCrossLanguageTest.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * 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.resource.test;
+
+import org.apache.flink.agents.api.Event;
+import org.apache.flink.agents.api.InputEvent;
+import org.apache.flink.agents.api.OutputEvent;
+import org.apache.flink.agents.api.agents.Agent;
+import org.apache.flink.agents.api.agents.AgentExecutionOptions;
+import org.apache.flink.agents.api.agents.ReActLoopBudget;
+import org.apache.flink.agents.api.chat.messages.ChatMessage;
+import org.apache.flink.agents.api.chat.messages.ChatResult;
+import org.apache.flink.agents.api.chat.messages.TokenUsage;
+import org.apache.flink.agents.api.chat.messages.ToolCallBlock;
+import org.apache.flink.agents.api.chat.model.BaseChatModelConnection;
+import org.apache.flink.agents.api.chat.model.BaseChatModelSetup;
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.agents.api.event.ChatRequestEvent;
+import org.apache.flink.agents.api.event.ChatResponseEvent;
+import org.apache.flink.agents.api.event.ToolResponseEvent;
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceContext;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.tools.Tool;
+import org.apache.flink.agents.plan.AgentPlan;
+import org.apache.flink.agents.plan.PythonFunction;
+import org.apache.flink.agents.plan.actions.Action;
+import org.apache.flink.agents.runtime.actionstate.ActionState;
+import org.apache.flink.agents.runtime.actionstate.ActionStateSerde;
+import org.apache.flink.agents.runtime.actionstate.ActionStateStore;
+import org.apache.flink.agents.runtime.operator.ActionExecutionOperator;
+import org.apache.flink.agents.runtime.operator.ActionExecutionOperatorFactory;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.runtime.checkpoint.OperatorSubtaskState;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Runs real Python actions/resources through Pemja and the checkpointable
operator. */
+@EnabledForJreRange(min = JRE.JAVA_21)
Review Comment:
Added mock-model job-level coverage for Java, Python, and cross-language
SOFT/HARD turn, token, and time budgets in 60b8af237. Removed the
cross-language test class's Java 21 restriction and verified it on Java 17 and
21.
##########
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:
Done in 813f5ff79. The shared CompileUtils submission path now validates
job-level budget defaults before creating the operator. Tests cover valid and
invalid configurations through both Java plans and Python plan JSON.
--
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]