feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-06-30 16:42:32 +03:00
parent 57a7f1d12b
commit 9ff9612bbb
5 changed files with 83 additions and 24 deletions
+10
View File
@@ -0,0 +1,10 @@
import { app } from './langgraph';
async function main() {
const result = await app.invoke({ input: 'Hello world' });
console.log('Final result:', result);
}
main().catch((err) => {
console.error('Error during execution:', err);
});
+41
View File
@@ -0,0 +1,41 @@
import { StateGraph } from 'langgraph';
export type State = {
input: string;
output?: string;
};
const startFn = (state: State) => {
// The start node simply passes the initial state through.
return state;
};
const reflection = (state: State) => {
console.log('Reflection node:', state);
return state;
};
const rewriting = (state: State) => {
const newState = { ...state, output: state.input.toUpperCase() };
console.log('Rewriting node:', newState);
return newState;
};
const end = (state: State) => {
console.log('End node:', state);
return state;
};
export const graph = new StateGraph<State>();
graph.addNode('start', startFn);
graph.addNode('reflection', reflection);
graph.addNode('rewriting', rewriting);
graph.addNode('end', end);
graph.setEntryPoint('start');
graph.addEdge('start', 'reflection');
graph.addEdge('reflection', 'rewriting');
graph.addEdge('rewriting', 'end');
export const app = graph.compile();