Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: add the maximum number of iterations to env (#16805)

XiaoBac451f54925c1
diff --git a/docker/.env.example b/docker/.env.example
index 4d7486ed89f..d366b181605 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -743,6 +743,9 @@ MAX_TOOLS_NUM=10
# Maximum number of Parallelism branches in the workflow
MAX_PARALLEL_LIMIT=10
+# The maximum number of iterations for agent setting
+MAX_ITERATIONS_NUM=5
+
# ------------------------------
# Environment Variables for web Service
# ------------------------------
diff --git a/docker/docker-compose-template.yaml b/docker/docker-compose-template.yaml
index 05db17102b7..e8ed382917d 100644
--- a/docker/docker-compose-template.yaml
+++ b/docker/docker-compose-template.yaml
@@ -70,6 +70,7 @@ services:
LOOP_NODE_MAX_COUNT: ${LOOP_NODE_MAX_COUNT:-100}
MAX_TOOLS_NUM: ${MAX_TOOLS_NUM:-10}
MAX_PARALLEL_LIMIT: ${MAX_PARALLEL_LIMIT:-10}
+ MAX_ITERATIONS_NUM: ${MAX_ITERATIONS_NUM:-5}
# The postgres database.
db:
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index c6a90eb5211..bc92cb0922c 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -325,6 +325,7 @@ x-shared-env: &shared-api-worker-env
LOOP_NODE_MAX_COUNT: ${LOOP_NODE_MAX_COUNT:-100}
MAX_TOOLS_NUM: ${MAX_TOOLS_NUM:-10}
MAX_PARALLEL_LIMIT: ${MAX_PARALLEL_LIMIT:-10}
+ MAX_ITERATIONS_NUM: ${MAX_ITERATIONS_NUM:-5}
TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000}
PGUSER: ${PGUSER:-${DB_USERNAME}}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-${DB_PASSWORD}}
@@ -502,6 +503,7 @@ services:
LOOP_NODE_MAX_COUNT: ${LOOP_NODE_MAX_COUNT:-100}
MAX_TOOLS_NUM: ${MAX_TOOLS_NUM:-10}
MAX_PARALLEL_LIMIT: ${MAX_PARALLEL_LIMIT:-10}
+ MAX_ITERATIONS_NUM: ${MAX_ITERATIONS_NUM:-5}
# The postgres database.
db:
diff --git a/web/.env.example b/web/.env.example
index 6b2ab154cfd..51dc3d6b3c4 100644
--- a/web/.env.example
+++ b/web/.env.example
@@ -45,4 +45,7 @@ NEXT_PUBLIC_LOOP_NODE_MAX_COUNT=100
NEXT_PUBLIC_MAX_TOOLS_NUM=10
# Maximum number of Parallelism branches in the workflow
-NEXT_PUBLIC_MAX_PARALLEL_LIMIT=10
\ No newline at end of file
+NEXT_PUBLIC_MAX_PARALLEL_LIMIT=10
+
+# The maximum number of iterations for agent setting
+NEXT_PUBLIC_MAX_ITERATIONS_NUM=5
diff --git a/web/app/components/app/configuration/config/agent/agent-setting/index.tsx b/web/app/components/app/configuration/config/agent/agent-setting/index.tsx
index 1501d75a8d6..26a1242bd75 100644
--- a/web/app/components/app/configuration/config/agent/agent-setting/index.tsx
+++ b/web/app/components/app/configuration/config/agent/agent-setting/index.tsx
@@ -10,7 +10,7 @@ import { CuteRobot } from '@/app/components/base/icons/src/vender/solid/communic
import { Unblur } from '@/app/components/base/icons/src/vender/solid/education'
import Slider from '@/app/components/base/slider'
import type { AgentConfig } from '@/models/debug'
-import { DEFAULT_AGENT_PROMPT } from '@/config'
+import { DEFAULT_AGENT_PROMPT, MAX_ITERATIONS_NUM } from '@/config'
type Props = {
isChatModel: boolean
@@ -21,7 +21,6 @@ type Props = {
}
const maxIterationsMin = 1
-const maxIterationsMax = 5
const AgentSetting: FC<Props> = ({
isChatModel,
@@ -99,7 +98,7 @@ const AgentSetting: FC<Props> = ({
<Slider
className='mr-3 w-[156px]'
min={maxIterationsMin}
- max={maxIterationsMax}
+ max={MAX_ITERATIONS_NUM}
value={tempPayload.max_iteration}
onChange={(value) => {
setTempPayload({
@@ -112,7 +111,7 @@ const AgentSetting: FC<Props> = ({
<input
type="number"
min={maxIterationsMin}
- max={maxIterationsMax} step={1}
+ max={MAX_ITERATIONS_NUM} step={1}
className="block h-7 w-11 rounded-lg border-0 bg-components-input-bg-normal px-1.5 pl-1 leading-7 text-text-primary placeholder:text-text-tertiary focus:ring-1 focus:ring-inset focus:ring-primary-600"
value={tempPayload.max_iteration}
onChange={(e) => {
@@ -120,8 +119,8 @@ const AgentSetting: FC<Props> = ({
if (value < maxIterationsMin)
value = maxIterationsMin
- if (value > maxIterationsMax)
- value = maxIterationsMax
+ if (value > MAX_ITERATIONS_NUM)
+ value = MAX_ITERATIONS_NUM
setTempPayload({
...tempPayload,
max_iteration: value,
diff --git a/web/app/layout.tsx b/web/app/layout.tsx
index 890d0bdf975..4f9fc616c82 100644
--- a/web/app/layout.tsx
+++ b/web/app/layout.tsx
@@ -52,6 +52,7 @@ const LocaleLayout = async ({
data-public-top-k-max-value={process.env.NEXT_PUBLIC_TOP_K_MAX_VALUE}
data-public-indexing-max-segmentation-tokens-length={process.env.NEXT_PUBLIC_INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH}
data-public-loop-node-max-count={process.env.NEXT_PUBLIC_LOOP_NODE_MAX_COUNT}
+ data-public-max-iterations-num={process.env.NEXT_PUBLIC_MAX_ITERATIONS_NUM}
>
<BrowserInitor>
<SentryInitor>
diff --git a/web/config/index.ts b/web/config/index.ts
index 3426222796d..bba893ca54d 100644
--- a/web/config/index.ts
+++ b/web/config/index.ts
@@ -293,3 +293,12 @@ else if (globalThis.document?.body?.getAttribute('data-public-loop-node-max-coun
loopNodeMaxCount = Number.parseInt(globalThis.document.body.getAttribute('data-public-loop-node-max-count') as string)
export const LOOP_NODE_MAX_COUNT = loopNodeMaxCount
+
+let maxIterationsNum = 5
+
+if (process.env.NEXT_PUBLIC_MAX_ITERATIONS_NUM && process.env.NEXT_PUBLIC_MAX_ITERATIONS_NUM !== '')
+ maxIterationsNum = Number.parseInt(process.env.NEXT_PUBLIC_MAX_ITERATIONS_NUM)
+else if (globalThis.document?.body?.getAttribute('data-public-max-iterations-num') && globalThis.document.body.getAttribute('data-public-max-iterations-num') !== '')
+ maxIterationsNum = Number.parseInt(globalThis.document.body.getAttribute('data-public-max-iterations-num') as string)
+
+export const MAX_ITERATIONS_NUM = maxIterationsNum