Runtime Behavior of Dynamic Code Generation Skills

This chapter explains the descriptor-driven execution path of the subsystem and clarifies how text responses and temporary code execution are selected at runtime.

Dynamic Decision Executor

The subsystem uses a single executor for this family. At runtime, it builds a decision prompt from the descriptor guidance and from the current input, then asks the LLM for a JSON object that selects either text mode or code mode. If the result is text mode, the returned text becomes the skill output. If the result is code mode, the returned code snippet is executed immediately.

The temporary code execution path is intentionally ephemeral. The subsystem wraps the generated snippet in an async function and executes it through eval. If the snippet returns undefined, the runtime performs one fallback attempt by detecting the last declared function name and calling it automatically. If the result remains undefined, execution fails with an explicit error asking for a final return value.

Important

In the default path, generated code is not written to disk. It is executed for the current request only and then discarded.

Input and Result Semantics

The operative input field for this subsystem is always input. If the caller supplies options.args.input, the subsystem uses that string. Otherwise it falls back to the user prompt text. An empty input is rejected before either executor runs.

The result semantics are stable. String results are returned as they are. Null or undefined values become an empty string. Other values are serialized to JSON when possible and converted to string otherwise. The subsystem also attempts to append the user input and produced output to session memory when such memory is available.

The runtime follows one descriptor-driven decision flow that either returns text directly or executes a temporary LLM-produced snippet.