Skip to main content
Glama
sdiehl
by sdiehl

substitute_expression

Perform symbolic substitution in mathematical expressions by replacing a specified variable with another expression. Returns the resulting expression key for further use.

Instructions

Substitutes a variable in an expression with another expression using SymPy's subs method.

Args:
    expr_key: The key of the expression to perform substitution on.
    var_name: The name of the variable to substitute.
    replacement_expr_key: The key of the expression to substitute in place of the variable.

Example:
    # Create variables x and y
    intro("x", [], [])
    intro("y", [], [])

    # Create expressions
    expr1 = introduce_expression("x**2 + y**2")
    expr2 = introduce_expression("sin(x)")

    # Substitute y with sin(x) in x^2 + y^2
    result = substitute_expression(expr1, "y", expr2)
    # Results in x^2 + sin^2(x)

Returns:
    A key for the resulting expression after substitution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expr_keyYes
replacement_expr_keyYes
var_nameYes
Behavior3/5

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

With no annotations provided, the description carries full burden. It explains the mathematical behavior (substitution using SymPy) and shows the transformation logic in the example. However, it doesn't disclose important behavioral traits like whether this modifies the original expression or creates a new one, error conditions, or performance characteristics.

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 well-structured with clear sections (purpose, Args, Example, Returns) and every sentence adds value. It could be slightly more concise by integrating the example more tightly, but overall it's efficiently organized with zero wasted text.

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

Completeness4/5

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

For a 3-parameter mathematical operation tool with no annotations and no output schema, the description provides good coverage: clear purpose, parameter explanations, usage example, and return value explanation. It could be more complete by describing error cases or the state management context (keys reference previously created expressions), but it's substantially adequate.

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?

With 0% schema description coverage, the description fully compensates by clearly explaining all three parameters in the Args section: 'expr_key' (key of expression to perform substitution on), 'var_name' (name of variable to substitute), and 'replacement_expr_key' (key of expression to substitute in place). The example further illustrates their usage and relationships.

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 specific action ('Substitutes a variable in an expression with another expression') and the implementation method ('using SymPy's subs method'). It distinguishes this tool from siblings like 'differentiate_expression' or 'simplify_expression' by focusing specifically on variable substitution rather than other mathematical operations.

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

Usage Guidelines4/5

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

The description provides clear context through the example showing when to use this tool (after creating variables and expressions with 'intro' and 'introduce_expression'). However, it doesn't explicitly state when NOT to use this tool or mention alternatives among the sibling tools, which prevents a perfect score.

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

Related 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/sdiehl/sympy-mcp'

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