UT

universal-tool-calling-protocol/code-mode

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

1626 stars 114 forks 质量 86 趋势 35MPL-2.0

🔌 即插即用库,使代理通过代码执行调用 MCP 和 UTCP 工具。

概览

🤖 代码模式库:首个通过代码执行实现工具调用的库 只需三行,就能将你的AI代理从笨拙的工具调用者转变为高效的代码执行者。 大型语言模型擅长写代码,但在工具调用方面却很吃力。与其直接暴露数百个工具,不如给它们一个能执行TypeScript代码并访问整个工具包的工具。 苹果、Cloudflare和Anthropic都表示,Code-Mode比传统的导出函数信息和提取JSON调用工具调用更高效。 独立的Python基准测试研究验证了性能声明,每天有1000个场景: - 单代码块替代多个API调用 - LLM在代码生成与工具编排方面表现出色- 操作间无上下文重处理 ](https://www.youtube.com/watch?v=zsMjkPzmqhA) 仅此而已。你的AI代理现在可以在单一请求中执行复杂工作流程,而不是数十个请求。

概述(AI 翻译)

–>

🤖 代码模式库:首个通过代码执行实现工具调用的库

只需三行,就能将你的AI代理从笨拙的工具调用者转变为高效的代码执行者。

为什么这改变了一切

大型语言模型擅长写代码,但在工具调用方面却很吃力。与其直接暴露数百个工具,不如给它们一个能执行TypeScript代码并访问整个工具包的工具。

苹果、Cloudflare和Anthropic都表示,Code-Mode比传统的导出函数信息和提取JSON调用工具调用更高效。

基准测试

独立的Python基准研究验证了性能声明,在每天1000个场景下,每年节省9536美元的成本:

场景复杂度 传统 代码模式 改进
简单(2-3个工具) 3次迭代 1次执行 速度提升67%
中等(4-7个工具) 8次迭代 1次执行 速度提升75%
复杂(8+工具) 16次迭代 1次执行 速度提升88%

为什么代码模式主导一切:

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Transform your AI agents from clunky tool callers into efficient code executors — in just 3 lines.

Why This Changes Everything

LLMs excel at writing code but struggle with tool calls. Instead of exposing hundreds of tools directly, give them ONE tool that executes TypeScript code with access to your entire toolkit.

Apple, Cloudflare, and Anthropic say that Code-Mode is a more efficient way to approach tool calling compared to the traditional dump function information and then extract a JSON for function calling.

Benchmarks

Independent Python benchmark study validates the performance claims with $9,536/year cost savings at 1,000 scenarios/day:

Scenario Complexity Traditional Code Mode Improvement
Simple (2-3 tools) 3 iterations 1 execution 67% faster
Medium (4-7 tools) 8 iterations 1 execution 75% faster
Complex (8+ tools) 16 iterations 1 execution 88% faster

Why Code Mode Dominates:

Batching Advantage - Single code block replaces multiple API calls
Cognitive Efficiency - LLMs excel at code generation vs. tool orchestration
Computational Efficiency - No context re-processing between operations

Getting Started

Get Started in 3 Lines

import { CodeModeUtcpClient } from '@utcp/code-mode';

const client = await CodeModeUtcpClient.create();                    // 1. Initialize
await client.registerManual({ name: 'github', /* MCP config */ });  // 2. Add tools
在 GitHub 查看完整 README

安装

npx @utcp/code-mode-mcp
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "code-mode": { "command": "npx", "args": ["@utcp/code-mode-mcp"], "env": { "UTCP_CONFIG_FILE": "/path/to/your/.utcp_config.json" } } } }