local agent dev -> "RPC error: Error: Method toJSON does not exist"

for the life of me, I cannot figure out why this RPC call is failing. Near as I can tell, when toJSON is not available, it means the durable object isn't available? my local DO seems to exist in .wrangler and naming agrees with my wrangler.jsonc, so idk if this is an agent thing or what. Happy to provide more here, but idk what to share. signed, nearly dead from this in Atlanta ☠️ -- via browser console:
agents_react.js?v=96d2183a:799 Uncaught (in promise) Error: Method toJSON does not exist
at Object.onMessage (agents_react.js?v=96d2183a:799:28)
at PartySocket.onMessage (agents_react.js?v=96d2183a:652:104)
at PartySocket.sentryWrapped (@sentry_remix.js?v=96d2183a:10441:17)
at WebSocket.<anonymous> (agents_react.js?v=96d2183a:148:12)
at WebSocket.sentryWrapped (@sentry_remix.js?v=96d2183a:10441:17)
agents_react.js?v=96d2183a:799 Uncaught (in promise) Error: Method toJSON does not exist
at Object.onMessage (agents_react.js?v=96d2183a:799:28)
at PartySocket.onMessage (agents_react.js?v=96d2183a:652:104)
at PartySocket.sentryWrapped (@sentry_remix.js?v=96d2183a:10441:17)
at WebSocket.<anonymous> (agents_react.js?v=96d2183a:148:12)
at WebSocket.sentryWrapped (@sentry_remix.js?v=96d2183a:10441:17)
via agent worker terminal:

RPC error: Error: Method toJSON does not exist
at null.<anonymous>
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/agents/src/index.ts:445:23)
at Agent.onMessage
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/agents/src/index.ts:418:27)
at _AgentSupervisor.webSocketMessage
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/partyserver/src/index.ts:386:17)

RPC error: Error: Method toJSON does not exist
at null.<anonymous>
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/agents/src/index.ts:445:23)
at Agent.onMessage
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/agents/src/index.ts:418:27)
at _AgentSupervisor.webSocketMessage
(file:///Users/pk2/Avnir/cfw-avnir-agent/node_modules/partyserver/src/index.ts:386:17)
4 Replies
steyblind
steyblindOP5mo ago
if this helps, here's npm list depth=0
├── @ai-sdk/openai@2.0.0-beta.3
├── @clerk/backend@2.3.0
├── @cloudflare/vitest-pool-workers@0.8.47
├── @types/node@24.0.8
├── agents@0.0.101
├── ai@5.0.0-beta.6
├── handlebars@4.7.8
├── hono@4.8.3
├── openai@5.8.2
├── partyserver@0.0.72
├── typescript@5.8.3
├── vitest@3.0.9
├── workers-mcp@0.0.13
├── wrangler@4.23.0
└── zod@3.25.67
├── @ai-sdk/openai@2.0.0-beta.3
├── @clerk/backend@2.3.0
├── @cloudflare/vitest-pool-workers@0.8.47
├── @types/node@24.0.8
├── agents@0.0.101
├── ai@5.0.0-beta.6
├── handlebars@4.7.8
├── hono@4.8.3
├── openai@5.8.2
├── partyserver@0.0.72
├── typescript@5.8.3
├── vitest@3.0.9
├── workers-mcp@0.0.13
├── wrangler@4.23.0
└── zod@3.25.67
1984 Ford Laser
1984 Ford Laser5mo ago
Do you have a toJSON() method defined in your Agent/DO class?
steyblind
steyblindOP5mo ago
I'll try manually creating one. My best guess is that the object being checked was the Agent-as-a-DO stub, which should have it anyway. good idea tho OK, shockingly, this fixed the error, but I'm failing to understand why this is different from any other DO/websocket interface.
@callable()
toJSON() {
console.log('toJSON called?', this.state);
return this.state;
}
@callable()
toJSON() {
console.log('toJSON called?', this.state);
return this.state;
}
@1984 Ford Laser you're a champ my first car was a 78 chevy nova, tho, sorry
1984 Ford Laser
1984 Ford Laser5mo ago
I couldn't find any reference to a toJSON() function being included in the Agents SDK, unless I'm missing something. Good to hear you got it sorted though

Did you find this page helpful?