Skip to content
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

docs: Resolves #7483, resolves #7274 #7505

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
npm install @langchain/openai @langchain/core @langchain/community
```

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
Expand Down
26 changes: 19 additions & 7 deletions examples/src/tools/google_calendar.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import { OpenAI } from "@langchain/openai";
import { AgentExecutor, createOpenAIToolsAgent } from "langchain/agents";
import { pull } from "langchain/hub";
import { OpenAI, 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 OpenAI({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ChatOpenAI with model: "gpt-4o-mini" for everything, OpenAI completions models are deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Cuz ChatOpenAI inherits BaseChatModel, not BaseLLM, I also update google_calendar type definitions.

Expand All @@ -31,22 +33,32 @@ export async function run() {
new GoogleCalendarViewTool(googleCalendarParams),
];

const calendarAgent = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
const llm = new ChatOpenAI({
temperature: 0,
apiKey: process.env.OPENAI_API_KEY,
});
const prompt: ChatPromptTemplate = await pull("hwchase17/openai-tools-agent");
const calendarAgent = await createOpenAIToolsAgent({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@ucev ucev Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. import { createReactAgent } from "@langchain/langgraph" ask users to install an extra package not mentioned in google_calendar.mdx, I use createReactAgent from @langchain/agents instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would still prefer to use it and add install instructions as it's the latest and what people should be using long term. Can make modifications myself too.

llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent: calendarAgent,
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 calendarAgent.invoke({ input: createInput });
const createResult = await agentExecutor.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 calendarAgent.invoke({ input: viewInput });
const viewResult = await agentExecutor.invoke({ input: viewInput });
// View Result {
// output: "You have no meetings this week between 8am and 8pm."
// }
Expand Down