feat(tool): conditional description for read file#603
Conversation
Signed-off-by: Richard Chien <stdrc@outlook.com>
There was a problem hiding this comment.
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_jinjautility 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]() |
There was a problem hiding this comment.
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).
| capabilities = runtime.llm.capabilities if runtime.llm else set[str]() | |
| capabilities = runtime.llm.capabilities if runtime.llm else set() |
| @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 |
There was a problem hiding this comment.
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.
Generate ReadFile tool description dynamically based on model capabilities:
Changes:
load_desc_jinjafunction to render tool description with Jinja2ReadFiletool to get llm capabilities fromRuntimeread.mdtemplate with Jinja2 conditionals