Skip to main content
Glama

yade_execute_code

Execute Python code live in the YADE simulation environment. Inspect and modify simulation state in real time without pre-scripted print statements.

Instructions

Execute Python code synchronously in the running YADE process.

Returns stdout immediately. Code runs in the YADE Python environment where yade modules are already imported; side effects persist.

This tool remains responsive EVEN WHILE a simulation task is running (submitted via yade_execute_task). Use it as a live REPL to inspect simulation state in real time — no need to pre-script print statements.

Typical uses:

  • Query simulation state: O.bodies count, current iteration

  • Create/modify bodies, engines, interactions

  • Read or set material properties

  • Live inspection during a running simulation (e.g. check stress tensor, coordination number, energy balance, or capture viewport screenshots when GUI is available)

  • Development and REPL-style testing

Unlike yade_execute_task, this tool is fire-and-return: the response contains the full output. It is NOT tracked by yade_list_tasks and cannot be interrupted or polled.

Timeout behaviour: on timeout the bridge attempts to abort the running code. The response is an error envelope (ok=false) whose error.code is one of:

  • interrupted — the code was running a simulation cycle (O.run) and was paused cleanly at an iteration boundary. For long simulations or solving to equilibrium, switch to yade_execute_task — it tracks progress and stops cleanly via yade_interrupt_task.

  • terminated — a non-cycle abort succeeded (async exception injection); the pump thread is free, but YADE state may be partially modified by the code that ran before the abort fired. Inspect state before retrying.

  • timeout — abort failed (code stuck in a C extension, or nested inside a running task's PyRunner tick); the bridge may still be blocked. Restart if unresponsive.

WARNING: For anything expected to take more than a few seconds, use yade_execute_task instead — it has proper cancellation via yade_interrupt_task and does not leave state drift on timeout. Also, do NOT write except BaseException: in your code; it defeats bridge-initiated cancellation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython code to execute in YADE process
timeoutNoConsole execution timeout in seconds

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

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

No annotations provided, so description carries full burden. Details side effects persistence, responsiveness during running simulations, timeout error codes (interrupted, terminated, timeout), and consequences of each. Also warns about state drift and unresponsiveness.

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?

Well-structured with front-loaded core purpose, bullet points for typical uses, and detailed timeout section. Every sentence adds value, though length could be slightly reduced for extreme conciseness.

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?

Covers all necessary aspects: what, when, alternatives, side effects, error handling, and warnings. Output schema exists but is not needed since tool behavior is fully described. Complete for a synchronous execution tool.

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 good descriptions. The description adds context about timeout behavior (error codes, suggestions) but does not significantly expand parameter meaning beyond what the schema already provides.

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 executes Python code synchronously in the YADE process and returns stdout immediately. It explicitly contrasts with yade_execute_task for long-running simulations, establishing a distinct purpose.

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?

Provides explicit guidance: use for quick REPL-style inspection, not for tasks > a few seconds (use yade_execute_task). Warns against catching BaseException to avoid breaking cancellation. Includes alternative tools.

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/yusong652/yade-mcp'

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