mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-05 10:42:10 +00:00
feat: Set max num of times reviewer can run (#418)
* feat: Set max num of times reviewer can run * cr
This commit is contained in:
parent
01f0698e02
commit
73e7ba5295
5 changed files with 57 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { END, Send, START, StateGraph } from "@langchain/langgraph";
|
import { Command, END, Send, START, StateGraph } from "@langchain/langgraph";
|
||||||
import {
|
import {
|
||||||
GraphAnnotation,
|
GraphAnnotation,
|
||||||
|
GraphConfig,
|
||||||
GraphConfiguration,
|
GraphConfiguration,
|
||||||
GraphState,
|
GraphState,
|
||||||
} from "@open-swe/shared/open-swe/types";
|
} from "@open-swe/shared/open-swe/types";
|
||||||
|
|
@ -39,12 +40,12 @@ function lastMessagesMissingToolCalls(
|
||||||
* Otherwise, it ends the process.
|
* Otherwise, it ends the process.
|
||||||
*
|
*
|
||||||
* @param {GraphState} state - The current graph state.
|
* @param {GraphState} state - The current graph state.
|
||||||
* @returns {"reviewer-subgraph" | "take-action" | "request-help" | "generate-action" | Send} The next node to execute, or END if the process should stop.
|
* @returns {"route-to-review-or-conclusion" | "take-action" | "request-help" | "generate-action" | Send} The next node to execute, or END if the process should stop.
|
||||||
*/
|
*/
|
||||||
function routeGeneratedAction(
|
function routeGeneratedAction(
|
||||||
state: GraphState,
|
state: GraphState,
|
||||||
):
|
):
|
||||||
| "reviewer-subgraph"
|
| "route-to-review-or-conclusion"
|
||||||
| "take-action"
|
| "take-action"
|
||||||
| "request-help"
|
| "request-help"
|
||||||
| "generate-action"
|
| "generate-action"
|
||||||
|
|
@ -82,7 +83,7 @@ function routeGeneratedAction(
|
||||||
}
|
}
|
||||||
|
|
||||||
// No tool calls, route to reviewer subgraph
|
// No tool calls, route to reviewer subgraph
|
||||||
return "reviewer-subgraph";
|
return "route-to-review-or-conclusion";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,6 +102,22 @@ function routeGenerateActionsOrEnd(
|
||||||
return "generate-action";
|
return "generate-action";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function routeToReviewOrConclusion(
|
||||||
|
state: GraphState,
|
||||||
|
config: GraphConfig,
|
||||||
|
): Command {
|
||||||
|
const maxAllowedReviews = config.configurable?.maxReviewCount ?? 3;
|
||||||
|
if (state.reviewsCount >= maxAllowedReviews) {
|
||||||
|
return new Command({
|
||||||
|
goto: "generate-conclusion",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Command({
|
||||||
|
goto: "reviewer-subgraph",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const workflow = new StateGraph(GraphAnnotation, GraphConfiguration)
|
const workflow = new StateGraph(GraphAnnotation, GraphConfiguration)
|
||||||
.addNode("initialize", initializeSandbox)
|
.addNode("initialize", initializeSandbox)
|
||||||
.addNode("generate-action", generateAction)
|
.addNode("generate-action", generateAction)
|
||||||
|
|
@ -109,12 +126,19 @@ const workflow = new StateGraph(GraphAnnotation, GraphConfiguration)
|
||||||
})
|
})
|
||||||
.addNode("update-plan", updatePlan)
|
.addNode("update-plan", updatePlan)
|
||||||
.addNode("progress-plan-step", progressPlanStep, {
|
.addNode("progress-plan-step", progressPlanStep, {
|
||||||
ends: ["summarize-history", "generate-action", "reviewer-subgraph"],
|
ends: [
|
||||||
|
"summarize-history",
|
||||||
|
"generate-action",
|
||||||
|
"route-to-review-or-conclusion",
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.addNode("generate-conclusion", generateConclusion)
|
.addNode("generate-conclusion", generateConclusion)
|
||||||
.addNode("request-help", requestHelp, {
|
.addNode("request-help", requestHelp, {
|
||||||
ends: ["generate-action", END],
|
ends: ["generate-action", END],
|
||||||
})
|
})
|
||||||
|
.addNode("route-to-review-or-conclusion", routeToReviewOrConclusion, {
|
||||||
|
ends: ["generate-conclusion", "route-to-review-or-conclusion"],
|
||||||
|
})
|
||||||
.addNode("reviewer-subgraph", reviewerGraph)
|
.addNode("reviewer-subgraph", reviewerGraph)
|
||||||
.addNode("open-pr", openPullRequest)
|
.addNode("open-pr", openPullRequest)
|
||||||
.addNode("diagnose-error", diagnoseError)
|
.addNode("diagnose-error", diagnoseError)
|
||||||
|
|
@ -124,7 +148,7 @@ const workflow = new StateGraph(GraphAnnotation, GraphConfiguration)
|
||||||
.addConditionalEdges("generate-action", routeGeneratedAction, [
|
.addConditionalEdges("generate-action", routeGeneratedAction, [
|
||||||
"take-action",
|
"take-action",
|
||||||
"request-help",
|
"request-help",
|
||||||
"reviewer-subgraph",
|
"route-to-review-or-conclusion",
|
||||||
"update-plan",
|
"update-plan",
|
||||||
"generate-action",
|
"generate-action",
|
||||||
])
|
])
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ Once you've determined the status of the current task, call either the \`mark_ta
|
||||||
taskPlan: updatedPlanTasks,
|
taskPlan: updatedPlanTasks,
|
||||||
};
|
};
|
||||||
return new Command({
|
return new Command({
|
||||||
goto: "reviewer-subgraph",
|
goto: "route-to-review-or-conclusion",
|
||||||
update: commandUpdate,
|
update: commandUpdate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,5 +157,6 @@ export async function finalReview(
|
||||||
taskPlan: updatedTaskPlan,
|
taskPlan: updatedTaskPlan,
|
||||||
messages: messagesUpdate,
|
messages: messagesUpdate,
|
||||||
internalMessages: messagesUpdate,
|
internalMessages: messagesUpdate,
|
||||||
|
reviewsCount: (state.reviewsCount || 0) + 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,16 @@ export const ReviewerGraphStateObj = MessagesZodState.extend({
|
||||||
fn: (_state, update) => update,
|
fn: (_state, update) => update,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
/**
|
||||||
|
* The number of times the reviewer subgraph has been executed.
|
||||||
|
*/
|
||||||
|
reviewsCount: withLangGraph(z.custom<number>(), {
|
||||||
|
reducer: {
|
||||||
|
schema: z.custom<number>(),
|
||||||
|
fn: (_state, update) => update,
|
||||||
|
},
|
||||||
|
default: () => 0,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ReviewerGraphState = z.infer<typeof ReviewerGraphStateObj>;
|
export type ReviewerGraphState = z.infer<typeof ReviewerGraphStateObj>;
|
||||||
|
|
|
||||||
|
|
@ -241,14 +241,14 @@ export const GraphAnnotation = MessagesZodState.extend({
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
/**
|
/**
|
||||||
* The review generated by the reviewer subgraph
|
* The number of times the reviewer subgraph has been executed.
|
||||||
*/
|
*/
|
||||||
review: withLangGraph(z.custom<string>(), {
|
reviewsCount: withLangGraph(z.custom<number>(), {
|
||||||
reducer: {
|
reducer: {
|
||||||
schema: z.custom<string>(),
|
schema: z.custom<number>(),
|
||||||
fn: (_state, update) => update,
|
fn: (_state, update) => update,
|
||||||
},
|
},
|
||||||
default: () => "",
|
default: () => 0,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// ---NOT USED---
|
// ---NOT USED---
|
||||||
|
|
@ -292,6 +292,11 @@ export const GraphConfigurationMetadata: {
|
||||||
"Maximum number of review actions allowed during the review phase. An action consists of a tool call.",
|
"Maximum number of review actions allowed during the review phase. An action consists of a tool call.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
maxReviewCount: {
|
||||||
|
x_open_swe_ui_config: {
|
||||||
|
type: "hidden",
|
||||||
|
},
|
||||||
|
},
|
||||||
programmerModelName: {
|
programmerModelName: {
|
||||||
x_open_swe_ui_config: {
|
x_open_swe_ui_config: {
|
||||||
type: "select",
|
type: "select",
|
||||||
|
|
@ -514,6 +519,12 @@ export const GraphConfiguration = z.object({
|
||||||
mcpServers: withLangGraph(z.string().optional(), {
|
mcpServers: withLangGraph(z.string().optional(), {
|
||||||
metadata: GraphConfigurationMetadata.mcpServers,
|
metadata: GraphConfigurationMetadata.mcpServers,
|
||||||
}),
|
}),
|
||||||
|
/**
|
||||||
|
* The maxium number of times the reviewer subgraph can be executed.
|
||||||
|
*/
|
||||||
|
maxReviewCount: withLangGraph(z.number().optional(), {
|
||||||
|
metadata: GraphConfigurationMetadata.maxReviewCount,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type GraphConfig = LangGraphRunnableConfig<
|
export type GraphConfig = LangGraphRunnableConfig<
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue