fix(ai): prevent duplicated system prompts in PydanticAI completions#8356
Merged
Light2Dark merged 2 commits intomarimo-team:mainfrom Feb 18, 2026
Merged
fix(ai): prevent duplicated system prompts in PydanticAI completions#8356Light2Dark merged 2 commits intomarimo-team:mainfrom
Light2Dark merged 2 commits intomarimo-team:mainfrom
Conversation
## Summary Add a test that verifies the `completion` method does not pass redundant instructions to the PydanticAI agent, which causes system prompt duplication in API requests. ## Description of Changes This test currently fails because `system_prompt` is passed to both the `Agent()` constructor (via `create_agent`) and `agent.run()`, causing PydanticAI's `_get_instructions` to concatenate them.
## Summary The `system_prompt` was being passed to both the `Agent` constructor and `agent.run()`, causing PydanticAI's `_get_instructions` to duplicate it. Remove the redundant `instructions` argument from `agent.run()`. ## Description of Changes In `PydanticProvider.completion()`, `system_prompt` was already passed to `create_agent()`, which initializes the agent with those instructions. Passing it again to `agent.run()` caused duplication because `Agent._get_instructions()` concatenates constructor-level instructions with run-level `additional_instructions`. Removing `instructions=system_prompt` from `agent.run()` resolves this.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
recheck |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Collaborator
|
Thanks @fpreiss , I think you are right. Do you also want to address the other parts? I believe they aren't hit because only on certain codepaths but would be good to get them |
Light2Dark
approved these changes
Feb 18, 2026
Contributor
Author
|
Yes, I'm willing to take care of this within the next week. |
LiquidGunay
pushed a commit
to LiquidGunay/marimo
that referenced
this pull request
Feb 21, 2026
…arimo-team#8356) I intercepted the outgoing API request and observed the following duplicated content in the system message during tab completion: ```json { "messages": [ { "content": "You are a python code completion assistant... \nYou are a python code completion assistant...", "role": "system" }, ... ] } ``` ## Cause This is caused by the internal concatenation logic of `pydantic_ai.agent.__init__.Agent._get_instructions` and how `completion` in `marimo/_server/ai/providers.py` is providing the `system_prompt` to both - the `Agent`'s constructor and the `agent.run` method. ## Fix The fix removes `instructions=system_prompt` from `agent.run()`, leaving only the constructor-level instructions. ## Notes A similar duplication issue likely exists in `stream_text()` (also in `providers.py`), where `system_prompt` may be passed to both `create_agent()` and `agent.run_stream()`. I have not verified this e2e though. ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [x] Tests have been added for the changes made. - [x] Pull request title is a good summary of the changes - it will be used in the [release notes](https://github.com/marimo-team/marimo/releases).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I intercepted the outgoing API request and observed the following duplicated content in the system message during tab completion:
{ "messages": [ { "content": "You are a python code completion assistant... \nYou are a python code completion assistant...", "role": "system" }, ... ] }Cause
This is caused by the internal concatenation logic of
pydantic_ai.agent.__init__.Agent._get_instructionsand howcompletioninmarimo/_server/ai/providers.pyis providing thesystem_promptto both - theAgent's constructor and theagent.runmethod.Fix
The fix removes
instructions=system_promptfromagent.run(), leaving only the constructor-level instructions.Notes
A similar duplication issue likely exists in
stream_text()(also inproviders.py), wheresystem_promptmay be passed to bothcreate_agent()andagent.run_stream(). I have not verified this e2e though.📋 Checklist