refactor(ai): collapse ReAct into a single reason-act loop - #1533
Open
larry-zy wants to merge 1 commit into
Open
refactor(ai): collapse ReAct into a single reason-act loop#1533larry-zy wants to merge 1 commit into
larry-zy wants to merge 1 commit into
Conversation
Fold the two-stage reasonAct/observe pipeline into one bounded reason-act loop: each iteration is a single model call that either requests tools (results fed back as context) or answers directly — a tool-free response IS the final answer, so no separate observe stage is needed to decide when to stop. The last iteration drops tools and forces a final answer so the loop always terminates. - Remove the orchestrator/state/step/runLoop scaffolding and the fallback handler package; drive the loop directly from run(). - Flatten AgentSpec to a single prompt_file; derive the tool-less answer prompt from the same system prompt plus an answer directive. - Drop the agentObserve.txt prompt; keep agentReasonAct.txt. - Update agent.schema.json, config loader test, e2e test and fixtures to the flat single-stage config.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the AI ReAct agent into a bounded single-call reason-act loop.
Changes:
- Replaces staged orchestration with direct tool-or-answer iterations.
- Flattens agent configuration and removes observe/fallback infrastructure.
- Removes page-context handling and changes model configuration.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
ai/testutils/fixtures.go |
Updates agent fixtures. |
ai/test/e2e/rag_complete_flow_test.go |
Updates e2e configuration. |
ai/schema/react.go |
Removes context from user input. |
ai/schema/json/agent.schema.json |
Flattens agent schema. |
ai/schema/context.go |
Deletes page-context types. |
ai/prompts/agentReasonAct.txt |
Enables direct final answers. |
ai/prompts/agentObserve.txt |
Deletes observe prompt. |
ai/config/test/loader_test.go |
Updates default-loading assertions. |
ai/component/server/engine/models.go |
Removes request context. |
ai/component/server/engine/handlers.go |
Stops forwarding page context. |
ai/component/server/engine/handlers_test.go |
Deletes context contract tests. |
ai/component/server/engine/docs/openapi.yaml |
Removes context API schemas. |
ai/component/server/engine/context.go |
Deletes context validation and sanitization. |
ai/component/server/engine/context_test.go |
Deletes context tests. |
ai/component/models/models.yaml |
Changes available/default models. |
ai/component/agent/react/test/flow_test.go |
Tests flattened validation. |
ai/component/agent/react/steps.go |
Implements the unified loop. |
ai/component/agent/react/step_test.go |
Tests direct and tool-assisted answers. |
ai/component/agent/react/react.go |
Simplifies agent construction and interaction. |
ai/component/agent/react/prompt.go |
Builds act and forced-answer prompts. |
ai/component/agent/react/page_context.go |
Deletes context injection. |
ai/component/agent/react/page_context_test.go |
Deletes context injection tests. |
ai/component/agent/react/orchestrator.go |
Deletes staged orchestration. |
ai/component/agent/react/orchestrator_test.go |
Deletes orchestrator tests. |
ai/component/agent/react/factory.go |
Passes the flattened specification. |
ai/component/agent/react/config.go |
Defines flat agent configuration. |
ai/component/agent/react/component.go |
Stores and initializes from AgentSpec. |
ai/component/agent/fallback/handler.go |
Deletes observation fallback handling. |
ai/component/agent/agent.yaml |
Configures the unified loop. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| context: | ||
| $ref: "#/components/schemas/AIContextSnapshot" | ||
| additionalProperties: false | ||
| properties: {} |
Comment on lines
+86
to
+87
| ra.finish(chans, history, sessionID, resp.Text()) | ||
| return usage, nil |
Comment on lines
+39
to
+40
| Message string `json:"message" binding:"required"` // User message | ||
| SessionID string `json:"sessionID" binding:"required"` // Session ID |
| type: models | ||
| spec: | ||
| default_model: "dashscope/qwen3.7-max" | ||
| default_model: "dashscope/qwen-max" |
Comment on lines
+58
to
+61
| forceAnswer := i == ra.maxIterations-1 | ||
| prompt := ra.actPrompt | ||
| if forceAnswer { | ||
| prompt = ra.answerPrompt |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What
Collapse the two-stage
reasonAct/observeReAct pipeline into one bounded reason-act loop.Each iteration is a single model call that either requests tools (whose results are fed back as context for the next iteration) or answers directly — a tool-free response is the final answer, so no separate
observereasoning step is needed to decide when to stop. The last allowed iteration drops the tools and forces a final answer, so the loop always terminates with a real reply rather than exhausting its budget in silence.Changes
fallbackhandler package; drive the loop directly fromrun().AgentSpecto a singleprompt_file; derive the tool-less answer prompt from the same system prompt plus an answer directive.agentObserve.txtprompt; keepagentReasonAct.txt.agent.schema.json, the config loader test, the e2e test and fixtures to the flat single-stage config.Scope
Backend only — all changes are under
ai/. No frontend (ui-vue3/) changes.Verification
go build ./...passes.