001/* 002 * Copyright (c) 2023-2026, Agents-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.agentsflex.core.agent.react; 017 018import com.agentsflex.core.message.Message; 019import com.agentsflex.core.message.UserMessage; 020import com.alibaba.fastjson2.JSON; 021import com.alibaba.fastjson2.JSONReader; 022import com.alibaba.fastjson2.JSONWriter; 023 024import java.io.Serializable; 025import java.util.ArrayList; 026import java.util.List; 027 028public class ReActAgentState implements Serializable { 029 030 private static final long serialVersionUID = 1L; 031 032 String userQuery; 033 List<Message> messageHistory; 034 int iterationCount = 0; 035 int maxIterations; 036 boolean streamable; 037 String promptTemplate; 038 boolean continueOnActionInvokeError; 039 040 public String getUserQuery() { 041 return userQuery; 042 } 043 044 public void setUserQuery(String userQuery) { 045 this.userQuery = userQuery; 046 } 047 048 public List<Message> getMessageHistory() { 049 return messageHistory; 050 } 051 052 public void setMessageHistory(List<Message> messageHistory) { 053 this.messageHistory = messageHistory; 054 } 055 056 public void addMessage(UserMessage message) { 057 if (messageHistory == null) { 058 messageHistory = new ArrayList<>(); 059 } 060 messageHistory.add(message); 061 } 062 063 public int getIterationCount() { 064 return iterationCount; 065 } 066 067 public void setIterationCount(int iterationCount) { 068 this.iterationCount = iterationCount; 069 } 070 071 public int getMaxIterations() { 072 return maxIterations; 073 } 074 075 public void setMaxIterations(int maxIterations) { 076 this.maxIterations = maxIterations; 077 } 078 079 public boolean isStreamable() { 080 return streamable; 081 } 082 083 public void setStreamable(boolean streamable) { 084 this.streamable = streamable; 085 } 086 087 public String getPromptTemplate() { 088 return promptTemplate; 089 } 090 091 public void setPromptTemplate(String promptTemplate) { 092 this.promptTemplate = promptTemplate; 093 } 094 095 public boolean isContinueOnActionInvokeError() { 096 return continueOnActionInvokeError; 097 } 098 099 public void setContinueOnActionInvokeError(boolean continueOnActionInvokeError) { 100 this.continueOnActionInvokeError = continueOnActionInvokeError; 101 } 102 103 public String toJSON() { 104 return JSON.toJSONString(this, JSONWriter.Feature.WriteClassName); 105 } 106 107 public static ReActAgentState fromJSON(String json) { 108 return JSON.parseObject(json, ReActAgentState.class, JSONReader.Feature.SupportClassForName); 109 } 110 111 112}