Skip to content

refactor(ai): collapse ReAct into a single reason-act loop - #1533

Open
larry-zy wants to merge 1 commit into
apache:aifrom
larry-zy:refactor/react-single-loop
Open

refactor(ai): collapse ReAct into a single reason-act loop#1533
larry-zy wants to merge 1 commit into
apache:aifrom
larry-zy:refactor/react-single-loop

Conversation

@larry-zy

Copy link
Copy Markdown

What

Collapse the two-stage reasonAct / observe ReAct 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 observe reasoning 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

  • 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, 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.
  • ReAct unit / step / flow tests updated to the single-loop shape.

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.
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants