Skip to content

add agentic for query service subcommand - #2572

Open
jperez999 wants to merge 1 commit into
NVIDIA:mainfrom
jperez999:query-agentic-service
Open

add agentic for query service subcommand#2572
jperez999 wants to merge 1 commit into
NVIDIA:mainfrom
jperez999:query-agentic-service

Conversation

@jperez999

Copy link
Copy Markdown
Collaborator

Description

Implemented retriever query service QUERY --agentic.

It now forwards agentic: true to the service’s /v1/query endpoint while using the service-owned LLM and embedding configuration—no local --agentic-* options are
added.

Updated CLI/service wiring and tests in nemo_retriever/src/nemo_retriever/cli/query/app.py, nemo_retriever/src/nemo_retriever/query/service.py, and nemo_retriever/
src/nemo_retriever/service/client.py. Documentation now includes the service CLI example.

Validation passed: 67 focused tests. git diff --check passed. Strict MkDocs build could not run because mkdocs is not installed.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@jperez999 jperez999 self-assigned this Aug 24, 2026
@jperez999
jperez999 requested review from a team as code owners August 24, 2026 02:52
@jperez999
jperez999 requested a review from jdye64 August 24, 2026 02:52
@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds an --agentic option to the service-query CLI and forwards it through ServiceQueryRequest and RetrieverServiceClient to POST /v1/query. It also adds focused tests and documents use of the service-owned agentic configuration.

  • Adds agentic request propagation across CLI, query orchestration, and synchronous/asynchronous service clients.
  • Documents the new service CLI invocation and configuration ownership.
  • Adds tests for CLI forwarding and request payload construction.

Confidence Score: 2/5

The PR should not merge until unsupported batched agentic requests, candidate-pool limit failures, and incorrect evidence provenance are addressed.

The new agentic path accepts a request shape the service rejects, can substitute candidate_k into the service's constrained agentic top_k, and reports agentic evidence as semantic retrieval.

Files Needing Attention: nemo_retriever/src/nemo_retriever/service/client.py, nemo_retriever/src/nemo_retriever/query/service.py, nemo_retriever/src/nemo_retriever/cli/query/app.py, nemo_retriever/src/nemo_retriever/query/options.py

Important Files Changed

Filename Overview
nemo_retriever/src/nemo_retriever/cli/query/app.py Adds --agentic forwarding, but evidence output still labels agentic results as semantic retrieval.
nemo_retriever/src/nemo_retriever/query/options.py Adds the agentic request field, but the user-facing setting remains in an unvalidated dataclass.
nemo_retriever/src/nemo_retriever/query/service.py Forwards agentic mode while reusing candidate_k as endpoint top_k, which can trigger the service's agentic backend-depth validation.
nemo_retriever/src/nemo_retriever/service/client.py Adds agentic payload support but permits unsupported list-query combinations and leaves the new public parameter undocumented.
nemo_retriever/tests/test_service_query_client.py Covers agentic payload forwarding but does not exercise the unsupported list-query combination.
nemo_retriever/tests/test_root_query_cli.py Covers CLI flag forwarding but not candidate_k limits or evidence provenance in agentic mode.
nemo_retriever/tests/test_query_workflow_options.py Updates service orchestration expectations for agentic forwarding without covering its interaction with candidate_k.
docs/docs/extraction/workflow-agentic-retrieval.md Documents the service-query agentic CLI workflow and clarifies that model configuration belongs to the service.
nemo_retriever/docs/cli/README.md Adds an accurate quick-start example for invoking service-owned agentic retrieval.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    CLI[retriever query service --agentic] --> Request[ServiceQueryRequest]
    Request --> Orchestration[query.service.query_documents]
    Orchestration --> Client[RetrieverServiceClient query/aquery]
    Client --> API[POST /v1/query agentic=true]
    API --> Agentic[Service-owned agentic workflow]
    Agentic --> Hits[Query hits]
    Hits --> Shape[Local result shaping]
    Shape --> Output[CLI JSON or evidence output]
Loading
Prompt To Fix All With AI
### Issue 1
nemo_retriever/src/nemo_retriever/service/client.py:584-591
**Reject batched agentic queries**

When `query()` or `aquery()` receives a list of query strings with `agentic=True`, the client serializes both values even though the service requires a single string for agentic mode, causing the request to fail service validation instead of returning results.

### Issue 2
nemo_retriever/src/nemo_retriever/query/service.py:30
**Candidate pool exceeds agentic depth**

When an agentic service query has a valid final `top_k` but a `candidate_k` above the configured `agentic.backend_top_k`, this call sends `candidate_k` as the endpoint's `top_k`, causing the service to reject the request with HTTP 422.

### Issue 3
nemo_retriever/src/nemo_retriever/cli/query/app.py:340
**Agentic evidence mislabeled semantic**

When `--agentic` is combined with `--format evidence`, the command runs the service's agentic workflow but still passes `strategies=["semantic"]` to output shaping, causing `coverage.strategies_used` to report incorrect provenance.

### Issue 4
nemo_retriever/src/nemo_retriever/service/client.py:556-563
**Document the agentic parameter**

The public `query()` and `aquery()` methods add `agentic` without documenting its behavior or single-query restriction, leaving library users unable to discover this changed request contract from the API documentation.

### Issue 5
nemo_retriever/src/nemo_retriever/query/options.py:95
**Validate the agentic request setting**

The new user-facing `agentic` setting is added to an unvalidated dataclass without descriptive field metadata, so unsupported option combinations are not rejected at request construction and instead fail later at the remote service boundary.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "add agentic for query service subcommand" | Re-trigger Greptile

Comment on lines +584 to +591
agentic: bool = False,
) -> list[list[dict[str, Any]]] | list[QueryHit]:
"""Asynchronously search through ``POST /v1/query``."""

payload: dict[str, Any] = {"query": query, "top_k": int(top_k)}
if collection_name:
payload["collection_name"] = collection_name
if agentic:

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.

P1 Reject batched agentic queries

When query() or aquery() receives a list of query strings with agentic=True, the client serializes both values even though the service requires a single string for agentic mode, causing the request to fail service validation instead of returning results.

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/service/client.py
Line: 584-591

Comment:
**Reject batched agentic queries**

When `query()` or `aquery()` receives a list of query strings with `agentic=True`, the client serializes both values even though the service requires a single string for agentic mode, causing the request to fail service validation instead of returning results.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

api_token=request.service.service_api_token,
)
raw_result_sets = client.query(request.query, top_k=retrieval_top_k)
raw_result_sets = client.query(request.query, top_k=retrieval_top_k, agentic=request.agentic)

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.

P1 Candidate pool exceeds agentic depth

When an agentic service query has a valid final top_k but a candidate_k above the configured agentic.backend_top_k, this call sends candidate_k as the endpoint's top_k, causing the service to reject the request with HTTP 422.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/query/service.py
Line: 30

Comment:
**Candidate pool exceeds agentic depth**

When an agentic service query has a valid final `top_k` but a `candidate_k` above the configured `agentic.backend_top_k`, this call sends `candidate_k` as the endpoint's `top_k`, causing the service to reject the request with HTTP 422.

**Knowledge Base Used:**
- [Query workflow orchestration](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/query-workflow-orchestration.md)
- [Retriever service](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/retriever-service.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

content_types: opts.ContentTypesOption = None,
output_format: opts.OutputFormatOption = "hits",
max_text_chars: opts.MaxTextCharsOption = None,
agentic: opts.AgenticOption = False,

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.

P1 Agentic evidence mislabeled semantic

When --agentic is combined with --format evidence, the command runs the service's agentic workflow but still passes strategies=["semantic"] to output shaping, causing coverage.strategies_used to report incorrect provenance.

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/cli/query/app.py
Line: 340

Comment:
**Agentic evidence mislabeled semantic**

When `--agentic` is combined with `--format evidence`, the command runs the service's agentic workflow but still passes `strategies=["semantic"]` to output shaping, causing `coverage.strategies_used` to report incorrect provenance.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +556 to 563
agentic: bool = False,
) -> list[list[dict[str, Any]]] | list[QueryHit]:
"""Search ingested documents through ``POST /v1/query``.

Note:
``top_k`` is required here but defaults to 10 on :meth:`aquery`.
That asymmetry is part of the released signature; do not unify it.
"""

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.

P2 Document the agentic parameter

The public query() and aquery() methods add agentic without documenting its behavior or single-query restriction, leaving library users unable to discover this changed request contract from the API documentation.

Rule Used: Every public class and function in nemo_retriever ... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/service/client.py
Line: 556-563

Comment:
**Document the agentic parameter**

The public `query()` and `aquery()` methods add `agentic` without documenting its behavior or single-query restriction, leaving library users unable to discover this changed request contract from the API documentation.

**Rule Used:** Every public class and function in nemo_retriever ... ([source](https://github.com/nvidia/nemo-retriever/blob/f41b14e714a1883d2d8640ff2c23991b7ed9ca6d/nemo_retriever/.greptile/config.json))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

query: str
retrieval: QueryRetrievalOptions = field(default_factory=QueryRetrievalOptions)
service: QueryServiceOptions = field(default_factory=QueryServiceOptions)
agentic: bool = False

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.

P2 Validate the agentic request setting

The new user-facing agentic setting is added to an unvalidated dataclass without descriptive field metadata, so unsupported option combinations are not rejected at request construction and instead fail later at the remote service boundary.

Rule Used: User-facing configuration must use Pydantic models... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/query/options.py
Line: 95

Comment:
**Validate the agentic request setting**

The new user-facing `agentic` setting is added to an unvalidated dataclass without descriptive field metadata, so unsupported option combinations are not rejected at request construction and instead fail later at the remote service boundary.

**Rule Used:** User-facing configuration must use Pydantic models... ([source](https://github.com/nvidia/nemo-retriever/blob/f41b14e714a1883d2d8640ff2c23991b7ed9ca6d/nemo_retriever/.greptile/config.json))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

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.

1 participant