Skip to content

docs: add example on custom tools#465

Merged
stdrc merged 1 commit intomainfrom
rc/custom-tool-example
Dec 12, 2025
Merged

docs: add example on custom tools#465
stdrc merged 1 commit intomainfrom
rc/custom-tool-example

Conversation

@stdrc
Copy link
Copy Markdown
Contributor

@stdrc stdrc commented Dec 12, 2025

No description provided.

Signed-off-by: Richard Chien <stdrc@outlook.com>
Copilot AI review requested due to automatic review settings December 12, 2025 05:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 a new example demonstrating how to create custom tools for Kimi CLI. The example includes a simple Ls tool that lists files in a directory and shows how to integrate custom tools into an agent configuration file.

  • Creates a standalone example project with proper dependency management
  • Implements a custom Ls tool using the CallableTool2 interface
  • Demonstrates integration of custom tools via agent YAML configuration

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/custom-tools/pyproject.toml Defines project dependencies and configuration for the custom tools example
examples/custom-tools/myagent.yaml Agent configuration file that extends the default agent and includes the custom Ls tool
examples/custom-tools/my_tools/ls.py Implementation of a custom Ls tool that lists files in a directory
examples/custom-tools/my_tools/__init__.py Empty init file to make my_tools a Python package
examples/custom-tools/main.py Example script demonstrating how to run the agent with custom tools
examples/custom-tools/README.md Documentation explaining the purpose of the example and how to run it

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

description: str = "List files in a directory."
params: type[Params] = Params

async def __call__(self, params: Params) -> ToolReturnValue:
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The __call__ method should be decorated with @override to follow the codebase convention. All other tool implementations in the codebase use the @override decorator on the __call__ method to explicitly indicate that this method is overriding the parent class method.

Copilot uses AI. Check for mistakes.
directory: str = Field(description="The directory to list files from.", default=".")


class Ls(CallableTool2):
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The CallableTool2 class should be parameterized with the Params type, following the pattern used in all other tools in the codebase. The declaration should be class Ls(CallableTool2[Params]): instead of class Ls(CallableTool2):. This provides better type safety and consistency with the rest of the codebase.

Suggested change
class Ls(CallableTool2):
class Ls(CallableTool2[Params]):

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
from kosong.tooling import CallableTool2, ToolError, ToolOk, ToolReturnValue
from pydantic import BaseModel, Field
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Missing import for override decorator. To use the @override decorator on the __call__ method (as is standard practice in all other tools), add from typing import override to the imports.

Copilot uses AI. Check for mistakes.
@stdrc stdrc merged commit 70c95d5 into main Dec 12, 2025
13 checks passed
@stdrc stdrc deleted the rc/custom-tool-example branch December 12, 2025 05:20
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