Skip to content

Programmatic Tool Calling with any LLM Fresh

Published: December 1, 2025 | Original Post


Agents can write and execute code that dynamically invokes tools, working with any LLM model.

Key Capabilities

The run_code_with_tools feature allows agents to invoke:

  • MCP tools (external MCP servers)
  • Custom tools (user-defined implementations)
  • Built-in tools (memory, filesystem, utilities)

Agents can write Python scripts that call these tools dynamically, rather than selecting from predefined tool sequences.

Technical Implementation

The feature operates at Letta's harness layer, making it model-agnostic. Tools execute server-side, eliminating client-side configuration requirements. The system scopes stateful tools to the calling agent through environment variables, including a special LETTA_AGENT_ID variable.

Benefits

  • Workflow Automation -- Agents define map-reduce and chained tool patterns themselves
  • Context Efficiency -- The agent can post-process output data to avoid polluting the LLM context
  • Cost Reduction -- Parallel tool calling within a single script reduces LLM invocations and token usage

Getting Started

Attach run_code_with_tools to Letta agents via the platform. Note that this remains an experimental feature requiring additional prompting for optimal effectiveness.