-
Notifications
You must be signed in to change notification settings - Fork 10.5k
feat(agent): make MCP tool call timeout configurable #18016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+131
−5
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
336c618
feat(agent): make MCP tool call timeout configurable
var4dev 15db558
feat(agent): validate tool timeout and assert timeout propagation
var4dev 0ac7aed
test(agent): cover timeout fallback for 0 and negative values
var4dev 244e5db
test(agent): move timeout test out of agent/tools to avoid pytest nam…
var4dev 9cb7924
test(agent): cover positive sub-second timeout fallback
var4dev 73aba03
Merge remote-tracking branch 'upstream/main' into feat/agent-tool-tim…
var4dev d9bf674
fix(agent): add docstrings to LLMToolPluginCallSession for coverage
var4dev 94a8784
fix(web): use RAGFlowFormItem for tool_timeout field
var4dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/unit_test/agent/tools/test_llm_tool_plugin_session.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # | ||
| # Copyright 2026 The InfiniFlow Authors. All Rights Reserved. | ||
| # | ||
| # Licensed 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. | ||
| # | ||
| """Verify that LLMToolPluginCallSession applies its configurable default timeout to MCP tool calls.""" | ||
|
|
||
| import asyncio | ||
| import time | ||
| from functools import partial | ||
|
|
||
| from agent.tools.base import LLMToolPluginCallSession | ||
| from common.mcp_tool_call_conn import MCPToolBinding | ||
|
|
||
|
|
||
| class _BlockingSession: | ||
| """Fake MCP session that waits until the caller-provided timeout elapses, mimicking MCPToolCallSession.""" | ||
|
|
||
| def tool_call(self, name: str, arguments: dict, timeout: float = 10) -> str: | ||
| deadline = time.monotonic() + timeout | ||
| while time.monotonic() < deadline: | ||
| time.sleep(0.005) | ||
| return "done" | ||
|
|
||
|
|
||
| def _noop_callback(*args, **kwargs): | ||
| pass | ||
|
|
||
|
|
||
| def _make_session(default_timeout): | ||
| return LLMToolPluginCallSession( | ||
| {"transcribe_0": MCPToolBinding(_BlockingSession(), "transcribe")}, | ||
| partial(_noop_callback), | ||
| default_timeout=default_timeout, | ||
| ) | ||
|
|
||
|
|
||
| def test_default_timeout_is_applied_to_mcp_tool_call(): | ||
| session = _make_session(default_timeout=0.1) | ||
| start = time.monotonic() | ||
| result = asyncio.run(session.tool_call_async("transcribe_0", {})) | ||
| elapsed = time.monotonic() - start | ||
| assert result == "done" | ||
| # Without the session default the 10s tool_call default would run far longer. | ||
| assert elapsed < 1.0 | ||
|
|
||
|
|
||
| def test_explicit_request_timeout_overrides_default(): | ||
| session = _make_session(default_timeout=0.5) | ||
| start = time.monotonic() | ||
| result = asyncio.run(session.tool_call_async("transcribe_0", {}, request_timeout=0.05)) | ||
| elapsed = time.monotonic() - start | ||
| assert result == "done" | ||
| assert elapsed < 0.3 | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import { Input, NumberInput } from '@/components/ui/input'; | |
| import { Label } from '@/components/ui/label'; | ||
| import { Separator } from '@/components/ui/separator'; | ||
| import { Switch } from '@/components/ui/switch'; | ||
| import NumberInputStepper from '@/components/originui/number-input'; | ||
| import { useFindLlmByUuid } from '@/hooks/use-llm-request'; | ||
| import { zodResolver } from '@hookform/resolvers/zod'; | ||
| import { get } from 'lodash'; | ||
|
|
@@ -49,6 +50,7 @@ import { | |
| useHandleShowStructuredOutput, | ||
| useShowStructuredOutputDialog, | ||
| } from './use-show-structured-output-dialog'; | ||
| import { useGetAgentMCPIds } from './use-get-tools'; | ||
| import { useValues } from './use-values'; | ||
| import { useWatchFormChange } from './use-watch-change'; | ||
|
|
||
|
|
@@ -74,6 +76,7 @@ const FormSchema = z.object({ | |
| exception_method: z.string().optional(), | ||
| exception_goto: z.array(z.string()).optional(), | ||
| exception_default_value: z.string().optional(), | ||
| tool_timeout: z.coerce.number().optional(), | ||
| ...LargeModelFilterFormSchema, | ||
| cite: z.boolean().optional(), | ||
| showStructuredOutput: z.boolean().optional(), | ||
|
|
@@ -118,6 +121,8 @@ function AgentForm({ node }: INextOperatorForm) { | |
| name: 'exception_method', | ||
| }); | ||
|
|
||
| const { mcpIds } = useGetAgentMCPIds(); | ||
|
|
||
| const showStructuredOutput = useWatch({ | ||
| control: form.control, | ||
| name: 'showStructuredOutput', | ||
|
|
@@ -248,6 +253,29 @@ function AgentForm({ node }: INextOperatorForm) { | |
| </FormItem> | ||
| )} | ||
| /> | ||
| {mcpIds.length > 0 && ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We recommend using RAGFlowFormItem to reduce code and ensure consistent styles. |
||
| <FormField | ||
| control={form.control} | ||
| name={`tool_timeout`} | ||
| render={({ field }) => ( | ||
| <FormItem className="flex-1"> | ||
| <FormLabel tooltip={t('flow.toolTimeoutTip')}> | ||
| {t('flow.toolTimeout')} | ||
| </FormLabel> | ||
| <FormControl> | ||
| <div className="flex gap-2 items-center"> | ||
| <NumberInputStepper | ||
| value={field.value} | ||
| onChange={field.onChange} | ||
| min={1} | ||
| />{' '} | ||
| {t('flow.seconds')} | ||
| </div> | ||
| </FormControl> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| )} | ||
| {hasSubAgentOrTool(edges, node?.id) && ( | ||
| <FormField | ||
| control={form.control} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 50375
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 50375
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 11777
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 13718
Validate
tool_timeoutat component construction.The form accepts optional values, including zero, and
agent/component/agent_with_tools.py#L115-L117converts falsy values to10.agent/tools/base.py#L60then uses whatever default came from construction, so invalid settings can hide behind the fallback or propagate to MCP calls. Reject values below the intended minimum (for example, less than1) before creatingLLMToolPluginCallSession.📍 Affects 3 files
agent/tools/base.py#L51-L60(this comment)agent/component/agent_with_tools.py#L115-L117web/src/pages/agent/form/agent-form/index.tsx#L79-L79🤖 Prompt for AI Agents