// A node in the graph that returns an object with a "currentOutput" key // replaces the value in the state. You can get the state type as shown below: constmyNode = (state: typeofSimpleAnnotation.State) => { return { currentOutput:"some_new_value", }; }
// Define a state with a single key named "messages" that will // combine a returned BaseMessage or arrays of BaseMessages constAnnotationWithReducer = Annotation.Root({ messages:Annotation<BaseMessage[]>({ // Different types are allowed for updates reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => { if (Array.isArray(right)) { returnleft.concat(right); } returnleft.concat([right]); }, default: () => [], }), });
// A node in the graph that returns an object with a "messages" key // will update the state by combining the existing value with the returned one. constmyNode = (state: typeofAnnotationWithReducer.State) => { return { messages: [newAIMessage("Some new response")], }; };
在 StateGraph 状态中实例化通道的助手。
可以在 Annotation.Root 包装器中以两种方式之一用作字段
示例
示例