Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 30, 2024
1 parent ef620c8 commit 781ec9b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/agent/open-canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ const cleanState = (_: typeof OpenCanvasGraphAnnotation.State) => {
};
};

/**
* Conditionally route to the "generateTitle" node if there are only
* two messages in the conversation. This node generates a concise title
* for the conversation which is displayed in the thread history.
*/
const conditionallyGenerateTitle = (
state: typeof OpenCanvasGraphAnnotation.State
) => {
if (state.messages.length > 2) {
// Do not generate if there are more than two messages (meaning it's not the first human-AI conversation)
return END;
}
return "generateTitle";
};

const builder = new StateGraph(OpenCanvasGraphAnnotation)
// Start node & edge
.addNode("generatePath", generatePath)
Expand Down Expand Up @@ -71,7 +86,10 @@ const builder = new StateGraph(OpenCanvasGraphAnnotation)
// Only reflect if an artifact was generated/updated.
.addEdge("generateFollowup", "reflect")
.addEdge("reflect", "cleanState")
.addEdge("cleanState", "generateTitle")
.addConditionalEdges("cleanState", conditionallyGenerateTitle, [
END,
"generateTitle",
])
.addEdge("generateTitle", END);

export const graph = builder.compile().withConfig({ runName: "open_canvas" });

0 comments on commit 781ec9b

Please sign in to comment.