feat(cli): add Agent-friendly output flags (-q, -f json, --with-sources) to query command - #2
Open
als3453 wants to merge 1 commit into
Open
Conversation
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.
Summary
Adds 3 new flags to the
rag-python queryCLI command, enabling the tool to be callable as a structured Agent tool (viasubprocess+json.loads()), while remaining fully backward-compatible.New flags
-q/--quiet-f/--output-format {text,json,json-pretty}{text, sources, evaluation, retried}— designed for Agent tool use.--with-sourcesExample: calling as an Agent tool
Why this change (motivation)
Currently, Agent orchestrators (LangChain / CrewAI / custom ReAct loops) that want to wrap
rag-pythonas a Tool / Function Calling payload have to:This PR turns the CLI into a first-class structured output endpoint with 0 breaking changes to the default user experience.
Testing
Added 8 hermetic unit tests under
tests/test_cli_query_agent_output.py:--helplists all 3 new flags and their short aliases--quietprints the answer only (no trailers)-qshort alias equals--quiet-f jsonproduces valid JSON with 4 keys + full sources list-f json-prettyproduces valid, indent=2 pretty-printed JSON--with-sourcesprints sources trailer without requiring-v-vverbose behavior unchanged (backward compat)--quietemits tokens only; no trailers afterPlus regression checks (
--version,docs quickstart,docs --list) all pass.Full TDD: RED (8/8 failed on unmodified
main) → GREEN (8/8 pass after this change) → REFACTOR (0 ruff line-length / unused-import violations).Checklist
dataclasses.replacepattern forsearch, ruff-clean)rag-python query "..."unchanged)queryepilogargparse,json)Closes # — (no matching issue; this is a UX/toolability improvement)