Skip to main content
The @langchain/openai package provides LangChain-compatible wrappers for OpenAI’s built-in tools. These tools can be bound to ChatOpenAI using bindTools() or createAgent.

Web search tool

The web search tool allows OpenAI models to search the web for up-to-date information before generating a response. Web search supports three main types:
  1. Non-reasoning web search: Quick lookups where the model passes queries directly to the search tool
  2. Agentic search with reasoning models: The model actively manages the search process, analyzing results and deciding whether to keep searching
  3. Deep research: Extended investigations using models like o3-deep-research or gpt-5 with high reasoning effort
Domain filtering - Limit search results to specific domains (up to 100):
User location - Refine search results based on geography:
Cache-only mode - Disable live internet access:
For more information, see OpenAI’s Web Search Documentation.

MCP tool (Model context protocol)

The MCP tool allows OpenAI models to connect to remote MCP servers and OpenAI-maintained service connectors, giving models access to external tools and services. There are two ways to use MCP tools:
  1. Remote MCP servers: Connect to any public MCP server via URL
  2. Connectors: Use OpenAI-maintained wrappers for popular services like Google Workspace or Dropbox
Remote MCP server - Connect to any MCP-compatible server:
Service connectors - Use OpenAI-maintained connectors for popular services:
For more information, see OpenAI’s MCP Documentation.

Code interpreter tool

The Code Interpreter tool allows models to write and run Python code in a sandboxed environment to solve complex problems. Use Code Interpreter for:
  • Data analysis: Processing files with diverse data and formatting
  • File generation: Creating files with data and images of graphs
  • Iterative coding: Writing and running code iteratively to solve problems
  • Visual intelligence: Cropping, zooming, rotating, and transforming images
Memory configuration - Choose from 1GB (default), 4GB, 16GB, or 64GB:
With files - Make uploaded files available to the code:
Explicit container - Use a pre-created container ID:
Note: Containers expire after 20 minutes of inactivity. While called “Code Interpreter”, the model knows it as the “python tool” - for explicit prompting, ask for “the python tool” in your prompts.
For more information, see OpenAI’s Code Interpreter Documentation.

File search tool

The File Search tool allows models to search your files for relevant information using semantic and keyword search. It enables retrieval from a knowledge base of previously uploaded files stored in vector stores. Prerequisites: Before using File Search, you must:
  1. Upload files to the File API with purpose: "assistants"
  2. Create a vector store
  3. Add files to the vector store
Filter operators: eq (equals), ne (not equal), gt (greater than), gte (greater than or equal), lt (less than), lte (less than or equal). For more information, see OpenAI’s File Search Documentation.

Image generation tool

The Image Generation tool allows models to generate or edit images using text prompts and optional image inputs. It leverages the GPT Image model and automatically optimizes text inputs for improved performance. Use Image Generation for:
  • Creating images from text: Generate images from detailed text descriptions
  • Editing existing images: Modify images based on text instructions
  • Multi-turn image editing: Iteratively refine images across conversation turns
  • Various output formats: Support for PNG, JPEG, and WebP formats
Custom size and quality - Configure output dimensions and quality:
Output format and compression - Choose format and compression level:
Transparent background - Generate images with transparency:
Streaming with partial images - Get visual feedback during generation:
Force image generation - Ensure the model uses the image generation tool:
Multi-turn editing - Refine images across conversation turns:
Prompting tips: Use terms like “draw” or “edit” for best results. For combining images, say “edit the first image by adding this element” instead of “combine” or “merge”.
Supported models: gpt-4o, gpt-4o-mini, gpt-5.5, gpt-5.4-mini, gpt-5.4-nano, o3 For more information, see OpenAI’s Image Generation Documentation.

Computer use tool

The Computer Use tool allows models to control computer interfaces by simulating mouse clicks, keyboard input, scrolling, and more. It uses OpenAI’s Computer-Using Agent (CUA) model to understand screenshots and suggest actions.
Beta: Computer use is in beta. Use in sandboxed environments only and do not use for high-stakes or authenticated tasks. Always implement human-in-the-loop for important decisions.
How it works: The tool operates in a continuous loop:
  1. Model sends computer actions (click, type, scroll, etc.)
  2. Your code executes these actions in a controlled environment
  3. You capture a screenshot of the result
  4. Send the screenshot back to the model
  5. Repeat until the task is complete
For more information, see OpenAI’s Computer Use Documentation.

Local shell tool

The Local Shell tool allows models to run shell commands locally on a machine you provide. Commands are executed inside your own runtime—the API only returns the instructions.
Security Warning: Running arbitrary shell commands can be dangerous. Always sandbox execution or add strict allow/deny-lists before forwarding commands to the system shell. Note: This tool is designed to work with Codex CLI and the codex-mini-latest model.
Action properties: The model returns actions with these properties:
  • command - Array of argv tokens to execute
  • env - Environment variables to set
  • working_directory - Directory to run the command in
  • timeout_ms - Suggested timeout (enforce your own limits)
  • user - Optional user to run the command as
For more information, see OpenAI’s Local Shell Documentation.

Shell tool

The Shell tool allows models to run shell commands through your integration. Unlike Local Shell, this tool supports executing multiple commands concurrently and is designed for gpt-5.1.
Security Warning: Running arbitrary shell commands can be dangerous. Always sandbox execution or add strict allow/deny-lists before forwarding commands to the system shell.
Use cases:
  • Automating filesystem or process diagnostics – e.g., “find the largest PDF under ~/Documents”
  • Extending model capabilities – Using built-in UNIX utilities, Python runtime, and other CLIs
  • Running multi-step build and test flows – Chaining commands like pip install and pytest
  • Complex agentic coding workflows – Using with apply_patch for file operations
Action properties: The model returns actions with these properties:
  • commands - Array of shell commands to execute (can run concurrently)
  • timeout_ms - Optional timeout in milliseconds (enforce your own limits)
  • max_output_length - Optional maximum characters to return per command
Return format: Your execute function should return a ShellResult:
Note: Only available through the Responses API with gpt-5.1. The timeout_ms from the model is only a hint—always enforce your own limits.
For more information, see OpenAI’s Shell Documentation.

Apply patch tool

The Apply Patch tool allows models to propose structured diffs that your integration applies. This enables iterative, multi-step code editing workflows where the model can create, update, and delete files in your codebase. When to use:
  • Multi-file refactors – Rename symbols, extract helpers, or reorganize modules
  • Bug fixes – Have the model both diagnose issues and emit precise patches
  • Tests & docs generation – Create new test files, fixtures, and documentation
  • Migrations & mechanical edits – Apply repetitive, structured updates
Security Warning: Applying patches can modify files in your codebase. Always validate paths, implement backups, and consider sandboxing. Note: This tool is designed to work with gpt-5.1 model.
Operation types: The model returns operations with these properties:
  • create_file – Create a new file at path with content from diff
  • update_file – Modify an existing file at path using V4A diff format in diff
  • delete_file – Remove a file at path
Best practices:
  • Path validation: Prevent directory traversal and restrict edits to allowed directories
  • Backups: Consider backing up files before applying patches
  • Error handling: Return descriptive error messages so the model can recover
  • Atomicity: Decide whether you want “all-or-nothing” semantics (rollback if any patch fails)
For more information, see OpenAI’s Apply Patch Documentation.