Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12', '3.13']
python-version: ['3.12']
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 2 additions & 0 deletions agentic-framework/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies = [
"langchain-core>=1.1.3",
"typer>=0.12.0",
"rich>=13.0.0",
"tree-sitter==0.21.3",
"tree-sitter-languages>=1.10.2",
]

[project.scripts]
Expand Down
84 changes: 67 additions & 17 deletions agentic-framework/src/agentic_framework/core/developer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from agentic_framework.registry import AgentRegistry
from agentic_framework.tools import (
CodeSearcher,
FileEditorTool,
FileFinderTool,
FileFragmentReaderTool,
FileOutlinerTool,
Expand All @@ -24,23 +25,66 @@ class DeveloperAgent(LangGraphMCPAgent):
@property
def system_prompt(self) -> str:
return """You are a Principal Software Engineer assistant.
Your goal is to help the user understand and maintain their codebase.
You have access to several specialized tools for:
1. Discovering the project structure and finding files by name (`find_files`).
2. Extracting class and function outlines from code files (`get_file_outline`).
Supports: Python, JavaScript, TypeScript, Rust, Go, Java, C/C++, PHP.
3. Reading specific fragments of a file (`read_file_fragment`).
4. Searching the codebase for patterns using ripgrep (`code_search`).

When you need to find a specific file by name, use `find_files`.
When asked about the project structure, start with `discover_structure`.
When asked to explain a file, start with `get_file_outline` to get an overview.
Use `read_file_fragment` to read specific lines if you need more detail.
Use `code_search` for fast global pattern matching.

Always provide clear, concise explanations and suggest improvements when relevant.
You also have access to MCP tools like `webfetch` if you need to fetch information from the web.
"""
Your goal is to help the user understand and maintain their codebase.

## AVAILABLE TOOLS

1. **find_files** - Fast file search by name using fd
2. **discover_structure** - Directory tree exploration
3. **get_file_outline** - Extract class/function signatures (Python, JS, TS, Rust, Go, Java, C/C++, PHP)
4. **read_file_fragment** - Read specific line ranges (format: 'path:start:end')
5. **code_search** - Fast pattern search via ripgrep
6. **edit_file** - Edit files with line-based or text-based operations
7. **webfetch** (MCP) - Fetch web content

## MANDATORY FILE EDITING WORKFLOW

Before using edit_file, you MUST follow this sequence:

### Step 1: READ FIRST (Required)
- Use `read_file_fragment` to see the EXACT lines you plan to modify
- NEVER guess line numbers - always verify them first
- Example: read_file_fragment("example.py:88:95")

### Step 2: COPY EXACTLY
When providing replacement content:
- Copy the EXACT text including all quotes, indentation, and punctuation
- Do NOT truncate, paraphrase, or summarize
- Preserve docstring delimiters (\"\"\" or \'\'\')
- Maintain exact indentation (tabs vs spaces)

### Step 3: APPLY EDIT
Use edit_file with the appropriate format:

Line-based operations:
- replace:path:start:end:content
- insert:path:after_line:content
- delete:path:start:end

Text-based operation (RECOMMENDED - no line numbers needed):
{"op": "search_replace", "path": "file.py", "old": "exact text to find", "new": "replacement text"}

### Step 4: VERIFY
After editing:
- Check the result message for SYNTAX WARNING
- If warning appears, read the affected lines and fix immediately
- Do not exceed 3 retry attempts

### Error Recovery
If edit_file returns an error:
1. READ the file first using read_file_fragment
2. Understand what went wrong from the error message
3. Apply a corrected edit

## GENERAL GUIDELINES

- When finding files by name, use `find_files`
- When exploring project structure, use `discover_structure`
- When explaining a file, start with `get_file_outline`
- Use `code_search` for fast global pattern matching

Always provide clear, concise explanations and suggest improvements when relevant.
"""

def local_tools(self) -> Sequence[Any]:
# Initialize tool instances with project root
Expand All @@ -49,6 +93,7 @@ def local_tools(self) -> Sequence[Any]:
explorer = StructureExplorerTool(str(BASE_DIR))
outliner = FileOutlinerTool(str(BASE_DIR))
reader = FileFragmentReaderTool(str(BASE_DIR))
editor = FileEditorTool(str(BASE_DIR))

return [
StructuredTool.from_function(
Expand Down Expand Up @@ -76,4 +121,9 @@ def local_tools(self) -> Sequence[Any]:
name=reader.name,
description=reader.description,
),
StructuredTool.from_function(
func=editor.invoke,
name=editor.name,
description=editor.description,
),
]
6 changes: 6 additions & 0 deletions agentic-framework/src/agentic_framework/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .code_searcher import CodeSearcher
from .codebase_explorer import (
FileEditorTool,
FileFinderTool,
FileFragmentReaderTool,
FileOutlinerTool,
StructureExplorerTool,
)
from .example import CalculatorTool, WeatherTool
from .syntax_validator import SyntaxValidator, ValidationResult, get_validator
from .web_search import WebSearchTool

__all__ = [
Expand All @@ -17,4 +19,8 @@
"FileOutlinerTool",
"FileFragmentReaderTool",
"FileFinderTool",
"FileEditorTool",
"SyntaxValidator",
"ValidationResult",
"get_validator",
]
Loading