import { StateGraph, END } from '@langchain/langgraph';
import { serveAgent } from '@reminix/langgraph';
// Define your state
interface AgentState {
messages: string[];
nextStep: string;
}
// Define nodes
async function processNode(state: AgentState) {
return { nextStep: 'respond' };
}
async function respondNode(state: AgentState) {
return { messages: [...state.messages, 'Response'] };
}
// Create graph
const graph = new StateGraph<AgentState>({
channels: {
messages: { value: (a, b) => [...a, ...b] },
nextStep: { value: (_, b) => b }
}
});
graph.addNode('process', processNode);
graph.addNode('respond', respondNode);
graph.addEdge('process', 'respond');
graph.addEdge('respond', END);
graph.setEntryPoint('process');
const workflow = graph.compile();
// Wrap and serve
serveAgent(workflow, { name: 'workflow-agent', port: 8080 });