Skip to content

Inline sub-agents (## agent:) are dropped when inlined-imports: true, so the Copilot task tool reports "Unknown agent_type" #76317

Done

Description

@marekjagielski

Summary

With inlined-imports: true, inline sub-agents defined with ## agent: \name`never reach the run. The compiler strips the blocks from the markdown, and nothing writes them to.github/agents/. The tasktool then fails withUnknown agent_type: `.

Without inlined-imports, it works: the main body is loaded at runtime, the markers are still in it, and interpolate_prompt.cjs writes the agent files.

  • Seen on: gh-aw v0.92.0 (compiler and gh-aw-actions/setup), engine copilot (CLI 1.0.96, copilot-sdk 1.0.16).
  • Still present on main (1e0f35f) and v1.0.1, as far as I can tell from the source.

Minimal reproduction

.github/workflows/inline-agent-repro.md:

---
on: workflow_dispatch
engine: copilot
inlined-imports: true
permissions:
  contents: read
---

Call the `task` tool once with `agent_type: greeter` and the prompt "Say hello".
Report the tool's exact result.

## agent: `greeter`
---
description: Replies with a fixed greeting.
---
Reply with exactly: hello from greeter
## end agent: `greeter`
  1. gh aw compile inline-agent-repro
  2. Run the workflow.

Expected: .github/agents/greeter.agent.md exists in the workspace, and task with agent_type: greeter returns "hello from greeter".

Actual:

  • The compiled prompt in inline-agent-repro.lock.yml has no ## agent: markers.
  • At runtime, interpolate_prompt.cjs takes the "No inline sub-agent markers found, skipping" branch, so no agent file is written.
  • "Restore inline sub-agents from activation artifact" has nothing to copy.
  • The task tool returns:
    Unknown agent_type: greeter. Valid types are: explore, task, general-purpose, code-review, research, security-review

Remove inlined-imports: true, recompile, and the same workflow works.

We hit this in a reusable workflow_call workflow, where inlined-imports: true is required because callers in other repositories don't have the source markdown. The failure was the same with claude-opus-5.5 and claude-sonnet-5.5.

Root cause

pkg/workflow/compiler_orchestrator_tools.go, extractEffectiveMarkdown:

effectiveMarkdown, subAgents, err := parser.ExtractInlineSubAgents(markdown)
...
orchestratorToolsLog.Printf("Extracted inline sub-agents: count=%d", len(subAgents))

subAgents is only logged. effectiveMarkdown (without the blocks) is used for prompt generation. (buildInitialWorkflowData extracts the sub-agents again into WorkflowData.SubAgents, but that is only read by pi_subagent_validation.go.)

  • Runtime-import mode (default): the prompt references the source file ({{#runtime-import …}}). At runtime the full file, markers included, is loaded, and writeInlineSubAgents in actions/setup/js/extract_inline_sub_agents.cjs writes the agents. Stripping at compile time has no effect.
  • inlined-imports: true: buildMainWorkflowPromptChunks embeds MainWorkflowMarkdown, which is derived from the stripped effectiveMarkdown, into the lock file. The markers are gone before runtime, and nothing else writes the agents.

The comment in pkg/parser/sub_agent_extractor.go also says the agent files "are written at runtime by interpolate_prompt.cjs after runtime imports are inlined". That assumption does not hold when the imports are inlined at compile time. (Its "Compilation Output" section says the extracted sub-agents are written to .github/agents/<name>.md during compilation, which no code does.)

ExtractInlineSkills runs right after it with the same pattern, so inline skills (## skill:) probably have the same problem with inlined-imports: true. I have not verified that.

Proposed fix

Either of these:

  1. Keep the blocks in the inlined prompt. When inlined-imports is on, append the extracted sub-agents (and skills) back to the embedded prompt, each with an explicit ## end agent: \name`marker.writeInlineSubAgents then extracts and writes them at runtime, as in runtime-import mode. This is the smallest change and reuses the per-engine target logic (getEngineSubAgentTarget`).
  2. Emit them at compile time. Put the extracted subAgents into the lock file (for example as a heredoc that the activation job writes to /tmp/gh-aw/<engine agents dir>/ before the artifact upload). The existing "Restore inline sub-agents from activation artifact" step then copies them into the workspace.

Tests to add:

  • A compiler test: with inlined-imports: true and an inline agent, the lock file still carries the agent (as markers or as an emitted file).
  • A runtime test: the agent file ends up under .github/agents/ for copilot (and .claude/agents/ and so on for other engines).

Workaround

A pre-agent step (steps:) writes /tmp/gh-aw/.github/agents/<name>.agent.md by hand and adds it to .git/info/exclude. "Restore inline sub-agents from activation artifact" then copies it into the workspace, and the Copilot SDK loads it as a custom agent. This works, but the agent definition then lives in a shell heredoc instead of the workflow body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions