Skip to main content
Glama

generate_python_function

Convert verified SymPy derivation steps into executable Python functions with specified parameters, descriptions, and return values.

Instructions

    Generate a Python function from VERIFIED derivation steps.

    ═══════════════════════════════════════════════════════════════════════
    ⚠️ PREREQUISITE: All expressions must be verified with SymPy-MCP first!
    ═══════════════════════════════════════════════════════════════════════

    Correct workflow:
    1. Use SymPy-MCP to derive and verify each expression
    2. Use print_latex_expression() to show results to user
    3. User confirms the derivation is correct
    4. Call this tool with the verified expressions

    The generated code uses SymPy for computation, ensuring correctness.
    This is NOT Agent-generated code - it's assembled from verified steps.

    Args:
        name: Function name (e.g., "calculate_seatbelt_tension")
        description: Function docstring description
        parameters: List of {"name": str, "type": str, "description": str}
        steps: List of {"description": str, "expression": str, "result_var": str}
        return_vars: Variables to return

    Returns:
        Generated Python code

    Example:
        generate_python_function(
            name="calculate_tension",
            description="Calculate seatbelt tension from collision",
            parameters=[
                {"name": "M1", "type": "float", "description": "Vehicle 1 mass (kg)"},
                {"name": "M2", "type": "float", "description": "Vehicle 2 mass (kg)"},
                {"name": "v", "type": "float", "description": "Initial velocity (m/s)"},
                {"name": "m", "type": "float", "description": "Person mass (kg)"},
                {"name": "k", "type": "float", "description": "Seatbelt constant (N/m)"},
            ],
            steps=[
                {"description": "Final velocity after collision",
                 "expression": "M1 * v / (M1 + M2)",
                 "result_var": "v_f"},
                {"description": "Velocity change",
                 "expression": "v - v_f",
                 "result_var": "delta_v"},
                {"description": "Maximum tension",
                 "expression": "delta_v * sqrt(m * k)",
                 "result_var": "T_max"},
            ],
            return_vars=["v_f", "delta_v", "T_max"]
        )
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
stepsYes
parametersYes
descriptionYes
return_varsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior4/5

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

Since no annotations are provided, the description carries the full burden of behavioral disclosure. It reveals that the generated code uses SymPy for computation, is assembled from verified steps, and is not agent-generated, providing important context about its reliability. However, it does not discuss potential failure modes or behaviors when prerequisites are unmet, so it falls slightly short of full transparency.

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

Conciseness4/5

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

The description is structured effectively with headers, a warning banner, and a clear example. It is lengthy due to the necessary detail (args, workflow, example), but every section serves a purpose. The only minor issue is slight redundancy in restating the verification requirement in multiple ways.

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, the description covers prerequisites, workflow, parameters, and provides a full example. Since an output schema exists, the description need not detail return values beyond 'Generated Python code'. The description is sufficiently complete to guide correct use without ambiguity.

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

Parameters5/5

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

The input schema has no descriptions (0% coverage), but the description fully compensates with a detailed 'Args' section for all five parameters, explaining their expected structure, and provides a comprehensive example that demonstrates each parameter with concrete values. This gives the agent complete guidance for parameter construction.

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 clearly states the tool's purpose: 'Generate a Python function from VERIFIED derivation steps.' This identifies a specific verb (generate), resource (Python function), and context (verified derivation steps), which distinctly differentiates it from sibling tools like generate_latex_derivation, generate_sympy_script, and generate_derivation_report.

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

Usage Guidelines5/5

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

The description explicitly outlines the correct workflow in numbered steps, starting with a PREREQUISITE warning that expressions must be verified with SymPy-MCP first. It specifies when to use this tool (after user confirmation) and contrasts it with agent-generated code, making the usage context and alternatives clear.

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/u9401066/nsforge-mcp'

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