Skip to content

Commit e8d343a

Browse files
authored
add js to overview (#160)
1 parent c8bd992 commit e8d343a

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/oss/overview.mdx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ Trusted by companies shaping the future of agents – including Klarna, Replit,
66

77
Install LangGraph:
88

9-
```
9+
:::python
10+
```python
1011
pip install -U langgraph
1112
```
13+
:::
14+
15+
:::js
16+
```js
17+
npm install @langchain/langgraph @langchain/core
18+
```
19+
:::
1220

1321
Then, create an agent [using prebuilt components](/oss/prebuilts):
1422

23+
:::python
1524
```python
1625
# pip install -qU "langchain[anthropic]" to call the model
1726

@@ -32,6 +41,45 @@ agent.invoke(
3241
{"messages": [{"role": "user", "content": "what is the weather in sf"}]}
3342
)
3443
```
44+
:::
45+
46+
:::js
47+
```js
48+
// npm install @langchain/anthropic to call the model
49+
50+
import { createReactAgent } from "@langchain/langgraph/prebuilt";
51+
import { initChatModel } from "langchain/chat_models/universal";
52+
import { tool } from "@langchain/core/tools";
53+
import { z } from "zod";
54+
55+
const getWeather = tool(
56+
async (input: { city: string }) => {
57+
return `It's always sunny in ${input.city}!`;
58+
},
59+
{
60+
name: "getWeather",
61+
schema: z.object({
62+
city: z.string().describe("The city to get the weather for"),
63+
}),
64+
description: "Get weather for a given city.",
65+
}
66+
);
67+
68+
const llm = await initChatModel("anthropic:claude-3-7-sonnet-latest");
69+
const agent = createReactAgent({
70+
llm,
71+
tools: [getWeather],
72+
prompt: "You are a helpful assistant",
73+
});
74+
75+
// Run the agent
76+
await agent.invoke({
77+
messages: [{ role: "user", content: "what is the weather in sf" }],
78+
});
79+
80+
```
81+
:::
82+
3583

3684
For more information, see the [Quickstart](/oss/quickstart). Or, to learn how to build an [agent workflow](/oss/graph-api) with a customizable architecture, long-term memory, and other complex task handling, see the [LangGraph basics tutorials](/oss/1-build-basic-chatbot).
3785

0 commit comments

Comments
 (0)