Skip to content

feat(tool): conditional description for read file#603

Merged
stdrc merged 2 commits into
mainfrom
rc/conditional-read-file
Jan 12, 2026
Merged

feat(tool): conditional description for read file#603
stdrc merged 2 commits into
mainfrom
rc/conditional-read-file

Conversation

@stdrc

@stdrc stdrc commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Generate ReadFile tool description dynamically based on model capabilities:

  • Model supports image + video: show both image and video instructions
  • Model supports image only: show image instructions, note that video is not supported
  • Model supports video only: show video instructions, note that image is not supported
  • Model supports neither: note that media files are not supported

Changes:

  • Add load_desc_jinja function to render tool description with Jinja2
  • Update ReadFile tool to get llm capabilities from Runtime
  • Update read.md template with Jinja2 conditionals
  • Add unit tests for the new functionality

stdrc added 2 commits January 12, 2026 14:37
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Copilot AI review requested due to automatic review settings January 12, 2026 07:05

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

This PR adds dynamic, model capability-aware descriptions for the ReadFile tool. The tool's description now adjusts based on whether the LLM model supports image input, video input, both, or neither, providing more accurate guidance to the model about what file types it can process.

Changes:

  • Added Jinja2 templating support for tool descriptions via new load_desc_jinja utility function
  • Modified ReadFile tool to accept Runtime parameter and generate descriptions based on model capabilities
  • Updated test fixtures and expectations to reflect the new behavior

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyproject.toml Added Jinja2 3.1.4 as a new dependency
uv.lock Updated lock file to include Jinja2 3.1.4 (downgraded from 3.1.6)
src/kimi_cli/tools/utils.py Added load_desc_jinja function for Jinja2-based template rendering
src/kimi_cli/tools/file/read.py Updated ReadFile to use Runtime parameter and dynamically generate descriptions
src/kimi_cli/tools/file/read.md Converted template to use Jinja2 syntax with conditional blocks for capabilities
tests/test_read_file_desc.py New test file covering all four capability combinations
tests/test_tool_descriptions.py Updated expected description for default capability case
tests/test_default_agent.py Updated expected description for default agent case
tests/conftest.py Updated fixtures to use Runtime and ALL_MODEL_CAPABILITIES
docs/*/changelog.md Added changelog entries for the feature
CHANGELOG.md Added changelog entry for the feature
Makefile Updated prompt file paths (unrelated change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

super().__init__()
self._work_dir = builtin_args.KIMI_WORK_DIR
def __init__(self, runtime: Runtime) -> None:
capabilities = runtime.llm.capabilities if runtime.llm else set[str]()

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

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

The expression set[str]() is incorrect syntax. This should be set() to create an empty set. The current code set[str]() attempts to call a generic type as a function, which will raise a TypeError at runtime when runtime.llm is None. To fix this, change it to just set() since the type will be inferred from the conditional expression, or use set[ModelCapability]() if you want to be explicit (though you'll need to import ModelCapability from kimi_cli.llm).

Suggested change
capabilities = runtime.llm.capabilities if runtime.llm else set[str]()
capabilities = runtime.llm.capabilities if runtime.llm else set()

Copilot uses AI. Check for mistakes.
Comment thread Makefile
Comment on lines +113 to +116
@uv run kimi -c "$$(cat .kimi/prompts/gen-changelog.md)" --yolo
gen-docs: ## Generate user docs with Kimi CLI.
@echo "==> Generating user docs"
@uv run kimi -c "$$(cat ./docs/prompts/gen-docs.txt)" --yolo
@uv run kimi -c "$$(cat .kimi/prompts/gen-docs.md)" --yolo

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

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

These Makefile changes (updating prompt file paths from ./docs/prompts/ to .kimi/prompts/ and changing file extensions from .txt to .md) appear to be unrelated to the PR's stated purpose of adding conditional ReadFile descriptions. These changes should either be explained in the PR description or moved to a separate commit/PR for better change tracking.

Copilot uses AI. Check for mistakes.
@stdrc
stdrc merged commit c50ecb7 into main Jan 12, 2026
38 checks passed
@stdrc
stdrc deleted the rc/conditional-read-file branch January 12, 2026 07:17
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