Skip to main content
Glama

optimize_code

Prove code optimization: generate an improved version, verify identical outputs on test inputs, and measure speedup for measurable gains. Returns optimized code with timings.

Instructions

Optimize code and PROVE the improvement.

An LLM proposes an optimized version; the executor verifies correctness (identical stdout on test inputs) AND measures speedup (same sizes, min-of-repeats, baseline-subtracted). Accepted only if correct AND measurably faster (default 1.15x); retried once with the failure reason. Returns optimized_code, speedup_ratio, before/after timings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
sizesNo
languageYes
min_speedupNo
test_inputsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description thoroughly discloses behavioral traits: verification via identical stdout, speedup measurement methodology (same sizes, min-of-repeats, baseline-subtracted), acceptance criteria (correct AND measurably faster at default 1.15x), retry behavior (retried once with failure reason), and return values. Since no annotations are provided, this description carries the full transparency burden and handles it excellently.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense yet concise, with a strong front-loaded opening sentence and no wasted words. Every sentence delivers essential information about the process, verification, and acceptance criteria.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity and the absence of annotations, the description covers the complete workflow: proposal, verification, measurement, acceptance threshold, retry behavior, and return values. This is sufficient for an agent to select and invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 0% schema description coverage, the description compensates by referencing key parameters: 'same sizes' for `sizes`, 'default 1.15x' for `min_speedup`, and 'test inputs' for `test_inputs`. It also explains the return values, giving context to the parameters. It does not fully detail `code` and `language`, but these are self-explanatory given the tool's purpose.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Optimize code and PROVE the improvement,' which clearly states the tool's function and unique value. It distinguishes itself from sibling tools like 'benchmark' or 'translate_code' by emphasizing optimization with verification, not merely measurement or translation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when code needs to be optimized with rigorous proof of improvement, but it does not explicitly mention when to prefer this tool over alternatives such as 'benchmark' or 'analyze_complexity'. No exclusions or alternative guidance is provided beyond the purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/The-40-Thieves/codecalc'

If you have feedback or need assistance with the MCP directory API, please join our Discord server