Skip to content

Conversation

@christian-bromann
Copy link
Member

This PR adds support for OpenAI's Shell tool, which allows gpt-5.1 models to execute shell commands through the Responses API. Unlike the existing localShell tool (designed for Codex CLI), this tool supports executing multiple commands concurrently and uses a different interface optimized for the newer model.

Usage

import { ChatOpenAI, tools } from "@langchain/openai";
import { exec } from "node:child_process/promises";

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

const shellTool = tools.shell({
  execute: async (action) => {
    const outputs = await Promise.all(
      action.commands.map(async (cmd) => {
        const { stdout, stderr } = await exec(cmd);
        return {
          stdout,
          stderr,
          outcome: { type: "exit" as const, exit_code: 0 },
        };
      })
    );
    return { output: outputs, maxOutputLength: action.max_output_length };
  },
});

const llmWithShell = model.bindTools([shellTool]);
const response = await llmWithShell.invoke("List all TypeScript files");

Key Differences from localShell

Feature localShell shell
Model codex-mini-latest gpt-5.1
Commands Single command (argv array) Multiple commands (string array)
Execution Sequential Concurrent support
Return format String output Structured ShellResult

@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2025

🦋 Changeset detected

Latest commit: 7940bb0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@langchain/openai Minor
@langchain/classic Patch
@langchain/community Patch
@langchain/deepseek Patch
@langchain/xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

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

Think we do this already, but with these server tool changes we should make sure that the useResponsesApi logic in ChatOpenAI works appropriately when tools like these are passed. (I expect this to work for a bunch of tools already, but I'm less confident that its up to date)

@christian-bromann christian-bromann merged commit 9ac949f into cb/openai-apply-patch-tool Dec 9, 2025
27 of 28 checks passed
@christian-bromann christian-bromann deleted the cb/openai-shell-tool branch December 9, 2025 00:23
jonghwanhyeon pushed a commit to jonghwanhyeon/langchainjs that referenced this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants