Engineering Blog

                            

Open-Source Programmatic Tool Calling: LangChain Community Brings Anthropic’s Efficient Agent Pattern to Everyone

In late 2024, Anthropic introduced a groundbreaking approach to AI agent tool calling in their engineering blog: Programmatic Tool Calling (PTC) using code execution with the Model Context Protocol (MCP). This method allows agents to write and execute code in a sandbox to orchestrate tools, dramatically reducing token usage—up to 98% savings on data-intensive tasks—by processing large results outside the model’s context window.

Now, the LangChain community has open-sourced an accessible implementation: Open PTC Agent, built on LangChain’s DeepAgents framework. This brings Anthropic’s advanced pattern to any LLM (not just Claude), making it tunable, production-ready with LangGraph/LangSmith, and equipped for complex workflows.

Why Programmatic Tool Calling Matters

Traditional agents rely on sequential JSON tool calls, which bloat context with full tool schemas and raw results (e.g., thousands of rows from a database query). PTC flips this: the agent writes Python code that imports MCP tools as functions, executes in a secure sandbox, filters/aggregates data locally, and returns only summaries or finals.

Benefits:

  • 85-98% token reduction on heavy tasks (e.g., processing stock data or large spreadsheets)
  • Better control flow: loops, conditionals, error handling in one step
  • Enhanced privacy: sensitive data stays in the sandbox
  • Progressive discovery: tools loaded on-demand via filesystem navigation

The Open-Source Implementation: Open PTC Agent

Created by community member Chen Zexi, Open PTC Agent leverages LangChain’s DeepAgents—a harness for “deep” agents with planning, filesystem access, sub-agents, and more.

Key features:

  • Universal MCP support: Auto-converts any MCP server tools to Python functions
  • Sandbox execution: Uses Daytona for isolated, secure code running
  • Multi-LLM compatibility: Works with Anthropic, OpenAI, Google, etc., via LangChain
  • Vision/multimodal: New tools for image analysis
  • Inherits DeepAgents perks: sub-agents, human-in-the-loop, persistent memory

This makes PTC deployable in production pipelines with LangGraph for stateful graphs and LangSmith for tracing.

DeepAgents by LangChain: Building Robust, Multi-Step AI Agents for ...

Real-World Impact

For data-heavy agent tasks—like analyzing large datasets, orchestrating multi-tool workflows, or handling sensitive info—PTC slashes costs and latency while boosting reliability. Community benchmarks echo Anthropic’s: massive token savings without sacrificing capability.

As MCP gains traction as the standard for agent-tool connectivity, open implementations like this democratize efficiency gains previously limited to proprietary systems.

Check out the repo on GitHub and start experimenting—it’s a step toward more scalable, cost-effective AI agents for all developers.

Follow us for more Updates

Previous Post