Repository navigation
Expand file tree
/
Copy pathquickstart.ts
More file actions
82 lines (72 loc) · 2.27 KB
/
Copy pathquickstart.ts
File metadata and controls
82 lines (72 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// :snippet-start: quickstart-search-tool-js
import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z
.number()
.optional()
.default(5)
.describe("Maximum number of results to return"),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general")
.describe("Search topic category"),
includeRawContent: z
.boolean()
.optional()
.default(false)
.describe("Whether to include raw content"),
}),
},
);
// :snippet-end:
// :snippet-start: quickstart-create-agent-js
import { createDeepAgent } from "deepagents";
// System prompt to steer the agent to be an expert researcher
const researchInstructions = `You are an expert researcher. Your job is to conduct thorough research and then write a polished report.
You have access to an internet search tool as your primary means of gathering information.
## \`internet_search\`
Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
`;
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-4-6",
tools: [internetSearch],
systemPrompt: researchInstructions,
});
// :snippet-end:
// :snippet-start: quickstart-run-agent-js
const result = await agent.invoke({
messages: [{ role: "user", content: "What is langgraph?" }],
});
// Print the agent's response
console.log(result.messages[result.messages.length - 1].content);
// :snippet-end:
// :remove-start:
if (!result) throw new Error("No result returned");
// :remove-end: