Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 20, 2024
1 parent 292c09b commit 39c1310
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion langgraph/src/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export {
export {
MessageGraph,
messagesStateReducer,
MessagesState,
type MessagesState,
createMessagesState,
} from "./message.js";
4 changes: 3 additions & 1 deletion langgraph/src/graph/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export class MessageGraph extends StateGraph<
}
}

export const MessagesState = Annotation.Root({
export const createMessagesState = () => Annotation.Root({
messages: Annotation<BaseMessage[]>({
reducer: messagesStateReducer,
default: () => [],
}),
});

export type MessagesState = ReturnType<typeof createMessagesState>['State'];
2 changes: 1 addition & 1 deletion langgraph/src/prebuilt/react_agent_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type N = typeof START | "agent" | "tools";
export type CreateReactAgentParams = {
llm: BaseChatModel;
tools:
| ToolNode<typeof MessagesState.State>
| ToolNode<MessagesState>
| (StructuredToolInterface | RunnableToolLike)[];
messageModifier?:
| SystemMessage
Expand Down
8 changes: 4 additions & 4 deletions langgraph/src/prebuilt/tool_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ToolNodeOptions = {
};

export class ToolNode<
T extends BaseMessage[] | typeof MessagesState.State
T extends BaseMessage[] | MessagesState
> extends RunnableCallable<T, T> {
/**
A node that runs the tools requested in the last AIMessage. It can be used
Expand All @@ -41,9 +41,9 @@ export class ToolNode<
}

private async run(
input: BaseMessage[] | typeof MessagesState.State,
input: BaseMessage[] | MessagesState,
config: RunnableConfig
): Promise<BaseMessage[] | typeof MessagesState.State> {
): Promise<BaseMessage[] | MessagesState> {
const message = Array.isArray(input)
? input[input.length - 1]
: input.messages[input.messages.length - 1];
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ToolNode<
}

export function toolsCondition(
state: BaseMessage[] | typeof MessagesState.State
state: BaseMessage[] | MessagesState
): "tools" | typeof END {
const message = Array.isArray(state)
? state[state.length - 1]
Expand Down
3 changes: 2 additions & 1 deletion langgraph/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export {
MessageGraph,
messagesStateReducer,
Annotation,
MessagesState,
createMessagesState,
type MessagesState,
type StateType,
type UpdateType,
type CompiledGraph,
Expand Down

0 comments on commit 39c1310

Please sign in to comment.