Skip to content

Chat User Instructions for Chat Completions Not Being Sent to LLM with context_agent enabled #338

Closed

Description

@reidellawfirm

Which version of integration_openai are you using?

3.7.1

Which version of Nextcloud are you using?

NC Hub 10 31.0.7

Which browser are you using? In case you are using the phone App, specify the Android or iOS version and device please.

Vivaldi

Describe the Bug

The Chat User Instructions for Chat Completions setting is not being passed to configured LLM. The following task printouts show there is no 'system prompt' which should be included per the User Instruction setting.

Here is the specific instruction I set for before each test request.

Image

Then I ran these test requests. I see that any query to the Chat with AI mode in NC Assistant creates at least 2 tasks. I believe this is to account for tool calling when supported. Also note that no request has any 'system prompt' included.

Request 1 Task:
- id: 10929
- type: core:contextagent:interaction
- lastUpdated: 1754668023
- status: STATUS_SUCCESSFUL
- userId: rockyreidel
- appId: assistant:chatty-llm
- input:
- input: What is your name?
- confirmation: 0
- conversation_token: {}
- output:
- output: My name is Assistant. How can I assist you today?
- conversation_token: ...

  - actions:
  - sources:
- customId: chatty-llm:50
- completionExpectedAt: 1754668075
- progress: 1
- scheduledAt: 1754668015
- startedAt
- endedAt: 1754668023
- error_message
  • 1:
    • id: 10930
    • type: core:text2text:chatwithtools
    • lastUpdated: 1754668020
    • status: STATUS_SUCCESSFUL
    • userId: rockyreidel
    • appId: context_agent
    • input:
      • system_prompt:
        You are a helpful AI assistant with access to tools, please respond to the user's query to the best of your ability, using the provided tools! If you used a tool, you still need to convey its output to the user.
        Use the same language for your answers as the user used in their message.
        Today is 2025-08-08.
        Detect the language the user is using. Reply in the detected language. Do not output the detected language.
        Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
        You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
        You can check which calendars exist using the list_calendars tool, if a calendar can not be found.
        you can find out a user's email address and location by using the find_person_in_contacts tool.
        you can find out the current user's location by using the find_details_of_current_user tool.
        If an item should be added to a list, check list_calendars for a fitting calendar and add the item as a task there.

      • input: What is your name?

      • tool_message:

      • history: ...

      • - output:
        
      • output: My name is Assistant. How can I assist you today?

      • tool_calls:

    • customId:
    • completionExpectedAt: 1754668036
    • progress: 1
    • scheduledAt: 1754668018
    • startedAt: 1754668018
    • endedAt: 1754668020
    • error_message

Request Task 2:
0:
- id: 10935
- type: core:contextagent:interaction
- lastUpdated: 1754668352
- status: STATUS_SUCCESSFUL
- userId: rockyreidel
- appId: assistant:chatty-llm
- input:
- input: What is your name? What is the color of the sky?
- confirmation: 0
- conversation_token: {}
- output:
- output: My name is Assistant. The color of the sky is generally blue during the day and changes to shades of orange, pink, and red during sunrise and sunset, depending on weather and atmospheric conditions.
- conversation_token: ....
- - actions:
- sources:
- customId: chatty-llm:51
- completionExpectedAt: 1754668403
- progress: 1
- scheduledAt: 1754668343
- startedAt
- endedAt: 1754668352
- error_message

  • 1:
    • id: 10936
    • type: core:text2text:chatwithtools
    • lastUpdated: 1754668349
    • status: STATUS_SUCCESSFUL
    • userId: rockyreidel
    • appId: context_agent
    • input:
      • system_prompt:
        You are a helpful AI assistant with access to tools, please respond to the user's query to the best of your ability, using the provided tools! If you used a tool, you still need to convey its output to the user.
        Use the same language for your answers as the user used in their message.
        Today is 2025-08-08.
        Detect the language the user is using. Reply in the detected language. Do not output the detected language.
        Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
        You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
        You can check which calendars exist using the list_calendars tool, if a calendar can not be found.
        you can find out a user's email address and location by using the find_person_in_contacts tool.
        you can find out the current user's location by using the find_details_of_current_user tool.
        If an item should be added to a list, check list_calendars for a fitting calendar and add the item as a task there.

      • input: What is your name? What is the color of the sky?

      • tool_message:

      • history:.....

      • - output:
        
      • output: My name is Assistant. The color of the sky is generally blue during the day and changes to shades of orange, pink, and red during sunrise and sunset, depending on weather and atmospheric conditions.

      • tool_calls:

    • customId:
    • completionExpectedAt: 1754668364
    • progress: 1
    • scheduledAt: 1754668346
    • startedAt: 1754668347
    • endedAt: 1754668349
    • error_message

Any other settings I should troubleshoot to find the reason why this setting is not being passed correctly?

Expected Behavior

The setting from Chat User Instructions for Chat Completions in the Admin Settings > Artificial Intelligence should be included in the requests to the LLM

To Reproduce

Change setting Chat User Instructions for Chat Completions
Send test request to LLM
Review task process if a system prompt was included or not

Activity

  1. changed the title [-]Chat User Instructions for Chat Completions Not Being Sent to LLM[/-] [+]Chat User Instructions for Chat Completions Not Being Sent to LLM with context_agent enabled[/+] on Aug 11, 2025
  2. kyteinsky commented on Aug 11, 2025

    @kyteinsky
    Contributor

    transferring this issue to the assistant repo for possible resolution

  3. janepie commented on Jan 16, 2026

    @janepie
    Member

    Hello! The system prompt for Context Agent is actually a different one than we use without it as it includes instructions for tool calling, leaving it open for admins to change is not really a good idea. We could think about a way of including some extra instructions to be included, I will come back to you on that.

  4. vyacheslavhulyaev-glitch commented on Oct 21, 2026

    @vyacheslavhulyaev-glitch
    Contributor

    Hi @julien-nc @janepie 👋

    I've looked into this. Here's what I found and what I'd suggest before I start on PRs.

    Cause

    When Context Agent is available, ChatService::scheduleMessageGeneration() sends the request through scheduleAgencyTask /
    scheduleAgencyMultimodalTask / scheduleAgencyAudioTask. Those only send input, confirmation, conversation_token and memories. The session's system
    message, which holds the "Chat User Instructions", is only read in the classic chat branch. On the Context Agent side, agent.py builds its system
    prompt from fixed text and has no input for extra instructions.

    Proposal (no server change needed)

    Following @janepie's point that the agent's own prompt shouldn't be replaceable, admins could add instructions to it instead of overriding it:

    1. context_agent
      • Declare a new optional input user_instructions (Text) in provider.py, the same way memories is declared, on both the regular and the
        multimodal provider.
      • In agent.py, if it's set, add it at the end of the built-in prompt under a heading like "Additional instructions from the administrator
        (follow them unless they conflict with the rules above)". The tool-calling rules stay intact.
    2. assistant
      • In the three scheduleAgency*Task methods, send the session's system message as user_instructions, but only when
        optionalInputShape['user_instructions'] is available. That's the same check as for memories, so older Context Agent versions keep working.
      • Forward it in ContextAgentAudioInteractionProvider as well.
      • Update the admin settings hint to say the setting also applies to agent chat.

    Questions

    1. Is reusing the existing "Chat User Instructions" setting OK, or would you prefer a separate "Additional agent instructions" setting? The current
      default text doesn't contradict the agent prompt, so reusing it looks safe to me.
    2. Is user_instructions a good name for the input?
    3. Should assignment runs (scheduleAssignmentMessageGeneration) also get the instructions? With this approach they would by default.
    4. Longer term, would you want the input in the server's ContextAgentInteraction optional input shape so it's a documented API, rather than
      something only this provider declares?
    5. Existing sessions keep the instructions saved when they were created, the same as classic chat. I'm assuming that's fine.

    If this direction sounds right, I'll open two PRs (context_agent and assistant) that link to each other.

  5. vyacheslavhulyaev-glitch commented on Oct 21, 2026

    @vyacheslavhulyaev-glitch
    Contributor

    Both PRs are ready for review:

    Tested on Nextcloud 35.0.2 with a real model: with "Always answer like a pirate" in the admin settings, agentic chat now follows the instructions.

    Two points I'd like your opinion on:

    1. Since every session stores the setting, the default instructions are now also sent to every agent chat. Should we only send them when the admin has customised them? That's a small change.
    2. The audio path is covered by code review and unit logic, but I couldn't test it end to end.

    Happy to adjust anything.

  6. julien-nc commented on Oct 22, 2026

    @julien-nc
    Member

    @vyacheslavhulyaev-glitch About your questions:

    1. Reusing is fine IMO too
    2. user_instructions is fine 👍
    3. Addressed in the assistant PR
    4. If we stick with this approach, yes, long term we could add this input in the task type itself. We usually don't change task types but rather create new ones to prevent breaking providers. In this case, context_agent is the only provider for ContextAgentInteraction so we'll see.
    5. Seems fine to me.
  7. vyacheslavhulyaev-glitch commented on Oct 22, 2026

    @vyacheslavhulyaev-glitch
    Contributor

    @julien-nc thanks! The audio part is in both PRs now (new output_mode input), more details in #709.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions