generated from langchain-ai/langgraphjs-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from langchain-ai/jacob/updates
Update comments and documentation
- Loading branch information
Showing
10 changed files
with
135 additions
and
295 deletions.
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/graph.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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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.