mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 12:43:16 +00:00
feat: add configurable maxContextActions field for planner context gathering (#52)
* Apply patch * Apply patch * formatting * fix types --------- Co-authored-by: Harrison Chase <11986836+hwchase17@users.noreply.github.com> Co-authored-by: bracesproul <braceasproul@gmail.com>
This commit is contained in:
parent
7144fbbc22
commit
c2ff18bee9
2 changed files with 26 additions and 3 deletions
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { END, START, StateGraph } from "@langchain/langgraph";
|
||||
import { PlannerGraphState, PlannerGraphStateObj } from "./types.js";
|
||||
import { GraphConfiguration } from "../../types.js";
|
||||
import { GraphConfig, GraphConfiguration } from "../../types.js";
|
||||
import {
|
||||
generateAction,
|
||||
generatePlan,
|
||||
|
|
@ -18,12 +18,15 @@ import { isAIMessage } from "@langchain/core/messages";
|
|||
|
||||
function takeActionOrGeneratePlan(
|
||||
state: PlannerGraphState,
|
||||
config: GraphConfig,
|
||||
): "take-plan-action" | "generate-plan" {
|
||||
const { plannerMessages } = state;
|
||||
const lastMessage = plannerMessages[plannerMessages.length - 1];
|
||||
// If the last message is a tool call, and we have executed less than 6 actions, take action.
|
||||
// Max actions is 13, because that's 6 actions (2 messages per action, ai & tool) plus the input message.
|
||||
const maxActionsCount = 13;
|
||||
// Max actions count is calculated as: maxContextActions * 2 + 1
|
||||
// This is because each action generates 2 messages (AI request + tool result) plus 1 initial human message
|
||||
const maxContextActions = config.configurable?.maxContextActions ?? 6;
|
||||
const maxActionsCount = maxContextActions * 2 + 1;
|
||||
if (
|
||||
isAIMessage(lastMessage) &&
|
||||
lastMessage.tool_calls?.length &&
|
||||
|
|
|
|||
|
|
@ -336,6 +336,26 @@ export const GraphConfiguration = z.object({
|
|||
description: "Controls randomness (0 = deterministic, 2 = creative)",
|
||||
},
|
||||
}),
|
||||
|
||||
/**
|
||||
* The maximum number of context gathering actions to take during planning.
|
||||
* Each action consists of 2 messages (request & result), plus 1 human message.
|
||||
* Total messages = maxContextActions * 2 + 1
|
||||
* @default 6
|
||||
*/
|
||||
maxContextActions: z
|
||||
.number()
|
||||
.optional()
|
||||
.langgraph.metadata({
|
||||
x_oap_ui_config: {
|
||||
type: "number",
|
||||
default: 6,
|
||||
min: 1,
|
||||
max: 20,
|
||||
description:
|
||||
"Maximum number of context gathering actions during planning",
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export type GraphConfig = LangGraphRunnableConfig<
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue