Skip to content

Commit

Permalink
feat: use createReactAgent from @langchain/langgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ucev committed Jan 14, 2025
1 parent c165999 commit 790b5bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/tools/google_calendar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import IntegrationInstallTooltip from "@mdx_components/integration_install_toolt
<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai @langchain/core @langchain/community
npm install @langchain/openai @langchain/core @langchain/community @langchain/langgraph
```

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
Expand Down
16 changes: 4 additions & 12 deletions examples/src/tools/google_calendar.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { AgentExecutor, createReactAgent } from "langchain/agents";
import { pull } from "langchain/hub";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
import { Calculator } from "@langchain/community/tools/calculator";
import {
GoogleCalendarCreateTool,
GoogleCalendarViewTool,
} from "@langchain/community/tools/google_calendar";
import { ChatPromptTemplate } from "@langchain/core/prompts";

export async function run() {
const model = new ChatOpenAI({
Expand Down Expand Up @@ -34,28 +32,22 @@ export async function run() {
new GoogleCalendarViewTool(googleCalendarParams),
];

const prompt: ChatPromptTemplate = await pull("hwchase17/react");
const calendarAgent = await createReactAgent({
llm: model,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent: calendarAgent,
tools,
tools
});

const createInput = `Create a meeting with John Doe next Friday at 4pm - adding to the agenda of it the result of 99 + 99`;

const createResult = await agentExecutor.invoke({ input: createInput });
const createResult = calendarAgent.invoke({ input: createInput });
// Create Result {
// output: 'A meeting with John Doe on 29th September at 4pm has been created and the result of 99 + 99 has been added to the agenda.'
// }
console.log("Create Result", createResult);

const viewInput = `What meetings do I have this week?`;

const viewResult = await agentExecutor.invoke({ input: viewInput });
const viewResult = await calendarAgent.invoke({ input: viewInput });
// View Result {
// output: "You have no meetings this week between 8am and 8pm."
// }
Expand Down

0 comments on commit 790b5bc

Please sign in to comment.