Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agents

Xinze Li, Yuhang Zang, Yixin Cao, Aixin SunarXiv 2026

TL;DR

Skill-as-Pseudocode (SaP) automatically refactors free-form markdown skill libraries into structured, typed pseudocode paired with concrete action templates. By replacing ambiguous prose with precise code-like contracts, SaP breaks the costly "confused $\rightarrow$ re-retrieve" loop in LLM agents, boosting task success rates while significantly lowering token consumption and LLM calls.

What Problem Does This Paper Address?

Modern LLM agents rely heavily on skill libraries—repositories of pre-authored procedural documents that guide them through complex tasks. Today, these libraries are typically written in free-form Markdown prose.

While human-readable, prose is a massive bottleneck for language models. A standard markdown skill document interleaves what a skill accomplishes (its output schema) with how it should be executed (the exact environment syntax), often burying crucial details under hints, caveats, and examples.

When an agent retrieves a prose-heavy skill, it must re-derive the input schema and exact invocation syntax on the fly. This frequently triggers a frustrating feedback loop: the agent emits a slightly incorrect action (e.g., writing put X in Y instead of move X to Y), the environment responds with a generic "Nothing happens.", and the agent re-retrieves the exact same prose document hoping to find its mistake. This loop drives up both task failure rates and API costs.

Methods

The authors introduce Skill-as-Pseudocode (SaP), an automated pipeline that converts messy markdown documentation into a structured, verified pseudocode specification.

Figure 1: SaP as verified refactoring. Repeated prose spans in parent skills (A) feed a numbered, checked pipeline (B): form a candidate cluster c, draft a child contract κ, verify it, bind concrete arguments and clean residual conflicts, then emit an agent-facing pseudocode skill. The resulting representation (C) separates what the skill does (typed signature), what local arguments this parent supplies (grounded invoke), and how the environment is actually called (concrete action template).

The SaP pipeline operates in five main stages:

  1. Parser: Splits the original markdown skills into distinct procedural units based on headings.
  2. Candidate Proposer: Clusters similar procedural units across different documents using semantic embeddings and shallow syntactic parsing (verbs and objects).
  3. Contract Extractor: Uses an LLM (gpt-4o-mini) to synthesize a unified, typed contract ($\kappa$) in strict JSON format, detailing the trigger, input/output schemas, and pre/postconditions.
  4. Deterministic Verifier: To prevent LLM hallucinations from corrupting the library, the contract must pass four rule-based checks: Coverage (token recall), Binding (input parameter alignment), Replacement (structural coherence), and Risk (scanning for unsafe operations like rm -rf).
  5. Refactor & Post-Verification: Rewrites the original parent documents to replace the messy prose sections with invoke(κ, args) placeholders. Two additional LLM passes—Binding Extraction (BE) and Rewrite Cleanup (RC)—ensure that local arguments are correctly bound and any conflicting residual prose is cleaned up.

At task time, instead of raw prose, the agent receives a substituted skill bundle that cleanly separates the execution syntax from the high-level contract.

Figure 2: Retrieval-time substitution (§3.5). For each retrieved parent, SaP replaces an invoke placeholder with the content the agent needs to act: concrete action templates with bindings, the rewritten parent skeleton, and the inlined child contract.

Datasets

The approach was evaluated using the following resources:

  • skills_500: A public skillset containing 500 markdown skill documents spanning roughly 10 domains, including text-game automation, API wrappers, and software engineering tasks.
  • ALFWorld: The primary evaluation benchmark, specifically the unseen split consisting of 134 text-based interactive household games (e.g., heating, cooling, and placing objects).
  • SkillsBench: A 10-task subset of Docker-based coding challenges used to verify the generality of the approach beyond text games.

Key Insights and Ideas

  • Prose is the Core Bottleneck: The primary issue with current agent libraries isn't a lack of modular organization, but the prose representation itself. Forcing an LLM to parse natural language instructions at runtime introduces unnecessary ambiguity.
  • The "What" and "How" Must Co-Exist: A crucial finding from the paper's ablation studies is that providing only a typed contract actually hurts performance compared to raw prose. Agents need a dual signal: a typed signature explaining what the skill does, paired immediately with a concrete template showing how to invoke it in the environment's exact tokens.
  • Deterministic Gates Ensure Portability: By relying on a strict, rule-based verifier rather than a soft LLM classifier, the pipeline can safely use different model families (like DeepSeek or GPT). Model discrepancies are safely absorbed as rejections rather than corrupted code contracts.

Key Results

SaP was tested against the Graph-of-Skills (GoS) baseline on 134 ALFWorld games across three seeds (402 total paired games).

  • Higher Success Rates: SaP achieved 82 paired wins compared to only 47 for the GoS baseline—a 74% relative improvement in reward. As shown below, SaP consistently outperformed the baseline across every single task category.
Figure 3: Per-task-type win rate on ALFWorld 134- game (seed = 42; numerical breakdown in Appendix Q). SaP beats GOS on every task type, with the largest gains on the multi-step heat/cool/place categories.
  • Significant Resource Savings: Concurrently, SaP reduced input tokens by 22.8%, output tokens by 17.3%, and total LLM calls per game by 14.5%.
  • Generality Check: On the SkillsBench coding tasks, SaP maintained a +1 win advantage over GoS while slashing input token overhead by 43%.

Limitations and Future Work

  • Static vs. Runtime Binding: Currently, argument bindings are resolved statically at index-time. If a skill requires arguments that only exist as dynamic, episode-specific runtime states (e.g., a specific object ID generated during the game), the static binding can become stale. The authors note that developing a runtime expansion tool (sap_invoke) is a vital next step.
  • Scope Constraints: The empirical evaluation focused entirely on English markdown libraries within one core skillset (skills_500). While SaP includes architectural designs to support structured API formats like OpenAPI and Anthropic's Model Context Protocol (MCP), these cross-modality capabilities have not yet been experimentally verified.

Summary updated

BibTeX
@misc{li2026skill,
  author = {Xinze Li and Yuhang Zang and Yixin Cao and Aixin Sun},
  title = {{Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agents}},
  year = {2026},
  eprint = {2605.27955},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.27955},
}
Figure