No project description provided
Project description
Moatless Tools
Moatless Tools is a hobby project where I experiment with some ideas I have about how LLMs can be used to edit code in large existing codebases. I believe that rather than relying on an agent to reason its way to a solution, it is crucial to build good tools to insert the right context into the prompt and handle the response.
_Right now I'm focusing on moatless-tree-search, an extended version of moatless-tools that builds a tree structure of nodes with parallel solutions and uses tree search to find the optimal trajectory. The code in moatless-tools has been simplified and is now a streamlined version of this expanded codebase.
SWE-Bench
I use the SWE-bench benchmark as a way to verify my ideas and am currently sharing the sixth place on the SWE-Bench Lite Leaderboard.
Version 0.0.3: Claude 3.5 Sonnet v20241022
With version 0.0.3 I get 38.3% solve rate with Claude 3.5 Sonnet v20241022. Average cost per instance is $0.30.
The three main reasons I’ve been able to go from 27% to 38% solved instances in this version:
-
Claude 3.5 Sonnet and Computer Use
The solution has been adjusted to use thetext_editor_20241022
tool introduced in the new version of Claude 3.5 Sonnet. This provides more stable results when editing existing code. -
moatless-testbeds
I set up a Kubernetes-based solution to run tests and provide feedback on test results to the agent. It’s worth noting that the agent has to independently identify the tests and can’t rely on thePASS_TO_PASS
orFAIL_TO_PASS
data for each instance. -
More flexible model
In the earlier version of Moatless Tools, the agent followed a rigid flow where it first retrieved content and then edited the code. Now, it can dynamically choose between actions for code retrieval or editing, depending on the situation.
Try the Claude 3.5 Sonnet v20241022 evaluation set up on Google Colab
Version 0.0.2: Claude 3.5 Sonnet
With version 0.0.2 I get 26.7% solve rate with Claude 3.5 Sonnet, with a bit higher cost of $0.17 per instance.
Try the Claude 3.5 evaluation set up on Google Colab
Version 0.0.1: GPT-4o
Moatless Tools 0.0.1 has a solve rate of 24%, with each benchmark instance costing an average of $0.13 to solve with GPT-4o. Running the SWE Bench Lite dataset with 300 instances costs approx 40 dollars.
Try it out
I have focused on testing my ideas, and the project is currently a bit messy. My plan is to organize it in the coming period. However, feel free to clone the repo and try running this notebook:
Environment Setup
Before running the evaluation, you'll need:
- At least one LLM provider API key (e.g., OpenAI, Anthropic, etc.)
- A Voyage AI API key from voyageai.com to use the pre-embedded vector stores for SWE-Bench instances.
- (Optional) Access to a testbed environment - see moatless-testbeds for setup instructions
You can configure these settings by either:
- Create a
.env
file in the project root (copy from.env.example
):
cp .env.example .env
# Edit .env with your values
- Or export the variables directly:
# Directory for storing vector index store files
export INDEX_STORE_DIR="/tmp/index_store"
# Directory for storing clonedrepositories
export REPO_DIR="/tmp/repos"
# Required: At least one LLM provider API key
export OPENAI_API_KEY="<your-key>"
export ANTHROPIC_API_KEY="<your-key>"
# ...or Base URL for custom LLM API service (optional)
export CUSTOM_LLM_API_BASE="<your-base-url>"
export CUSTOM_LLM_API_KEY="<your-key>"
# Required: API Key for Voyage Embeddings
export VOYAGE_API_KEY="<your-key>"
# Optional: Configuration for testbed environment (https://github.com/aorwall/moatless-testbeds)
export TESTBED_API_KEY="<your-key>"
export TESTBED_BASE_URL="<your-base-url>"
Example
Basic setup using the AgenticLoop
to solve a SWE-Bench instance.
from moatless.agent import ActionAgent
from moatless.agent.code_prompts import SIMPLE_CODE_PROMPT
from moatless.benchmark.swebench import create_repository
from moatless.benchmark.utils import get_moatless_instance
from moatless.completion import CompletionModel
from moatless.file_context import FileContext
from moatless.index import CodeIndex
from moatless.loop import AgenticLoop
from moatless.actions import FindClass, FindFunction, FindCodeSnippet, SemanticSearch, RequestMoreContext, RequestCodeChange, Finish, Reject
index_store_dir = "/tmp/index_store"
repo_base_dir = "/tmp/repos"
persist_path = "trajectory.json"
instance = get_moatless_instance("django__django-16379")
completion_model = CompletionModel(model="gpt-4o", temperature=0.0)
repository = create_repository(instance)
code_index = CodeIndex.from_index_name(
instance["instance_id"], index_store_dir=index_store_dir, file_repo=repository
)
actions = [
FindClass(code_index=code_index, repository=repository),
FindFunction(code_index=code_index, repository=repository),
FindCodeSnippet(code_index=code_index, repository=repository),
SemanticSearch(code_index=code_index, repository=repository),
RequestMoreContext(repository=repository),
RequestCodeChange(repository=repository, completion_model=completion_model),
Finish(),
Reject()
]
file_context = FileContext(repo=repository)
agent = ActionAgent(actions=actions, completion=completion_model, system_prompt=SIMPLE_CODE_PROMPT)
loop = AgenticLoop.create(
message=instance["problem_statement"],
agent=agent,
file_context=file_context,
repository=repository,
persist_path=persist_path,
max_iterations=50,
max_cost=2.0 # Optional: Set maximum cost in dollars
)
final_node = loop.run()
if final_node:
print(final_node.observation.message)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file moatless-0.0.3b0.tar.gz
.
File metadata
- Download URL: moatless-0.0.3b0.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d93913a6f82f39f1d8b0497df2b1fad9857a4de48dce20d0537cf2f41b17a8 |
|
MD5 | dbfc7ba8a5112f51b0eda7da3117035b |
|
BLAKE2b-256 | 73e67abefcaa87b7652f115584f5ec18b2f84eb9ca48b9c10da18d99f3cde2ad |
File details
Details for the file moatless-0.0.3b0-py3-none-any.whl
.
File metadata
- Download URL: moatless-0.0.3b0-py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1be566603645c5977a2bbbd8f27e93c1aecc9b28243e505ab49e1f40402f63bc |
|
MD5 | a1701fa22b6d4dc3bf0e4eaaaf2d6f87 |
|
BLAKE2b-256 | 601c25c8fcfad318a89590aab47ae8b8ad42024466adb91c5e3dc32f63213b99 |