[Bug]: Copilot provider (claude-sonnet-5) repository generation crashes with "expected AIMessage or Command, got object" in OpenWikiRepositoryWorkerNoDelegation
Author: RajeshLTIMCreated Sep 4, 2026Updated Sep 10, 2026
Description
openwiki --init (repository/code mode) fails on the first model call when the provider is copilot with a Claude model, in the repository-generation page-job path (src/agent/repository-runner.ts), not the chat-mode agent path:
Error Invalid response from "wrapModelCall" in middleware "OpenWikiRepositoryWorkerNoDelegation": expected AIMessage or Command, got objectThis looks related to #213 / #659 (same validator, same error text) but is a distinct, unfixed path:
- #213/#659's fix (PR #660) only special-cases
provider !== "openai-compatible"insrc/agent/index.ts'srunOpenWikiAgentCore, dropping the"messages"stream mode to avoidChatMessageChunkaggregation from providers that stream reasoning deltas before the firstrole:"assistant"delta. - The repository-generation path used by
--init/--update(runNativeRepositoryGeneration→runPlanningAgent/runPageAgentinrepository-runner.ts) never uses"messages"stream mode at all —streamWorkerToolsonly streams["tools"]. So the #660 fix's root cause (chunk-aggregation from a streamed roleless-first delta) does not apply here, meaning something else is producing a non-AIMessageobject from the model call in this path. - The middleware named in the error,
OpenWikiRepositoryWorkerNoDelegation, only exists inrepository-runner.ts(added to strip thetasktool from DeepAgents 1.12+). It just forwardswrapModelCall's result untouched — it isn't the source of the invalid object, only the outermost middleware that surfaces the agent loop's rejection.
Steps to Reproduce
- Configure the GitHub Copilot provider with a Claude model:
OPENWIKI_PROVIDER=copilot OPENWIKI_MODEL_ID=claude-sonnet-5 COPILOT_API_KEY=<GitHub OAuth token> - Run
openwiki --initin any repository (code/repository mode). - The first agent turn (planning worker) crashes with the error above. No wiki is produced.
Expected Behavior
The run completes and the wiki is generated, as it does with other providers/models.
Actual Behavior
Crash on the first model call in the repository planning worker. Credential diagnostics confirm OPENWIKI_PROVIDER=copilot, OPENWIKI_MODEL_ID=claude-sonnet-5, and COPILOT_API_KEY are all present and correctly sourced — this is not a missing-credential issue.
Environment
- OpenWiki version: 0.5.0
- Provider:
copilot(routes throughhttps://api.githubcopilot.com, OpenAI-compatible surface) - Model:
claude-sonnet-5 - OS: Windows
Additional Context
- Searched existing issues for
copilot+wrapModelCall/AIMessageand forOpenWikiRepositoryWorkerNoDelegation— no existing reports found. - Suspect the Copilot API's response shape for Claude models (proxied through an OpenAI-compatible surface) produces a message object that the DeepAgents/langchain
AgentNode'swrapModelCallvalidator (AIMessage.isInstance(...) || isCommand(...) || {structuredResponse, messages}) doesn't recognize, similar in class to #659 but via_generate/.invoke()rather than streaming chunk-aggregation, since this path never streams"messages". - A repro comparing the raw object returned by
ChatOpenAI(as constructed for thecopilotprovider increateModel) againstAIMessage.isInstance()for aclaude-sonnet-5completion would likely confirm the shape mismatch.
Source: langchain-ai/openwiki