Skip to main content
Glama

pfc_execute_code

Execute Python code in the running PFC simulation to inspect and modify state in real time. Use it as a live REPL during tasks without pre-scripted prints.

Instructions

Execute Python code synchronously in the running PFC process.

Returns stdout and an optional result variable immediately. Code runs in PFC's main thread, sharing the same main namespace as any running task — side effects persist and are immediately visible to the task on its next cycle.

This tool remains responsive EVEN WHILE a simulation task is running (submitted via pfc_execute_task), as long as the task is actively cycling — execute_code interleaves at cycle gaps. Use it as a live REPL to inspect simulation state in real time — no need to pre-script print statements, and parameter sweeps or sentinel-based control don't have to be baked into the task script up front.

Environment: PFC's embedded Python interpreter. The version is bundled with PFC (PFC 6/7 → Python 3.6, PFC 9 → 3.10); the PFC version is encoded in sys.executable (e.g. PFC700, PFC900). When unsure, write code compatible with Python 3.6+.

Typical uses:

  • Query model state: ball/wall/contact counts, current cycle

  • Issue PFC commands and read their console output: itasca.command('ball list'), itasca.command('model list information'). Table dumps, list output, and command summaries are captured and interleaved with Python prints in execution order — no need to re-implement queries via the SDK just to see what a command would print

  • Live inspection during a running task: check forces, energy, coordination number, contact statistics

  • Live tuning during a running task: modify parameters, swap callbacks, or set sentinel variables that the task reads each cycle (e.g. change a servo target, adjust damping, signal early termination)

  • Create and export plots: itasca.command('plot ...')

  • Development and REPL-style testing

Do NOT invoke program call '<file>.p3dat' (or .p2dat / .dat) through this tool. PFC's command-script interpreter blocks the bridge for the script's entire duration with no cycle-gap interleaving, so any long model cycle inside the file leaves the bridge unreachable until PFC is stopped manually. If the user asks to run a .dat / .p3dat / .p2dat file, read the file and translate its commands into a sequence of itasca.command(...) calls in Python instead.

This is a synchronous tool: the request blocks until the code finishes or hits the timeout (default 10s, max 600s). Output is returned in full; the call is NOT tracked by pfc_list_tasks and cannot be interrupted mid-execution. For cancellable, pollable, or background work, submit it via pfc_execute_task instead — and you can still call pfc_execute_code against the task while it cycles.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython code to execute in PFC user console
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?

With no annotations, the description fully discloses behavioral traits: side effects persist, shares namespace, interleaves with running tasks at cycle gaps, synchronous with timeout, not tracked by pfc_list_tasks, and cannot be interrupted. It also mentions environment version and that it remains responsive during tasks.

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 detailed yet well-structured. It starts with a clear definition, then explains behavior, typical uses grouped by bullet points, and a warning. Each sentence earns its place; no fluff. Could be slightly more concise, but clarity is prioritized.

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 complexity of executing arbitrary code in PFC, the description is comprehensive: covers environment version, side effects, interaction with running tasks, anti-patterns, and differentiation from sibling tools. The presence of an output schema means return details need not be in description, but it still mentions stdout and result. No gaps remain.

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

Parameters4/5

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

Input schema has 2 parameters with 100% coverage, but descriptions in schema are minimal ('Python code to execute', 'Console execution timeout in seconds'). The tool description adds significant value: explains code runs in main thread, shares namespace, interleaving behavior, environment version tips, and typical use cases. Also clarifies timeout default and max. This exceeds the baseline of 3.

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 it executes Python code synchronously in the running PFC process, specifying the verb 'execute', resource 'Python code', and context 'PFC process'. It distinguishes from siblings like pfc_execute_task (for background tasks) and pfc_query_command (for query outputs).

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?

Explicitly provides when-to-use scenarios (live REPL, inspecting state, issuing commands, live tuning during tasks) and when-not-to-use (do not invoke 'program call' files, as they block the bridge). Also contrasts with pfc_execute_task for cancellable/pollable work.

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/pfc-mcp'

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