KeyError: 'code' in code_execution_tool when 'code' arg missing #69

Open
opened 2026-09-04 15:16:02 +00:00 by mara · 0 comments
Collaborator

Summary

code_execution_tool.execute() raises KeyError: 'code' when the LLM emits a tool call without a code argument (e.g. a bare runtime call such as an accidental empty wait/probe call). The traceback:

File "/a0/plugins/_code_execution/tools/code_execution_tool.py", line 76, in execute
    cfg, command=self.args["code"], session=session, reset=reset
                 ~~~~~~~~~^^^^^^^^
KeyError: 'code'

Analysis

  • Lines 68, 72 and 76 use direct self.args["code"] access for python/nodejs/terminal runtimes instead of self.args.get("code", "").
  • Other args (runtime, session, reset, allow_running) already use .get() with defaults, so this is the one inconsistent path.
  • A malformed or degenerate tool call from the model crashes the monologue loop instead of returning a repairable tool error.

Suggested fix

Replace the three direct accesses with self.args.get("code", "") and, if code is empty for runtimes that require it, return the existing fw.code.runtime_wrong.md-style error prompt (or a dedicated "missing code argument" prompt) instead of raising.

Observed environment

  • agent.py line 1203 _execute_tool_request → tool.execute(**tool_args)
  • Affected runtimes: python, terminal, nodejs (same pattern at lines 68/72/76).
## Summary `code_execution_tool.execute()` raises `KeyError: 'code'` when the LLM emits a tool call without a `code` argument (e.g. a bare `runtime` call such as an accidental empty `wait`/probe call). The traceback: ``` File "/a0/plugins/_code_execution/tools/code_execution_tool.py", line 76, in execute cfg, command=self.args["code"], session=session, reset=reset ~~~~~~~~~^^^^^^^^ KeyError: 'code' ``` ## Analysis - Lines 68, 72 and 76 use direct `self.args["code"]` access for python/nodejs/terminal runtimes instead of `self.args.get("code", "")`. - Other args (`runtime`, `session`, `reset`, `allow_running`) already use `.get()` with defaults, so this is the one inconsistent path. - A malformed or degenerate tool call from the model crashes the monologue loop instead of returning a repairable tool error. ## Suggested fix Replace the three direct accesses with `self.args.get("code", "")` and, if `code` is empty for runtimes that require it, return the existing `fw.code.runtime_wrong.md`-style error prompt (or a dedicated "missing code argument" prompt) instead of raising. ## Observed environment - agent.py line 1203 `_execute_tool_request` → `tool.execute(**tool_args)` - Affected runtimes: `python`, `terminal`, `nodejs` (same pattern at lines 68/72/76).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/a0-symbolics#69
No description provided.