Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename search => ripgrep #916

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codegen-examples/examples/deep_code_research/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from codegen.extensions.langchain.tools import (
ListDirectoryTool,
RevealSymbolTool,
SearchTool,
RipGrepTool,
SemanticSearchTool,
ViewFileTool,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ def research(repo_name: Optional[str] = None, query: Optional[str] = None, threa
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
SemanticSearchTool(codebase),
RevealSymbolTool(codebase),
]
Expand Down
2 changes: 1 addition & 1 deletion codegen-examples/examples/langchain_agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The agent comes with several built-in tools for code operations:

- `ViewFileTool`: View file contents and metadata
- `ListDirectoryTool`: List directory contents
- `SearchTool`: Search code using regex
- `SearchTool`: Search code using ripgrep
- `EditFileTool`: Edit file contents
- `CreateFileTool`: Create new files
- `DeleteFileTool`: Delete files
Expand Down
14 changes: 6 additions & 8 deletions codegen-examples/examples/langchain_agent/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Demo implementation of an agent with Codegen tools."""

from codegen import Codebase
from codegen.extensions.langchain.graph import create_react_agent
from codegen.extensions.langchain.llm import LLM
from codegen.extensions.langchain.prompts import REASONER_SYSTEM_MESSAGE
from codegen.extensions.langchain.tools import (
CommitTool,
CreateFileTool,
Expand All @@ -10,18 +13,13 @@
MoveSymbolTool,
RenameFileTool,
RevealSymbolTool,
SearchTool,
RipGrepTool,
SemanticEditTool,
ViewFileTool,
)

from codegen.extensions.langchain.llm import LLM
from codegen.extensions.langchain.prompts import REASONER_SYSTEM_MESSAGE

from langchain_core.messages import SystemMessage
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph.graph import CompiledGraph
from codegen.extensions.langchain.graph import create_react_agent
from langchain_core.messages import SystemMessage


def create_codebase_agent(
Expand Down Expand Up @@ -57,7 +55,7 @@ def create_codebase_agent(
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
EditFileTool(codebase),
CreateFileTool(codebase),
DeleteFileTool(codebase),
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/cli/commands/agent/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
MoveSymbolTool,
RenameFileTool,
RevealSymbolTool,
SearchTool,
RipGrepTool,
ViewFileTool,
)
from codegen.sdk.core.codebase import Codebase
Expand Down Expand Up @@ -62,7 +62,7 @@ def say(message: str):
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
CreateFileTool(codebase),
DeleteFileTool(codebase),
RenameFileTool(codebase),
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/extensions/langchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
EditFileTool,
ListDirectoryTool,
RevealSymbolTool,
SearchTool,
RipGrepTool,
SemanticEditTool,
ViewFileTool,
)
Expand All @@ -24,7 +24,7 @@
"EditFileTool",
"ListDirectoryTool",
"RevealSymbolTool",
"SearchTool",
"RipGrepTool",
"SemanticEditTool",
"ViewFileTool",
# Helper functions
Expand All @@ -44,7 +44,7 @@ def get_workspace_tools(codebase: Codebase) -> list[BaseTool]:
return [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
EditFileTool(codebase),
CreateFileTool(codebase),
DeleteFileTool(codebase),
Expand Down
8 changes: 4 additions & 4 deletions src/codegen/extensions/langchain/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
RenameFileTool,
ReplacementEditTool,
RevealSymbolTool,
RipGrepTool,
SearchFilesByNameTool,
SearchTool,
# SemanticEditTool,
ViewFileTool,
)
Expand Down Expand Up @@ -67,7 +67,7 @@ def create_codebase_agent(
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
# EditFileTool(codebase),
CreateFileTool(codebase),
DeleteFileTool(codebase),
Expand Down Expand Up @@ -131,7 +131,7 @@ def create_chat_agent(
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
CreateFileTool(codebase),
DeleteFileTool(codebase),
RenameFileTool(codebase),
Expand Down Expand Up @@ -177,7 +177,7 @@ def create_codebase_inspector_agent(
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
RipGrepTool(codebase),
DeleteFileTool(codebase),
RevealSymbolTool(codebase),
]
Expand Down
11 changes: 5 additions & 6 deletions src/codegen/extensions/langchain/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,19 @@ class SearchInput(BaseModel):

query: str = Field(
...,
description="""The search query to find in the codebase. When ripgrep is available, this will be passed as a ripgrep pattern. For regex searches, set use_regex=True.
Ripgrep is the preferred method.""",
description="""ripgrep query (or regex pattern) to run. For regex searches, set use_regex=True. Ripgrep is the preferred method.""",
)
file_extensions: list[str] | None = Field(default=None, description="Optional list of file extensions to search (e.g. ['.py', '.ts'])")
page: int = Field(default=1, description="Page number to return (1-based, default: 1)")
files_per_page: int = Field(default=10, description="Number of files to return per page (default: 10)")
use_regex: bool = Field(default=False, description="Whether to treat query as a regex pattern (default: False)")


class SearchTool(BaseTool):
"""Tool for searching the codebase."""
class RipGrepTool(BaseTool):
"""Tool for searching the codebase via RipGrep."""

name: ClassVar[str] = "search"
description: ClassVar[str] = "Search the codebase using text search or regex pattern matching"
description: ClassVar[str] = "Search the codebase using `ripgrep` or regex pattern matching"
args_schema: ClassVar[type[BaseModel]] = SearchInput
codebase: Codebase = Field(exclude=True)

Expand Down Expand Up @@ -853,7 +852,7 @@ def get_workspace_tools(codebase: Codebase) -> list["BaseTool"]:
RevealSymbolTool(codebase),
GlobalReplacementEditTool(codebase),
RunBashCommandTool(), # Note: This tool doesn't need the codebase
SearchTool(codebase),
RipGrepTool(codebase),
SearchFilesByNameTool(codebase),
# SemanticEditTool(codebase),
# SemanticSearchTool(codebase),
Expand Down
Loading