Skip to content

HDDS-15570. [Recon-Chatbot] Call Recon methods directly instead of using HTTP-calls.#10524

Merged
ArafatKhan2198 merged 9 commits into
apache:masterfrom
ArafatKhan2198:mcp-design
Jun 24, 2026
Merged

HDDS-15570. [Recon-Chatbot] Call Recon methods directly instead of using HTTP-calls.#10524
ArafatKhan2198 merged 9 commits into
apache:masterfrom
ArafatKhan2198:mcp-design

Conversation

@ArafatKhan2198

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR refactors the Recon chatbot so it fetches cluster data by calling Recon methods in-process, instead of making HTTP requests back to the same Recon server.

Previously, the chatbot ran inside the Recon JVM but still used the Recon REST API to answer questions. That added unnecessary overhead: URL construction, HTTP handling, and response parsing for data Recon already exposes in Java.

This change introduces a direct query path (ReconQueryExecutorReconEndpointRouter, and related helpers) that maps LLM-selected tools to the corresponding Recon logic. LangChain4j native tool-calling is used end to end for tool selection and execution. The old HTTP-based tool executor and OpenAPI-driven prompt resources are removed in favor of a simpler tool semantics model.

Existing safety behavior is preserved: only allowlisted tools can run, query limits are enforced, and scoped queries (for example, bucket-scoped key listing) still apply. The public Recon REST API used by the UI is unchanged.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15570

How was this patch tested?

  • Unit tests added/updated for the chatbot agent, LLM routing, and direct Recon query path (TestReconQueryExecutorTestReconEndpointRouterTestReconApiAllowlistTestLlmRouting, and related agent/LLM tests)
  • Existing chatbot tests updated to reflect the new direct-call flow

ArafatKhan2198 and others added 5 commits June 16, 2026 13:56
Use validateToolCall/validateToolCalls for pre-execution checks, raise
summarization max_tokens for reasoning models, and handle null provider text.

Co-authored-by: Cursor <cursoragent@cursor.com>
…trics tool, and improve tool semantics.

- Introduce GenParams (typed temperature + maxTokens) to replace untyped Map<String,Object>
  parameter passing; delete four dead parse helpers in LangChain4jDispatcher.
- Decompose chatWithTools into buildChatRequest / toLangChain4jToolSpecs / invokeModel /
  toLLMResponse private helpers; merge chatWithTools into a single chatCompletion method.
- Rename getToolCall → chooseToolsForQuery for clarity.
- Inline ReconQueryRequest (single-use DTO); ReconQueryExecutor now accepts (toolName, params)
  directly.
- Remove write-only LLMResponse.metadata field; retype ReconQueryResult.responseBody to JsonNode;
  delete dead ChatbotUtils.extractFirstJsonObject and its test class.
- Replace if/else if chain in ReconEndpointRouter with a switch; extract dense multi-arg dispatch
  branches into named helpers; fix checkstyle (import order, missing braces, long lines).
- Remove api_v1_metrics_api tool (Prometheus proxy): drop from allowlist, LlmToolSpecFactory,
  router, and test fixtures; router is now entirely in-JVM.
- Rewrite recon-tool-semantics.md as a method-call/tool-selection guide: endpoint-by-endpoint
  coverage, explicit open-vs-committed/FSO-trap and task-status disambiguation, parameter
  extraction rules, behavior-honesty contract (1000-record cap, not-randomized), and a
  ~55-row regression test matrix.
- Update test fixtures for all signature changes; delete TestChatbotAgentJsonExtraction.

Co-Authored-By: Claude <noreply@anthropic.com>
Align the chatbot test suite with the native-tool-call design and cover
branches that previously had no tests.

- Update stale agent/dispatcher tests to drive tool selection via native tool
  calls (not text-JSON envelopes) and the merged chatCompletion signature:
  TestChatbotAgentExecutionPolicy, TestChatbotAgentListKeysPolicy,
  TestChatbotAgentToolCallParsing, TestLangChain4jDispatcher.
- Drop the two listKeys prefix-validation tests from
  TestReconQueryExecutorListKeys; that validation now lives in
  ChatbotAgent.validateToolCall.
- Add TestReconToolCatalogConsistency: asserts the LLM tool catalog, the
  ReconApiAllowlist, and the router stay in sync (set equality + routability).
  Add ReconApiAllowlist.getRegisteredTools() to support it.
- Add TestChatbotUtils: bucket-scoped prefix check, limit parsing, and
  record-count estimation edge cases.
- Extend TestReconEndpointRouter with per-tool parameter-extraction checks.
- Add TestChatbotAgentMultiToolAndSummary: multi-tool partial failure,
  response-key de-duplication, and blank-summary fallback.
- Reconcile CODE_FLOW.md line references with the current code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@devmadhuu devmadhuu self-requested a review June 22, 2026 06:07

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

Thanks @ArafatKhan2198 for the patch. Few comments, pls check.

Cache static tool specs, centralize query-param names on ReconConstants, and
replace hardcoded record counting with a recursive array-of-objects estimator so
truncation metadata is accurate across Recon response shapes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Split tool-spec builder for method length, reorder imports, add missing
Javadoc, remove unused test imports, and suppress ParameterNumber on router.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ArafatKhan2198 ArafatKhan2198 changed the title [Recon-Chatbot] Call Recon methods directly instead of using HTTP-calls. HDDS-15570. [Recon-Chatbot] Call Recon methods directly instead of using HTTP-calls. Jun 22, 2026
This file was local reference material and should not be tracked or
subject to RAT license checks.

Co-authored-by: Cursor <cursoragent@cursor.com>

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

Thanks @ArafatKhan2198 for improving the patch. Changes LGTM +1. Let CI gets green.

Hoist ToolSelectionKind out of the inner class and use local mocks in
TestReconEndpointRouter setUp for endpoints only passed to the constructor.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ArafatKhan2198 ArafatKhan2198 marked this pull request as ready for review June 23, 2026 07:10
@ArafatKhan2198 ArafatKhan2198 requested a review from devmadhuu June 23, 2026 08:36
@ArafatKhan2198 ArafatKhan2198 merged commit e596681 into apache:master Jun 24, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants