Implementing programmatic tool calling on Amazon Bedrock
Summary
Programmatic Tool Calling (PTC) is a paradigm shift in how large language models (LLMs) interact with external tools, moving from sequential, one-at-a-time invocations to code-orchestrated execution. This approach involves the LLM generating Python code that runs in a sandboxed environment, handling multiple tool calls, data processing, and filtering. This dramatically reduces latency and token usage, with experimental results showing an 87-92% reduction in token consumption across models like Claude Sonnet 4.6, Qwen3-Coder-480B, and MiniMax M2.1. Accuracy also significantly improves as data processing occurs in Python rather than natural language. The article presents three implementation methods on Amazon Bedrock: a self-hosted Docker sandbox on ECS for maximum control, a managed solution using Amazon Bedrock AgentCore Code Interpreter, and an Anthropic SDK-compatible path via a proxy.
Key takeaway
For AI Engineers or ML Architects designing LLM-powered agents with complex multi-step workflows, adopting Programmatic Tool Calling (PTC) on Amazon Bedrock is crucial. You can achieve 87-92% token cost reduction and significantly improve accuracy by offloading data processing to a sandboxed Python environment. Consider the self-hosted ECS option for full control over custom packages and security, or the managed AgentCore Code Interpreter for reduced operational overhead, to optimize your agent's performance and cost efficiency.
Key insights
PTC enables LLMs to orchestrate multi-step tool interactions via generated code in a sandbox, drastically cutting tokens and boosting accuracy.
Principles
- Code-orchestrated tool execution reduces LLM context window burden.
- Sandboxed code execution enhances data privacy and processing accuracy.
- Model-agnostic PTC improves performance across diverse LLMs.
Method
LLM generates Python code for tool orchestration; code executes in an isolated sandbox; orchestrator intercepts tool calls, executes them, and injects results; only final output returns to LLM.
In practice
- Implement PTC on Amazon Bedrock via self-hosted Docker/ECS.
- Use Amazon Bedrock AgentCore Code Interpreter for managed PTC.
- Integrate Anthropic SDK with Bedrock via a translation proxy.
Topics
- Programmatic Tool Calling
- Large Language Models
- Amazon Bedrock
- Code Interpreter
- Sandbox Security
- Token Optimization
- AI Agents
Code references
Best for: AI Engineer, Machine Learning Engineer, AI Architect
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Artificial Intelligence.