Skip to content

fix: support additional user instructions in the system prompt - #285

Merged
marcelklehr merged 2 commits into
nextcloud:mainfrom
vyacheslavhulyaev-glitch:fix/338-user-instructions
Oct 22, 2026
Merged

marcelklehr merged 2 commits into
nextcloud:mainfrom
vyacheslavhulyaev-glitch:fix/338-user-instructions

Conversation

@vyacheslavhulyaev-glitch

@vyacheslavhulyaev-glitch vyacheslavhulyaev-glitch commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of the fix for nextcloud/assistant#338: the "Chat User Instructions for Chat Completions" admin setting of the Assistant is ignored when chatting through the Context Agent.

Companion PR in the Assistant: nextcloud/assistant#709

Changes

  • provider.py: declare a new optional input user_instructions (Text) on the classic and the multimodal provider, the same way memories is declared. No server change is needed.
  • agent.py: if set, append it after the agent's own system prompt, under a note telling the model to follow it unless it conflicts with the instructions above. As discussed in #338 by @janepie, admins can only add to the prompt, not replace it, so the tool calling instructions stay intact. Without the input, the prompt is unchanged.
  • main.py: log the new input along with memories.
  • tests/test_user_instructions.py: unit tests for the formatting and the provider declaration.

Testing

  • PYTHONPATH=. python tests/test_user_instructions.py: 3/3 pass
  • Local Nextcloud 35.0.2 with this branch, OpenAI gpt-4.1-mini: the optional input shows up in optionalInputShape of core:contextagent:interaction and core:contextagent:multimodal-interaction. With user_instructions: "Always answer like a pirate. Your name is Captain Cloud." and the input "What is your name?", the agent answers "Ahoy! I be Captain Cloud, yer trusty AI assistant sailin' the digital seas…"

Open questions

  • Is user_instructions a good name for the input?
  • Would you rather have this input in the server's ContextAgentInteraction optional input shape later, so it's a documented API rather than something only this provider declares?

Declare a new optional `user_instructions` input on the agent providers
(classic and multimodal). When set, e.g. by the Assistant app with its
"Chat User Instructions" admin setting, the text is appended to the
agent's own system prompt. It does not replace it, so the tool calling
instructions stay intact.

Refs nextcloud/assistant#338

Signed-off-by: Viacheslav Huliaiev <vyacheslavhulyaev@gmail.com>

@marcelklehr marcelklehr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@WSHAPER WSHAPER left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@julien-nc julien-nc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Add the optional "output_mode" input. With "speech", the agent's own
system prompt asks for a reply without Markdown or other formatting,
since it is sent to text-to-speech. This takes precedence over the
admin-provided instructions.

Signed-off-by: Viacheslav Huliaiev <vyacheslavhulyaev@gmail.com>
@vyacheslavhulyaev-glitch

Copy link
Copy Markdown
Contributor Author

Thanks for the approvals! After the review in nextcloud/assistant#709 I added one more optional input, output_mode. When it's speech (the Assistant sets it for audio chat), the prompt asks for plain text without Markdown, because the answer goes to TTS. If it's not set, nothing changes. Sorry for the extra round!

@marcelklehr marcelklehr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! No worries :)

@marcelklehr
marcelklehr merged commit e526caf into nextcloud:main Oct 22, 2026
5 of 7 checks passed
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.

4 participants