Skip to main content
Glama

evaluate_sage

Run arbitrary SageMath code in a persistent session for tasks without a dedicated tool. Variables persist across calls for multi-step computations.

Instructions

Run arbitrary SageMath code in a persistent session; variables persist across calls.

LAST RESORT. A dedicated tool exists for most tasks and should be preferred: it validates arguments and returns a typed result instead of a repr string. Reach for one of these first:

  • calculus: differentiate_expression, integrate_expression, limit_expression, series_expansion, symbolic_sum, solve_ode

  • algebra: solve_equation, simplify_expression, expand_expression, factor_expression, find_root

  • linear algebra: matrix_operation (determinant, inverse, eigenvalues, rank, rref, transpose), matrix_multiply

  • discrete: number_theory_operation, combinatorics_operation (binomial, partitions, catalan, fibonacci, bell), graph_operation, group_operation

  • specialised: elliptic_curve_operation, coding_theory_operation, polynomial_ring_operation, boolean_algebra_operation, geometry_operation, vector_calculus_operation

  • data: statistics_summary, distribution_operation

  • plots: plot_expression, plot3d_expression, plot_multi_expression

Use evaluate_sage only for what those do not cover, for example:

Transforms: var('t s'); laplace(sin(t), t, s); inverse_laplace(1/(s^2+1), s, t) Modular arithmetic: Mod(17, 5); power_mod(3, 100, 97) Recurrences: var('n'); f = function('f'); desolve_rec(f(n+2)-f(n+1)-f(n), f, [0, 1]) Continued fractions: continued_fraction(pi).convergents()[:10] Number fields: K. = NumberField(x^3 - 2); K.class_number() Multi-step work that builds on values defined earlier in the same session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesSageMath code to execute
sessionNoNamed workspace to use. Workspaces have independent variables; omit for 'default'.default
timeoutNoOverride the evaluation timeout in seconds
want_latexNoReturn LaTeX representation when possible
capture_stdoutNoCapture stdout emitted by Sage code

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
latexNoLaTeX serialization of the result when requested and supported.
resultNoString representation of the expression result if available.
stdoutNoCaptured stdout emitted during execution.
elapsed_msYesWall-clock execution time in milliseconds.
result_typeYes
Behavior4/5

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

No annotations are provided, so the description carries the burden of disclosing behavioral traits. It clearly states variables persist across calls and implies that output is a repr string (by contrasting with 'typed result'). It does not mention potential side effects of arbitrary code execution or session management options (reset/interrupt), but as an arbitrary code runner the core behavior is transparent.

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 longer than average but highly structured: it opens with the core purpose, then uses a bolded 'LAST RESORT' callout, a categorized list of alternatives, and concise examples. Every section serves a distinct purpose and the information is front-loaded. It is not bloated despite its length.

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 general-purpose code execution tool, the description covers purpose, alternatives, use cases, and persistence behavior. The existence of an output schema means return values need not be detailed in text. Missing details like timeout behavior and session reset are handled by sibling tools (interrupt_sage_session, reset_sage_session), so the description is complete enough for the tool's complexity.

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

Parameters3/5

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

Schema coverage is 100%, with each parameter (code, session, timeout, want_latex, capture_stdout) having its own description. The tool description adds context about persistent sessions and code examples, but does not deepen understanding of the parameters themselves beyond the schema. This meets the baseline of 3 for a well-covered schema.

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 a specific verb+resource: 'Run arbitrary SageMath code in a persistent session; variables persist across calls.' This clearly states the tool's function and distinguishes it from dedicated siblings like calculate_expression or differentiate_expression, which handle specific, typed operations rather than arbitrary code.

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 positions evaluate_sage as a 'LAST RESORT' and provides a comprehensive list of dedicated tools to prefer, saying 'Use evaluate_sage only for what those do not cover.' It gives concrete examples (transforms, modular arithmetic, recurrences) and notes it is for multi-step work builds on earlier values. This is exemplary when-to-use and when-not-to-use guidance.

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/XBP-Europe/sagemath-mcp'

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