Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
43bd4f9c
authored
Jul 24, 2026
by
YeYuheng
Committed by
GitHub
Jul 24, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(agent): recognize internal runtime tools (#7367)
parent
583d7297
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
2 deletions
+130
-2
packages/service/core/ai/llm/agentLoop/provider/fastAgent/loop/index.ts
+5
-1
packages/service/core/ai/llm/agentLoop/provider/piAgent/run.ts
+5
-1
packages/service/test/core/ai/llm/agentLoop/fastAgentLoop.test.ts
+52
-0
packages/service/test/core/ai/llm/agentLoop/piAgentProvider.test.ts
+68
-0
No files found.
packages/service/core/ai/llm/agentLoop/provider/fastAgent/loop/index.ts
View file @
43bd4f9c
...
...
@@ -182,7 +182,11 @@ export const runFastAgentMainLoop = async <TChildrenResponse = unknown>({
toolCatalog
:
normalized
};
const
hasRuntimeTools
=
normalized
.
runtimeTools
.
length
>
0
;
const
hasRuntimeTools
=
normalized
.
runtimeTools
.
length
>
0
||
(
normalized
.
sandboxTools
?.
length
??
0
)
>
0
||
!!
normalized
.
readFileTool
||
!!
normalized
.
datasetSearchTool
;
let
pendingAsk
:
|
{
...
...
packages/service/core/ai/llm/agentLoop/provider/piAgent/run.ts
View file @
43bd4f9c
...
...
@@ -403,7 +403,11 @@ export const runPiAgentLoop = async <TChildrenResponse = unknown>({
?
input
.
systemPrompt
||
''
:
getMainAgentSystemPrompt
({
systemPrompt
:
input
.
systemPrompt
,
hasRuntimeTools
:
runtime
.
toolCatalog
.
runtimeTools
.
length
>
0
hasRuntimeTools
:
runtime
.
toolCatalog
.
runtimeTools
.
length
>
0
||
runtime
.
systemTools
?.
sandbox
?.
enabled
===
true
||
runtime
.
systemTools
?.
readFile
?.
enabled
===
true
||
runtime
.
systemTools
?.
datasetSearch
?.
enabled
===
true
});
const
agent
=
new
Agent
({
initialState
:
{
...
...
packages/service/test/core/ai/llm/agentLoop/fastAgentLoop.test.ts
View file @
43bd4f9c
...
...
@@ -165,6 +165,58 @@ describe('runFastAgentMainLoop', () => {
expect
(
mainAgentPrompt
).
toContain
(
'options:2 到 5 个'
);
});
it
.
each
([
{
name
:
'no runtime-capable tools'
,
toolCatalog
:
{
runtimeTools
:
[]
},
expectedConstraint
:
true
},
{
name
:
'sandbox tools only'
,
toolCatalog
:
{
runtimeTools
:
[],
sandboxTools
:
[
tool
(
'sandbox_shell'
)]
},
expectedConstraint
:
false
},
{
name
:
'read file tool only'
,
toolCatalog
:
{
runtimeTools
:
[],
readFileTool
:
tool
(
'read_files'
)
},
expectedConstraint
:
false
},
{
name
:
'dataset search tool only'
,
toolCatalog
:
{
runtimeTools
:
[],
datasetSearchTool
:
tool
(
'dataset_search'
)
},
expectedConstraint
:
false
}
]
satisfies
Array
<
{
name
:
string
;
toolCatalog
:
AgentLoopRuntime
[
'toolCatalog'
];
expectedConstraint
:
boolean
;
}
>
)(
'sets the runtime tool constraint correctly with $name'
,
async
({
toolCatalog
,
expectedConstraint
})
=>
{
mockCreateLLMResponseQueue
(
createLLMResponseMock
,
[
text
({
requestId
:
'req_runtime_tool_constraint'
,
content
:
'direct answer'
})
]);
await
runFastAgentMainLoop
({
runtime
:
createRuntime
({
toolCatalog
}),
input
:
{
messages
:
[
{
role
:
ChatCompletionRequestMessageRoleEnum
.
User
,
content
:
'hello'
}
]
}
});
const
mainAgentPrompt
=
createLLMResponseMock
.
mock
.
calls
[
0
][
0
].
body
.
messages
[
0
].
content
;
expect
(
mainAgentPrompt
.
includes
(
'<tool_constraint>'
)).
toBe
(
expectedConstraint
);
}
);
it
(
'creates an active plan through set_plan'
,
async
()
=>
{
const
events
:
any
[]
=
[];
mockCreateLLMResponseQueue
(
createLLMResponseMock
,
[
...
...
packages/service/test/core/ai/llm/agentLoop/piAgentProvider.test.ts
View file @
43bd4f9c
import
{
beforeEach
,
describe
,
expect
,
it
,
vi
}
from
'vitest'
;
import
type
{
LLMModelItemType
}
from
'@fastgpt/global/core/ai/model.schema'
;
import
{
ModelTypeEnum
}
from
'@fastgpt/global/core/ai/constants'
;
import
type
{
AgentLoopSystemTools
}
from
'@fastgpt/service/core/ai/llm/agentLoop/domain'
;
const
{
agentPromptMock
,
...
...
@@ -366,6 +367,73 @@ describe('runPiAgentLoop', () => {
]);
});
it
.
each
([
{
name
:
'no runtime-capable tools'
,
systemTools
:
undefined
,
expectedConstraint
:
true
},
{
name
:
'sandbox tools only'
,
systemTools
:
{
sandbox
:
{
enabled
:
true
,
client
:
{}
as
any
}
},
expectedConstraint
:
false
},
{
name
:
'read file tool only'
,
systemTools
:
{
readFile
:
{
enabled
:
true
,
maxFileAmount
:
20
,
execute
:
vi
.
fn
()
}
},
expectedConstraint
:
false
},
{
name
:
'dataset search tool only'
,
systemTools
:
{
datasetSearch
:
{
enabled
:
true
,
execute
:
vi
.
fn
()
}
},
expectedConstraint
:
false
}
]
satisfies
Array
<
{
name
:
string
;
systemTools
?:
AgentLoopSystemTools
;
expectedConstraint
:
boolean
;
}
>
)(
'sets the runtime tool constraint correctly with $name'
,
async
({
systemTools
,
expectedConstraint
})
=>
{
await
runPiAgentLoop
({
input
:
{
messages
:
[{
role
:
'user'
,
content
:
'hello'
}]
},
runtime
:
{
llmParams
:
{
model
:
'gpt-5'
},
systemTools
,
toolCatalog
:
{
runtimeTools
:
[]
},
executeTool
:
vi
.
fn
(),
checkIsStopping
:
vi
.
fn
(()
=>
false
)
}
});
expect
(
agentConstructorArgs
.
at
(
-
1
).
initialState
.
systemPrompt
.
includes
(
'<tool_constraint>'
)
).
toBe
(
expectedConstraint
);
}
);
it
(
'preserves multimodal content in the current user prompt'
,
async
()
=>
{
await
runPiAgentLoop
({
input
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment