Skip to main content
Glama

pfc_execute_code

Execute Python code in the running PFC process for real-time simulation inspection and tuning without pre-scripted queries.

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?

Discloses synchronous blocking, main thread execution, side effects persistence, interleaving with tasks, timeout limits, and non-cancellability. No annotations present, so tool carries full disclosure burden.

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 sections, front-loaded with core purpose. Slightly verbose with environment details and extensive typical uses, but information is relevant.

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?

Comprehensive given no annotations: covers behavioral traits, environment, typical uses, error conditions (timeout), and distinction from other tools. No gaps for agent decision-making.

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?

Schema covers both parameters with descriptions. Description adds context (code runs in main thread, timeout defaults/max) but schema already provides sufficient meaning. High schema coverage reduces need for extra description.

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?

Clearly states it executes Python code synchronously in PFC. Differentiates from pfc_execute_task (synchronous vs. background) and other sibling tools like pfc_query_command.

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 lists typical uses (REPL, inspection, tuning) and warnings (do not use for .dat files, prefer pfc_execute_task for cancellable work). Provides clear when-to-use and when-not-to-use.

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