How get_full_path Resolves Partial Paths to Absolute Paths in SWE-Agent
The get_full_path function converts partial path fragments into absolute paths by detecting if the fragment exists as a suffix within the current working directory and reconstructing the full path from the matching substring.
The langtalks/swe-agent repository provides AI-powered software engineering tools that require precise filesystem navigation. Located in agent/tools/search.py, the get_full_path utility bridges the gap between user-friendly shorthand directory names and the absolute path requirements of underlying search operations.
Internal Resolution Logic
The function implements a deterministic four-step algorithm to handle path conversion without external dependencies beyond the Python standard library.
Early Exit for Absolute Paths
The function first eliminates inputs that require no processing. In agent/tools/search.py, lines 77-79 check whether the argument is already absolute:
if os.path.isabs(partial_path):
return partial_path
If os.path.isabs(partial_path) evaluates to True, the function returns the input unchanged, avoiding unnecessary string manipulation.
Current Working Directory Analysis
For relative inputs, the function captures the process context at line 80:
cwd = os.path.abspath(os.getcwd())
It then performs a substring check to determine if partial_path appears anywhere within cwd. This detection identifies whether the user provided a fragment that represents the tail end of the absolute working directory.
Path Fragment Reconstruction
When the substring match succeeds, the function splits the absolute working directory on the fragment and reassembles the complete path. According to lines 82-85 in agent/tools/search.py:
parts = cwd.split(partial_path)
full_path = parts[0] + partial_path
The split() operation isolates the prefix preceding the fragment, and concatenating this prefix with the original fragment yields the full absolute path.
Fallback for Unmatched Fragments
If the fragment does not exist within the current working directory string, line 86 implements a pass-through fallback:
return partial_path
This delegates resolution to downstream handlers or allows the filesystem layer to raise appropriate FileNotFoundError exceptions.
Practical Usage Examples
The utility supports both direct invocation and transparent integration with higher-level search tools.
Direct Function Calls
Import and call get_full_path explicitly when preprocessing path arguments:
from agent.tools.search import get_full_path
# Already absolute paths pass through unchanged
print(get_full_path("/usr/local/bin"))
# Output: /usr/local/bin
# Fragment resolution when cwd is "/home/alice/projects/myapp"
print(get_full_path("myapp"))
# Output: /home/alice/projects/myapp
# Unmatched fragments return unchanged for downstream handling
print(get_full_path("unknown_folder"))
# Output: unknown_folder
Integration with Search Tools
The search_keyword_in_directory tool internally utilizes get_full_path to normalize user inputs:
from agent.tools.search import search_keyword_in_directory
# Automatically resolves "tools" to full absolute path
results = search_keyword_in_directory.invoke({
"directory": "agent/tools",
"search_term": "def",
"context": 1
})
This integration allows users to specify convenient shorthand paths like "tools" or "agent/tools" when those strings match the suffix of their current working directory.
Summary
get_full_pathinagent/tools/search.pyresolves partial paths by matching fragments against the absolute current working directory.- Optimization check immediately returns absolute inputs via
os.path.isabs()without further processing. - Substring matching determines if the input represents a suffix of the cwd, enabling path reconstruction through string splitting and concatenation.
- Fallback behavior returns non-matching fragments unchanged to be handled by downstream components.
- Tool ecosystem enables shorthand directory arguments in
search_keyword_in_directoryand related utilities throughout the SWE-Agent codebase.
Frequently Asked Questions
Where is the get_full_path function implemented?
The get_full_path function is defined in agent/tools/search.py at lines 77-86 within the langtalks/swe-agent repository. This module also contains search_keyword_in_directory and related tools that depend on the function for path normalization.
What happens if the partial path is not found in the current directory?
When the fragment does not appear as a substring in os.path.abspath(os.getcwd()), the function returns the original input unchanged at line 86. This allows the calling tool or the underlying filesystem operations to handle the invalid path appropriately.
Does get_full_path handle relative path indicators like dot notation?
No, the function performs literal string matching without resolving relative components such as .. or . prior to the substring check. It expects either an already-absolute path or a simple fragment that exists within the current working directory string. Path normalization should be applied before invocation if dot notation is present.
Which SWE-Agent components use this path resolution utility?
The search_keyword_in_directory tool and other filesystem-related utilities in agent/tools/search.py rely on get_full_path. Additionally, auxiliary utilities in helpers/tools.py may interact with these search functions, though they typically handle logging and output formatting rather than direct path manipulation.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →