// 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 包装器中的字段,通过以下两种方式之一使用:
示例
示例