feat(agent): support helper tool loops and injected prompts - #7439
Conversation
Coverage Report
File CoverageNo changed files found. |
|
✅ Admin Preview Image Ready! 🕒 Time: 2026-08-04 11:25:07 (UTC+8) |
|
✅ Build Successful - Preview fastgpt Image for this PR: 🕒 Time: 2026-08-04 11:28:19 (UTC+8) |
There was a problem hiding this comment.
Pull request overview
This PR refactors Agent Loop prompt handling so that callers explicitly compose the final systemPrompt (including optional sandbox guidance and injected prompt extensions), while Agent Loop providers treat systemPrompt as an already-final string and avoid implicit prompt-mode behavior. It also updates auxiliary-generation to reuse the standard Agent Loop ask_user pause/resume and provider-state lifecycle, and adds/updates tests and design documentation accordingly.
Changes:
- Remove prompt-mode-driven prompt injection and expose
buildDefaultAgentSystemPromptfor caller-side system prompt composition (with optional sandbox + extension sections). - Update Workflow Agent + ToolCall to pass a normalized
systemPromptseparately from conversation messages (system messages stripped from the message list). - Extend auxiliary-generation to support
ask_userloops and injected runtime tools/executor, preservingpaused/providerStatesemantics; update tests and design doc.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/service/test/core/workflow/dispatch/ai/toolcall/toolcall/toolCall.test.ts | Adds coverage to ensure system messages are extracted into systemPrompt and removed from conversation messages. |
| packages/service/test/core/workflow/dispatch/ai/agentLoopCore/context/messages.test.ts | Removes tests for deleted agentLoopCore prompt helper utilities. |
| packages/service/test/core/workflow/dispatch/ai/agent/index.test.ts | Updates expectations to reflect default system prompt builder + sandbox section behavior. |
| packages/service/test/core/ai/llm/agentLoop/piAgentProvider.test.ts | Aligns provider tests with “caller supplies final systemPrompt” behavior. |
| packages/service/test/core/ai/llm/agentLoop/mainPrompt.test.ts | Replaces getMainAgentSystemPrompt tests with buildDefaultAgentSystemPrompt tests (extension/user prompt separation, sandbox injection). |
| packages/service/test/core/ai/llm/agentLoop/fastAgentProvider.test.ts | Adds coverage ensuring provider uses final input.systemPrompt and strips stale system messages from input.messages. |
| packages/service/test/core/ai/llm/agentLoop/fastAgentLoop.test.ts | Updates main loop tests to pass buildDefaultAgentSystemPrompt() explicitly; removes runtime-tool-constraint prompt-mode assertions. |
| packages/service/test/core/ai/auxiliaryGeneration/agentLoop.test.ts | New test validating auxiliary-generation Agent Loop supports ask pause/resume + provider state + runtime tools injection. |
| packages/service/core/workflow/dispatch/ai/toolcall/toolCall.ts | Extracts system prompt from system-role messages (including text-part arrays) and passes it separately to agent-loop input. |
| packages/service/core/workflow/dispatch/ai/agentLoopCore/interface/index.ts | Stops exporting deleted prompt helper. |
| packages/service/core/workflow/dispatch/ai/agentLoopCore/application/context/prompt.ts | Deletes legacy prompt rewrite/merge helpers. |
| packages/service/core/workflow/dispatch/ai/agentLoopCore/application/context/index.ts | Removes re-export of deleted prompt module. |
| packages/service/core/workflow/dispatch/ai/agent/index.ts | Switches to building final systemPrompt via buildDefaultAgentSystemPrompt after runtime creation; passes it into agent loop input. |
| packages/service/core/ai/llm/agentLoop/provider/piAgent/run.ts | Removes provider-side prompt-mode branching; consumes input.systemPrompt directly. |
| packages/service/core/ai/llm/agentLoop/provider/fastAgent/loop/type.ts | Removes promptMode from runtime type. |
| packages/service/core/ai/llm/agentLoop/provider/fastAgent/loop/index.ts | Removes prompt-mode injection path; builds initial messages from input.systemPrompt + non-system conversation messages. |
| packages/service/core/ai/llm/agentLoop/provider/fastAgent/index.ts | Stops threading removed promptMode into internal runtime. |
| packages/service/core/ai/llm/agentLoop/domain/runtime.ts | Removes promptMode from LLM params type. |
| packages/service/core/ai/llm/agentLoop/domain/mainPrompt.ts | Introduces buildDefaultAgentSystemPrompt (default + sandbox + extension + user section). |
| packages/service/core/ai/llm/agentLoop/domain/index.ts | Re-exports mainPrompt domain module. |
| packages/service/core/ai/auxiliaryGeneration/type.ts | Extends processor/run params to accept userAnswer; extends response to optionally return memories. |
| packages/service/core/ai/auxiliaryGeneration/service.ts | Passes through userAnswer to auxiliary-generation processor. |
| packages/service/core/ai/auxiliaryGeneration/agentLoop.ts | Reworks auxiliary-generation Agent Loop to enable ask_user, accept runtime tools/executor, forward deltas, and preserve pause/provider state. |
| .agents/design/core/ai/auxiliary-generation.md | Updates design doc to match implemented auxiliary-generation Agent Loop semantics (ask pause/resume, tool injection, providerState persistence). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * 构建进入主 Agent 的初始消息链。 | ||
| * raw 模式完全尊重调用方传入的 messages;fastAgent 模式会注入平台主提示词并剔除外部 system。 | ||
| * systemPrompt 是调用方已经组装完成的最终提示词;messages 中的 system message 不再重复注入。 | ||
| */ | ||
| const buildInitialMessages = ({ | ||
| input, | ||
| hasRuntimeTools, | ||
| promptMode = 'fastAgent' | ||
| }: { | ||
| input: FastAgentLoopInput; | ||
| hasRuntimeTools: boolean; | ||
| promptMode?: AgentLoopRuntime['promptMode']; | ||
| }): ChatCompletionMessageParam[] => { | ||
| if (promptMode === 'raw') { | ||
| return input.messages; | ||
| } | ||
|
|
||
| return [ | ||
| createSystemMessage( | ||
| getMainAgentSystemPrompt({ | ||
| systemPrompt: input.systemPrompt, | ||
| hasRuntimeTools | ||
| }) | ||
| ), | ||
| ...stripSystemMessages(input.messages) | ||
| ]; | ||
| }; | ||
| const buildInitialMessages = ({ input }: { input: FastAgentLoopInput }) => [ |
What changed
ask_userflow, runtime tools,userAnswer, and provider state.Why
Prompt construction and helper generation previously had parallel behavior outside the main Agent Loop. The new API makes ownership explicit and lets helper generation reuse the normal tool, pause/resume, transcript, and provider-state lifecycle.
Impact
Workflow Agent behavior remains caller-configured, while helper callers can disable planning, enable asking, register completion tools, and stream responses without custom pause detection.
Validation
prohelper suite: 4 files, 12 tests passed.agent/index.ts.Dependency
Paired PR: https://github.com/labring/fastgpt-pro/pull/1048
This PR intentionally does not update the
progitlink to a fork-only commit. Merge the pairedfastgpt-proPR first, then update this branch to the resulting upstream commit before marking it ready.