Skip to content

Strip non-schema message fields for Mistral chat requests#48

Open
jvmenen wants to merge 1 commit intoagent0ai:mainfrom
jvmenen:mistral-frontend-request-strip
Open

Strip non-schema message fields for Mistral chat requests#48
jvmenen wants to merge 1 commit intoagent0ai:mainfrom
jvmenen:mistral-frontend-request-strip

Conversation

@jvmenen
Copy link
Copy Markdown

@jvmenen jvmenen commented Apr 30, 2026

Summary

  • Mistral's chat completions API uses strict Pydantic validation (extra="forbid") and rejects any field on a message object that is not part of its defined schema.
  • Space Agent's prompt pipeline attaches internal bookkeeping fields such as tokenCount, kind, and source to message objects for prompt budgeting and UI display, which causes Mistral to reject the request.
  • This PR adds a headless _core/mistral module with shared endpoint detection and a body-rewrite helper, wired through extension hooks on prepareOnscreenAgentApiRequest and prepareAdminAgentApiRequest. Non-Mistral requests are left untouched.

Design notes

  • Provider detection runs against the configured upstream API endpoint (not the proxied fetch URL), since frontend fetches may be rerouted through /api/proxy.
  • The body rewrite preserves only the message fields accepted by Mistral's schema: role, content, name, tool_calls, tool_call_id. If Mistral expands the accepted schema later, extend ALLOWED_MESSAGE_FIELDS in request.js rather than removing the strip.
  • Provider-specific HTTP policy is kept inside this module instead of branching inside _core/onscreen_agent/llm.js or _core/admin/views/agent/api.js, so the admin and onscreen surfaces stay in sync via one shared helper.
  • AGENTS.md documents ownership and contracts for the new module.

Test plan

  • Send a chat request from the onscreen agent against a Mistral endpoint and confirm the request succeeds (previously rejected with a 422 from Pydantic validation).
  • Send a chat request from the admin agent view against a Mistral endpoint and confirm the same.
  • Send a request against a non-Mistral endpoint (e.g. OpenAI / OpenRouter) and confirm the request body is unchanged.
  • Verify in the desktop build that the bundled app/**/* assets include the new _core/mistral module after repackaging.

Mistral's chat completions API uses strict Pydantic validation
(extra="forbid") and rejects internal bookkeeping fields (tokenCount,
kind, source) that the prompt pipeline attaches to message objects.

Add a headless _core/mistral module with shared endpoint detection and
a body-rewrite helper, wired through extension hooks on
prepareOnscreenAgentApiRequest and prepareAdminAgentApiRequest.
Non-Mistral requests are untouched.
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.

1 participant