generated from langchain-ai/langgraphjs-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update comments and documentation #1
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Copy this over: | ||
# cp .env.example .env | ||
# Then modify to suit your needs | ||
ANTHROPIC_API_KEY=... | ||
# Then modify to suit your needs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"node_version": "20", | ||
"graphs": { | ||
"agent": "./src/agent.ts:graph" | ||
"agent": "./src/agent/index.ts:graph" | ||
}, | ||
"env": ".env" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,59 @@ | ||
import { BaseMessage } from "@langchain/core/messages"; | ||
import { BaseMessage, BaseMessageLike } from "@langchain/core/messages"; | ||
import { Annotation, messagesStateReducer } from "@langchain/langgraph"; | ||
|
||
/** | ||
* A graph's StateAnnotation defines three main thing: | ||
* A graph's StateAnnotation defines three main things: | ||
* 1. The structure of the data to be passed between nodes (which "channels" to read from/write to and their types) | ||
* 2. Default values each field | ||
* 3. Rducers for the state's. Reducers are functions that determine how to apply updates to the state. | ||
* 2. Default values for each field | ||
* 3. Reducers for the state's. Reducers are functions that determine how to apply updates to the state. | ||
* See [Reducers](https://langchain-ai.github.io/langgraphjs/concepts/low_level/#reducers) for more information. | ||
*/ | ||
|
||
// This is the primary state of your agent, where you can store any information | ||
export const StateAnnotation = Annotation.Root({ | ||
/** | ||
* Messages track the primary execution state of the agent. | ||
|
||
Typically accumulates a pattern of: | ||
|
||
1. HumanMessage - user input | ||
2. AIMessage with .tool_calls - agent picking tool(s) to use to collect | ||
information | ||
3. ToolMessage(s) - the responses (or errors) from the executed tools | ||
|
||
(... repeat steps 2 and 3 as needed ...) | ||
4. AIMessage without .tool_calls - agent responding in unstructured | ||
format to the user. | ||
|
||
5. HumanMessage - user responds with the next conversational turn. | ||
|
||
(... repeat steps 2-5 as needed ... ) | ||
|
||
Merges two lists of messages, updating existing messages by ID. | ||
|
||
By default, this ensures the state is "append-only", unless the | ||
new message has the same ID as an existing message. | ||
|
||
Returns: | ||
A new list of messages with the messages from \`right\` merged into \`left\`. | ||
If a message in \`right\` has the same ID as a message in \`left\`, the | ||
message from \`right\` will replace the message from \`left\`.` | ||
* | ||
* Typically accumulates a pattern of: | ||
* | ||
* 1. HumanMessage - user input | ||
* 2. AIMessage with .tool_calls - agent picking tool(s) to use to collect | ||
* information | ||
* 3. ToolMessage(s) - the responses (or errors) from the executed tools | ||
* | ||
* (... repeat steps 2 and 3 as needed ...) | ||
* 4. AIMessage without .tool_calls - agent responding in unstructured | ||
* format to the user. | ||
* | ||
* 5. HumanMessage - user responds with the next conversational turn. | ||
* | ||
* (... repeat steps 2-5 as needed ... ) | ||
* | ||
* Merges two lists of messages or message-like objects with role and content, | ||
* updating existing messages by ID. | ||
* | ||
* Message-like objects are automatically coerced by `messagesStateReducer` into | ||
* LangChain message classes. If a message does not have a given id, | ||
* LangGraph will automatically assign one. | ||
* | ||
* By default, this ensures the state is "append-only", unless the | ||
* new message has the same ID as an existing message. | ||
* | ||
* Returns: | ||
* A new list of messages with the messages from \`right\` merged into \`left\`. | ||
* If a message in \`right\` has the same ID as a message in \`left\`, the | ||
* message from \`right\` will replace the message from \`left\`.` | ||
*/ | ||
messages: Annotation<BaseMessage[]>({ | ||
messages: Annotation<BaseMessage[], BaseMessageLike[]>({ | ||
reducer: messagesStateReducer, | ||
default: () => [], | ||
}), | ||
// Feel free to add additional attributes to your state as needed. | ||
// Common examples include retrieved documents, extracted entities, API connections, etc. | ||
/** | ||
* Feel free to add additional attributes to your state as needed. | ||
* Common examples include retrieved documents, extracted entities, API connections, etc. | ||
* | ||
* For simple fields whose value should be overwritten by the return value of a node, | ||
* you don't need to define a reducer or default. | ||
*/ | ||
// additionalField: Annotation<string>, | ||
}); | ||
|
||
export type State = typeof StateAnnotation.State; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { describe, it, expect } from "@jest/globals"; | ||
import { _route } from "../src/agent/graph.js"; | ||
import { route } from "../src/agent/graph.js"; | ||
describe("Routers", () => { | ||
it("Test route", async () => { | ||
const res = _route({ messages: [] }); | ||
const res = route({ messages: [] }); | ||
expect(res).toEqual("callModel"); | ||
}, 100_000); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should just delete index and import from graph directly?