# Test Time Tool Evolution

> Enables agents to synthesize, verify, and evolve executable tools during inference rather than relying on static tool libraries, improving reasoning on heterogeneous scientific domains through dynamic tool adaptation.

- Skill: `adu2021/test-time-tool-evolution` (Agent Skill)
- Install (CLI): `npx skillmds@latest add adu2021/test-time-tool-evolution`
- Raw SKILL.md: https://api.skillmd.com/api/skills/adu2021/test-time-tool-evolution/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- License: MIT
- Author: adu2021 (https://skillmd.com/u/adu2021)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/adu2021/test-time-tool-evolution

---


## Overview

Instead of depending on pre-configured tool libraries, enable agents to dynamically create and refine computational tools at inference time. This approach transforms tools from fixed resources into problem-driven solutions that adapt to domain-specific requirements.

## When to Use

- For scientific reasoning tasks in heterogeneous domains (physics, chemistry, mathematics, biology)
- When domain-specific tools don't exist or are incomplete
- When tool requirements vary significantly based on problem specifics
- For cross-domain adaptation where tools need modification between problems

## When NOT to Use

- For domains with well-established, comprehensive tool libraries
- When tool synthesis latency is unacceptable (code generation takes time)
- For security-critical applications where tool verification is difficult
- In environments where code execution is restricted

## Key Technical Components

### Tool Synthesis Agent

Design an LLM-based agent that generates executable Python tools on-demand.

```python
# Tool synthesis from problem description
def synthesize_tool(problem_description, domain_context=""):
    """Generate Python code for solving specific problem"""
    prompt = f"""
    Create a Python function that solves this {domain_context} problem:
    {problem_description}

    Requirements:
    - Function should be self-contained
    - Include input validation
    - Return clear results
    """
    return llm_generate_code(prompt)
```

### Tool Verification Framework

Implement verification that checks tool correctness before execution.

```python
# Multi-stage tool verification
class ToolVerifier:
    def verify_tool(self, code, test_cases):
        """Verify tool safety and correctness"""
        # Stage 1: Syntax validation
        try:
            compile(code, '<string>', 'exec')
        except SyntaxError:
            return False, "Syntax error"

        # Stage 2: Test execution
        for inputs, expected_output in test_cases:
            result = execute_with_timeout(code, inputs, timeout=5)
            if result != expected_output:
                return False, f"Test failed: {inputs}"

        return True, "Verified"
```

### Tool Evolution Mechanism

Enable iterative refinement of tools based on problem-solving outcomes.

```python
# Evolutionary tool improvement
def evolve_tool(original_code, failure_analysis, problem_context):
    """Refine tool based on failure mode"""
    refinement_prompt = f"""
    The tool failed because: {failure_analysis}
    Original code:
    {original_code}

    Problem context: {problem_context}

    Improve the tool to handle this failure case.
    """
    return llm_generate_improved_code(refinement_prompt)
```

### SciEvo Benchmark Framework

Organize synthetic reasoning tasks with automatically evolved tools.

```python
# Benchmark task structure
benchmark_task = {
    "problem": "Calculate quantum mechanical properties",
    "domain": "quantum_physics",
    "evolved_tools": [
        {"code": "...", "for_subtask": "eigenvalue_calculation"},
        {"code": "...", "for_subtask": "wavefunction_analysis"}
    ],
    "expected_accuracy": 0.92
}
```

### Cross-Domain Tool Adaptation

Reuse and adapt tools across related problems in different domains.

```python
# Tool adaptation across domains
def adapt_tool_to_domain(base_tool_code, source_domain, target_domain):
    """Adapt tool from one domain to another"""
    adaptation_prompt = f"""
    Adapt this {source_domain} tool to {target_domain}:
    {base_tool_code}

    Key differences between domains:
    - Data formats
    - Computation patterns
    - Validation requirements
    """
    return llm_adapt_code(adaptation_prompt)
```

## Performance Characteristics

- SciEvo benchmark: 1,590 scientific reasoning tasks with 925 evolved tools
- Improvements over static tool baselines on both accuracy and efficiency
- Tool evolution typically takes 2-5 iterations for complex problems
- Supports diverse scientific domains: physics, chemistry, mathematics, biology

## Integration Pattern

1. Parse problem description and domain context
2. Synthesize candidate tool via LLM code generation
3. Verify tool against initial test cases
4. Execute tool on problem; capture failures
5. Evolve tool based on failure analysis
6. Repeat until tool solves problem or max iterations reached
7. Cache evolved tools for domain-similar future problems

## Safety Considerations

- Always run synthesized code in sandboxed environment
- Set strict timeouts on tool execution (5-10 seconds max)
- Validate tool outputs against expected ranges
- Log all synthesized code for auditing

## References

- Static tool libraries cannot cover heterogeneous scientific domains
- Test-time tool synthesis provides domain adaptation
- Tool evolution enables iterative problem-solving refinement

