-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
What happened?
In @mariozechner/pi-agent-core’s agent-loop, two call sites invoke .filter() directly on message.content and assistantMessage.content without checking that the value is an array. When a sub-agent (or another code path) yields a message whose content is a string or other non-array value, Node throws:
TypeError: xxx.content.filter is not a function
The assistant message ends up with stopReason: "error" and the agent loop stops. This was reproduced upstream in OpenClaw when using sessions_spawn with runtime: "subagent"; see openclaw/openclaw#51390.
Corresponding source in this repo:
- Main loop:
message.content.filter(...)inpackages/agent/src/agent-loop.ts(around line 201) executeToolCalls:assistantMessage.content.filter(...)(around line 343)
Other parts of the same file already iterate content defensively; these sites should follow the same pattern (e.g. (Array.isArray(content) ? content : []).filter(...)).
Steps to reproduce
- Run an agent through a path that can produce a message with non-array
content(as in upstream: parent usessessions_spawn, childruntime: "subagent"). - Ensure the child returns a message where
contentis a string (or otherwise not an array). - When the parent
agent-loopprocesses that message, execution hits one of the.filter()sites and throws.
Expected behavior
The agent loop must not crash with .filter is not a function when content is not an array. Non-array content should be treated as “no structured content blocks” or normalized according to the type contract before resolving tool calls.
Version
0.60.0