Skip to content

fix(ai-chat): ensure jsonSchema initialized before onChatMessage#979

Merged
threepointone merged 1 commit into
mainfrom
fix/ai-chat-ensure-json-schema
Feb 24, 2026
Merged

fix(ai-chat): ensure jsonSchema initialized before onChatMessage#979
threepointone merged 1 commit into
mainfrom
fix/ai-chat-ensure-json-schema

Conversation

@mattzcarey

Copy link
Copy Markdown
Contributor

Summary

  • Fix jsonSchema not initialized error when calling getAITools() in onChatMessage

Problem

After PR #565 (RPC transport), the base Agent class wraps onMessage to call ensureJsonSchema() before processing messages. However, AIChatAgent re-wraps onMessage in its constructor and handles chat messages directly without going through the base wrapper.

This caused getAITools() to throw "jsonSchema not initialized" when called in onChatMessage().

Fix

Add await this.mcp.ensureJsonSchema() to AIChatAgent's onMessage wrapper, matching the pattern used in the base Agent class.

Test plan

  • Deployed codemode example and verified chat messages work without error
  • Verified MCP tools can be retrieved via getAITools() in onChatMessage

AIChatAgent's onMessage wrapper bypasses the base Agent's wrapper which
calls ensureJsonSchema(). This caused "jsonSchema not initialized" errors
when getAITools() was called in onChatMessage.

Add ensureJsonSchema() call to AIChatAgent's onMessage wrapper to match
the base Agent pattern.
@changeset-bot

changeset-bot Bot commented Feb 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 14de6a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/ai-chat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@threepointone
threepointone merged commit 23c90ea into main Feb 24, 2026
6 of 7 checks passed
@threepointone
threepointone deleted the fix/ai-chat-ensure-json-schema branch February 24, 2026 12:37
@github-actions github-actions Bot mentioned this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants