Skip to content
Merged
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
22 changes: 13 additions & 9 deletions src/oss/javascript/integrations/chat/openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ If you use a model that supports custom tools, you can use the `ChatOpenAI` clas

```typescript
import { ChatOpenAI, customTool } from "@langchain/openai";
import { createAgent } from "@langchain/classic";
import { createAgent, HumanMessage } from "langchain";

const codeTool = customTool(
async (input) => {
async () => {
// ... Add code to execute the input
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The custom tool function signature has been changed to remove the input parameter, but the comment on line 299 still references using the input. Either the parameter should be restored or the comment should be updated to match the new signature.

Suggested change
// ... Add code to execute the input
// ... Add code to execute

Copilot uses AI. Check for mistakes.

return "Code executed successfully";
},
Expand All @@ -309,11 +309,13 @@ const codeTool = customTool(
const model = new ChatOpenAI({ model: "gpt-5" });

const agent = createAgent({
llm: model,
model,
tools: [codeTool],
});

const result = await agent.invoke("Use the tool to calculate 3^3");
const result = await agent.invoke({
messages: [new HumanMessage("Use the tool to execute the code")],
});
console.log(result);
```

Expand All @@ -324,7 +326,7 @@ OpenAI supports the specification of a [context-free grammar](https://platform.o

```typescript
import { ChatOpenAI, customTool } from "@langchain/openai";
import { createAgent } from "@langchain/classic";
import { createAgent, HumanMessage } from "langchain";

const MATH_GRAMMAR = `
start: expr
Expand All @@ -340,25 +342,27 @@ MUL: \"*\"
`;

const doMath = customTool(
async (input) => {
async () => {
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

Similar to the first example, this custom tool function removes the input parameter but the comment on line 346 mentions parsing and executing the input. The function signature and comment are inconsistent.

Suggested change
async () => {
async (input) => {

Copilot uses AI. Check for mistakes.

// ... Add code to parse and execute the input
return "27";
},
{
name: "do_math",
description: "Evaluate a math expression",
format: { type: "grammar", grammar: MATH_GRAMMAR },
format: { type: "grammar", definition: MATH_GRAMMAR, syntax: "lark" },
}
);

const model = new ChatOpenAI({ model: "gpt-5" });

const agent = createAgent({
llm: model,
model,
tools: [doMath],
});

const result = await agent.invoke("Use the tool to calculate 3^3");
const result = await agent.invoke({
messages: [new HumanMessage("Use the tool to calculate 3^3")],
});
console.log(result);
```

Expand Down