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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @langchain/langgraph
```

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
Expand Down
21 changes: 13 additions & 8 deletions examples/src/tools/google_calendar.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import { OpenAI } from "@langchain/openai";
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";

export async function run() {
const model = new OpenAI({
const model = new ChatOpenAI({
temperature: 0,
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4o-mini",
});

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

const calendarAgent = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
const calendarAgent = createReactAgent({
llm: model,
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 calendarAgent.invoke({
messages: [{ role: "user", content: 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 calendarAgent.invoke({
messages: [{ role: "user", content: viewInput }],
});
// View Result {
// output: "You have no meetings this week between 8am and 8pm."
// }
Expand Down
6 changes: 3 additions & 3 deletions libs/langchain-community/src/tools/google_calendar/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { google } from "googleapis";
import { Tool } from "@langchain/core/tools";
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import { BaseLLM } from "@langchain/core/language_models/llms";
import { BaseChatModel } from "@langchain/core/language_models/chat_models";

export interface GoogleCalendarAgentParams {
credentials?: {
Expand All @@ -10,7 +10,7 @@ export interface GoogleCalendarAgentParams {
calendarId?: string;
};
scopes?: string[];
model?: BaseLLM;
model?: BaseChatModel;
}

export class GoogleCalendarBase extends Tool {
Expand All @@ -27,7 +27,7 @@ export class GoogleCalendarBase extends Tool {

protected scopes: string[];

protected llm: BaseLLM;
protected llm: BaseChatModel;

constructor(
fields: GoogleCalendarAgentParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { google, calendar_v3 } from "googleapis";
import type { JWT, GaxiosResponse } from "googleapis-common";
import { PromptTemplate } from "@langchain/core/prompts";
import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager";
import { BaseLLM } from "@langchain/core/language_models/llms";
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { CREATE_EVENT_PROMPT } from "../prompts/index.js";
import { getTimezoneOffsetInHours } from "../utils/get-timezone-offset-in-hours.js";
Expand Down Expand Up @@ -61,7 +61,7 @@ const createEvent = async (
type RunCreateEventParams = {
calendarId: string;
auth: JWT;
model: BaseLLM;
model: BaseChatModel;
};

const runCreateEvent = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { calendar_v3 } from "googleapis";
import type { JWT } from "googleapis-common";
import { PromptTemplate } from "@langchain/core/prompts";
import { BaseLLM } from "@langchain/core/language_models/llms";
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager";
import { StringOutputParser } from "@langchain/core/output_parsers";

Expand All @@ -11,7 +11,7 @@ import { getTimezoneOffsetInHours } from "../utils/get-timezone-offset-in-hours.
type RunViewEventParams = {
calendarId: string;
auth: JWT;
model: BaseLLM;
model: BaseChatModel;
};

const runViewEvents = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest, expect, describe } from "@jest/globals";
import { LLM } from "@langchain/core/language_models/llms";
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
import {
GoogleCalendarCreateTool,
GoogleCalendarViewTool,
Expand All @@ -25,13 +25,13 @@ jest.mock("@langchain/core/utils/env", () => ({
// runViewEvents: jest.fn(),
// }));

class FakeLLM extends LLM {
class FakeLLM extends BaseChatModel {
_llmType() {
return "fake";
}

async _call(prompt: string): Promise<string> {
return prompt;
async _generate() {
return {} as any;
}
}

Expand Down