feat: Open Code agent

This commit is contained in:
bracesproul
2025-03-06 20:04:55 -08:00
parent c8e985ca69
commit 38710f3cb0
5 changed files with 64 additions and 0 deletions

18
agent/open-code/index.ts Normal file
View File

@@ -0,0 +1,18 @@
import { END, START, StateGraph } from "@langchain/langgraph";
import { OpenCodeAnnotation, OpenCodeState } from "./types";
import { planner } from "./nodes/planner";
import { interrupt } from "./nodes/interrupt";
import { executor } from "./nodes/executor";
function handleRoutingFromExecutor(state: OpenCodeState): "executor" | "interrupt" {}
function handleRoutingFromInterrupt(state: OpenCodeState): "executor" | typeof END {}
const workflow = new StateGraph(OpenCodeAnnotation)
.addNode("planner", planner)
.addNode("executor", executor)
.addNode("interrupt", interrupt)
.addEdge(START, "planner")
.addEdge("planner", "executor")
.addConditionalEdges("executor", handleRoutingFromExecutor, ["executor", "interrupt"])
.addConditionalEdges("interrupt", handleRoutingFromInterrupt, ["executor", END])

View File

@@ -0,0 +1,5 @@
import { OpenCodeState, OpenCodeUpdate } from "../types";
export async function executor(state: OpenCodeState): Promise<OpenCodeUpdate> {
throw new Error("Not implemented" + state);
}

View File

@@ -0,0 +1,5 @@
import { OpenCodeState, OpenCodeUpdate } from "../types";
export async function interrupt(state: OpenCodeState): Promise<OpenCodeUpdate> {
throw new Error("Not implemented" + state);
}

View File

@@ -0,0 +1,25 @@
import { v4 as uuidv4 } from "uuid";
import { AIMessage } from "@langchain/langgraph-sdk";
import { OpenCodeState, OpenCodeUpdate } from "../types";
export async function planner(state: OpenCodeState): Promise<OpenCodeUpdate> {
const aiMessage: AIMessage = {
type: "ai",
id: uuidv4(),
content: "",
tool_calls: [
{
name: "update_file",
args: {
args: {
new_file_content: "ADD_CODE_HERE"
},
},
id: uuidv4(),
type: "tool_call",
}
]
}
const toolMessage = {}
}

11
agent/open-code/types.ts Normal file
View File

@@ -0,0 +1,11 @@
import { Annotation } from "@langchain/langgraph";
import { GenerativeUIAnnotation } from "../types";
export const OpenCodeAnnotation = Annotation.Root({
messages: GenerativeUIAnnotation.spec.messages,
ui: GenerativeUIAnnotation.spec.ui,
timestamp: GenerativeUIAnnotation.spec.timestamp,
});
export type OpenCodeState = typeof OpenCodeAnnotation.State;
export type OpenCodeUpdate = typeof OpenCodeAnnotation.Update;