From 64e0e2e0d7201cda27cee7bb23d8131f55bcd6e9 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Mon, 26 May 2025 13:06:02 -0700 Subject: [PATCH] Harrison changes (#21) * cr * cr --------- Co-authored-by: Harrison Chase --- apps/open-swe/scripts/run-e2e.ts | 11 +++++------ apps/open-swe/src/nodes/generate-message.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/open-swe/scripts/run-e2e.ts b/apps/open-swe/scripts/run-e2e.ts index ea73ad6a..ad54f978 100644 --- a/apps/open-swe/scripts/run-e2e.ts +++ b/apps/open-swe/scripts/run-e2e.ts @@ -16,15 +16,14 @@ async function runE2E() { const threadId = uuidv4(); const userRequest = - "This repo contains the react/next.js code for my persona/portfolio site. It currently has static values set for the number of stars on the repositories I highlight. I want this to be accurate, but I do NOT want it to make requests to GitHub every time a user visits. Instead, please implement a solution which will run once a day, fetch the number of stars from a list of repos, then write them to vercel's KV store. Finally, update the UI to make a request to the KV store when the user visits my page and render the accurate star counts."; - + "The system message contains a REPO_DIRECTORY variable. But nothing is formatted in that variable. Please make sure to format the REPO_DIRECTORY variable in the system message. You will probably want to move the repo directory info from config to the State."; const configurable: Omit< GraphConfig["configurable"], "thread_id" | "assistant_id" > = { target_repository: { - owner: "bracesproul", - repo: "personal-site", + owner: "langchain-ai", + repo: "open-swe", }, }; @@ -67,8 +66,8 @@ async function resumeGraph(threadId: string) { "thread_id" | "assistant_id" > = { target_repository: { - owner: "bracesproul", - repo: "personal-site", + owner: "langchain-ai", + repo: "open-swe", }, }; diff --git a/apps/open-swe/src/nodes/generate-message.ts b/apps/open-swe/src/nodes/generate-message.ts index aa66df3e..a41225ac 100644 --- a/apps/open-swe/src/nodes/generate-message.ts +++ b/apps/open-swe/src/nodes/generate-message.ts @@ -1,6 +1,7 @@ import { GraphState, GraphConfig, GraphUpdate, PlanItem } from "../types.js"; import { loadModel, Task } from "../utils/load-model.js"; import { shellTool, applyPatchTool } from "../tools/index.js"; +import { getRepoAbsolutePath } from "../utils/git/index.js"; import { formatPlanPrompt } from "../utils/plan-prompt.js"; import { pauseSandbox } from "../utils/sandbox.js"; import { createLogger, LogLevel } from "../utils/logger.js"; @@ -70,10 +71,14 @@ You MUST adhere to the following criteria when executing the task: - Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them. - Always use \`rg\` instead of \`grep/ls -R\` because it is much faster and respects gitignore. - Always use glob patterns when searching with \`rg\` for specific file types. For example, to search for all TSX files, use \`rg -i star -g **/*.tsx project-directory/\`. This is because \`rg\` does not have built in file types for every language. +- Only make changes to the existing Git repo ({REPO_DIRECTORY}). Any changes outside this repo will not be detected, so do not attempt to create new files or directories outside of this repo. `; -const formatPrompt = (plan: PlanItem[]): string => { - return systemPrompt.replace("{PLAN_PROMPT}", formatPlanPrompt(plan)); +const formatPrompt = (plan: PlanItem[], config: GraphConfig): string => { + const repoDirectory = getRepoAbsolutePath(config); + return systemPrompt + .replace("{PLAN_PROMPT}", formatPlanPrompt(plan)) + .replaceAll("{REPO_DIRECTORY}", repoDirectory); }; export async function generateAction( @@ -87,7 +92,7 @@ export async function generateAction( const response = await modelWithTools.invoke([ { role: "system", - content: formatPrompt(state.plan), + content: formatPrompt(state.plan, config), }, ...state.messages, ]);