feat: Open Code agent
This commit is contained in:
18
agent/open-code/index.ts
Normal file
18
agent/open-code/index.ts
Normal 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])
|
||||
5
agent/open-code/nodes/executor.ts
Normal file
5
agent/open-code/nodes/executor.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { OpenCodeState, OpenCodeUpdate } from "../types";
|
||||
|
||||
export async function executor(state: OpenCodeState): Promise<OpenCodeUpdate> {
|
||||
throw new Error("Not implemented" + state);
|
||||
}
|
||||
5
agent/open-code/nodes/interrupt.ts
Normal file
5
agent/open-code/nodes/interrupt.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { OpenCodeState, OpenCodeUpdate } from "../types";
|
||||
|
||||
export async function interrupt(state: OpenCodeState): Promise<OpenCodeUpdate> {
|
||||
throw new Error("Not implemented" + state);
|
||||
}
|
||||
25
agent/open-code/nodes/planner.ts
Normal file
25
agent/open-code/nodes/planner.ts
Normal 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
11
agent/open-code/types.ts
Normal 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;
|
||||
Reference in New Issue
Block a user