Skip to content

[FEATURE] Near-max-turns wrap-up system reminder #628

Description

@edenreich

Summary

The periodic system reminder (prompts.agent.system_reminders) fires on a fixed
interval (turns % interval == 0, in shouldInjectSystemReminder) with no
awareness of max_turns
. There is only one reminder_text, reused for every
injection, and the agent loop simply exits when completed_turns >= max_turns
without emitting any "approaching the limit" message or stream event.

That leaves no way to give the agent a fresh, well-timed nudge to stop starting
new work, commit and push everything, and make sure a draft PR exists
as the turn
budget runs out. inference-gateway/infer-action depends on this for graceful stop
(its "graceful agent stop" work, infer-action #88): today it can only bake that
guidance into the always-on system prompt, which is far back in context by the time
turns actually run low. infer-action has just slimmed its periodic reminders to
focused per-context nudges and is deferring the timed wrap-up nudge to this feature.

Proposed design

Add two fields to PromptsAgentRemindersConfig (config/prompts.go):

  • wrap_up_text (string) - reminder injected near the turn limit.
  • wrap_up_threshold (int) - turns-remaining window; inject when
    max_turns - turns <= wrap_up_threshold.

In the injection path (shouldInjectSystemReminder / internal/agent/agent_utils.go):
when max_turns > 0 && wrap_up_text != "" && (max_turns - turns) <= wrap_up_threshold,
inject wrap_up_text instead of the regular reminder_text. Outside that window,
behaviour is unchanged.

Surface via env, matching the existing namespace:
INFER_PROMPTS_AGENT_SYSTEM_REMINDERS_WRAP_UP_TEXT and
INFER_PROMPTS_AGENT_SYSTEM_REMINDERS_WRAP_UP_THRESHOLD.

Optionally tag the emitted system_reminder stream event (e.g. add a
phase: "wrap_up" field) so external observers can distinguish a wrap-up nudge from
a periodic one.

Downstream (separate infer-action PR, after a CLI release + pinned-version bump)

Add a buildWrapUpReminder(ctx) plus wrapup-*.md prompt sources and set the new
env vars in runner.ts / action.yml, plus a consumer-overridable input.

Acceptance Criteria

  • PromptsAgentRemindersConfig gains wrap_up_text and wrap_up_threshold
    (yaml + mapstructure + env via the existing INFER_PROMPTS_... namespace).
  • With a low max_turns, wrap_up_text is injected on the first interval tick
    within the final wrap_up_threshold turns; reminder_text is used before that.
  • When wrap_up_text is empty, behaviour is unchanged (only reminder_text).
  • Unit test covers the threshold boundary (text switches at the expected turn).
  • Config/docs reference updated for the two new fields.

Tracked alongside the reminder-slimming change in inference-gateway/infer-action
(fix(prompts): slim periodic reminders to context essentials); that PR will link
back to this issue.

Activity

  1. added
    enhancement
    on Jun 15, 2026
  2. moved this to Todo in 2026on Jun 15, 2026
  3. moved this from Todo to Done in 2026on Jun 16, 2026
  4. edenreich commented on Jun 17, 2026

    @edenreich
    ContributorAuthor

    @infer Can you work on this?

  5. inference-gateway-maintainer commented on Jun 17, 2026

    @inference-gateway-maintainer
    Contributor

    View Job

    Todos

    • Explore codebase structure and understand existing code
    • Add wrap_up_text and wrap_up_threshold to PromptsAgentRemindersConfig in config/prompts.go
    • Update shouldInjectSystemReminder/getSystemReminderMessage/injectSystemReminderIfDue in agent_utils.go
    • Add env var mappings in cmd/config.go
    • Add unit tests for threshold boundary
    • [~] Run tests and verify everything compiles

    Pull Request

    #635

    ⚠️ Infer Result: Stopped early

    The agent hit the job's time limit before finishing, so it was stopped to salvage its work. Its committed changes were pushed; the draft pull request is linked above.

    Now let me run the tests:

    Model: ollama_cloud/deepseek-v4-flash · Exit Code: 0 · Duration: —

    Tokens: 15,520,513 in · 31,027 out · 15,551,540 total (96 requests)

    Tool calls: 104 total · 94% success rate

    ⚠️ 6 failed tool call(s)
    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_utils.go

    Possible matches found:

    Near line 743:
    // getSystemReminderMessage returns the system reminder message to inject
    func (s *AgentServiceImpl) getSystemReminderMessage() sdk.Message {
    reminderText := s.config.Prompts.Agent.SystemReminders.ReminderText
    if reminderText == "" {
    reminderText = <system-reminder> This is a reminder that your todo list is currently empty. DO NOT mention this to the user explicitly because they are already aware. If you are working on tasks that would benefit from a todo list please use the TodoWrite tool to create one. If not, please feel free to ignore. Again do not mention this message to the user. </system-reminder>
    }

    return sdk.Message{
    	Role:    sdk.User,
    	Content: sdk.NewMessageContent(reminderText),
    }
    

    }

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_utils.go

    Possible matches found:

    Near line 743:
    // getSystemReminderMessage returns the system reminder message to inject
    func (s *AgentServiceImpl) getSystemReminderMessage() sdk.Message {
    reminderText := s.config.Prompts.Agent.SystemReminders.ReminderText
    if reminderText == "" {
    reminderText = <system-reminder> This is a reminder that your todo list is currently empty. DO NOT mention this to the user explicitly because they are already aware. If you are working on tasks that would benefit from a todo list please use the TodoWrite tool to create one. If not, please feel free to ignore. Again do not mention this message to the user. </system-reminder>
    }

    return sdk.Message{
    	Role:    sdk.User,
    	Content: sdk.NewMessageContent(reminderText),
    }
    

    }

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_utils.go

    Possible matches found:

    Near line 743:
    // getSystemReminderMessage returns the system reminder message to inject
    func (s *AgentServiceImpl) getSystemReminderMessage() sdk.Message {
    reminderText := s.config.Prompts.Agent.SystemReminders.ReminderText
    if reminderText == "" {
    reminderText = <system-reminder> This is a reminder that your todo list is currently empty. DO NOT mention this to the user explicitly because they are already aware. If you are working on tasks that would benefit from a todo list please use the TodoWrite tool to create one. If not, please feel free to ignore. Again do not mention this message to the user. </system-reminder>
    }

    return sdk.Message{
    	Role:    sdk.User,
    	Content: sdk.NewMessageContent(reminderText),
    }
    

    }

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_utils.go

    Possible matches found:

    Near line 743:
    // getSystemReminderMessage returns the system reminder message to inject
    func (s *AgentServiceImpl) getSystemReminderMessage() sdk.Message {
    reminderText := s.config.Prompts.Agent.SystemReminders.ReminderText
    if reminderText == "" {
    reminderText = <system-reminder> This is a reminder that your todo list is currently empty. DO NOT mention this to the user explicitly because they are already aware. If you are working on tasks that would benefit from a todo list please use the TodoWrite tool to create one. If not, please feel free to ignore. Again do not mention this message to the user. </system-reminder>
    }

    return sdk.Message{
    	Role:    sdk.User,
    	Content: sdk.NewMessageContent(reminderText),
    }
    

    }

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_reminder_emission_test.go

    Possible matches found:

    Near line 132:
    func TestInjectSystemReminderIfDue_WrapUpTextUsedWithinThreshold(t *testing.T) {
    // maxTurns=10, wrapUpThreshold=3, interval=2
    // At turn 8: maxTurns(10) - turns(8) = 2 <= threshold(3) => wrap-up text
    cfg := remindersWithWrapUpConfig(true, 2, "regular reminder", "wrap up now!", 3, 10)
    svc := &AgentServiceImpl{config: cfg}

    buf := withDebugStreamWriter(t)

    conv := []sdk.Message{}
    injected := svc.injectSystemReminderIfDue(8, &conv)

    assert.True(t, injected, "interval 2 with turn 8 must fire")
    require.Len(t, conv, 1, "reminder must be appended to conversation")
    content, _ := conv[0].Content.AsMessageContent0()
    assert.Equal(t, "wrap up now!", content, "wrap-up text must be used within threshold")

    var event map[string]any
    require.NoError(t, json.Unmarshal(bytes.TrimSpace(buf.Bytes()), &event))
    assert.Equal(t, "wrap_up", event["phase"], "stream event must indicate wrap_up phase")
    }

    func TestInjectSystemReminderIfDue_RegularTextUsedBeforeThreshold(t *testing.T) {
    // maxTurns=10, wrapUpThreshold=3, interval=2
    // At turn 4: maxTurns(10) - turns(4) = 6 > threshold(3) => regular reminder
    cfg := remindersWithWrapUpConfig(true, 2, "regular reminder", "wrap up now!", 3, 10)
    svc := &AgentServiceImpl{config: cfg}

    buf := withDebugStreamWriter(t)

    conv := []sdk.Message{}
    injected := svc.injectSystemReminderIfDue(4, &conv)

    assert.True(t, injected, "interval 2 with turn 4 must fire")
    require.Len(t, conv, 1, "reminder must be appended to conversation")
    content, _ := conv[0].Content.AsMessageContent0()
    assert.Equal(t, "regular reminder", content, "regular reminder text must be used before threshold")

    var event map[string]any
    require.NoError(t, json.Unmarshal(bytes.TrimSpace(buf.Bytes()), &event))
    assert.Equal(t, "periodic", event["phase"], "stream event must indicate periodic phase")
    }

    func TestInjectSystemReminderIfDue_WrapUpTextEmptyFallsBackToRegular(t *testing.T) {
    // When wrap_up_text is empty, behaviour is unchanged (regular reminder used)
    cfg := remindersWithWrapUpConfig(true, 2, "regular reminder", "", 3, 10)
    svc := &AgentServiceImpl{config: cfg}

    buf := withDebugStreamWriter(t)

    conv := []sdk.Message{}
    injected := svc.injectSystemReminderIfDue(8, &conv)

    assert.True(t, injected, "interval 2 with turn 8 must fire")
    require.Len(t, conv, 1, "reminder must be appended to conversation")
    content, _ := conv[0].Content.AsMessageContent0()
    assert.Equal(t, "regular reminder", content, "regular reminder text must be used when wrap_up_text is empty")

    var event map[string]any
    require.NoError(t, json.Unmarshal(bytes.TrimSpace(buf.Bytes()), &event))
    assert.Equal(t, "periodic", event["phase"], "stream event must indicate periodic phase when wrap_up_text is empty")
    }

    func TestInjectSystemReminderIfDue_WrapUpThresholdBoundary(t *testing.T) {
    // maxTurns=10, wrapUpThreshold=3, interval=2
    // At turn 6: maxTurns(10) - turns(6) = 4 > threshold(3) => regular reminder
    // At turn 8: maxTurns(10) - turns(8) = 2 <= threshold(3) => wrap-up text
    cfg := remindersWithWrapUpConfig(true, 2, "regular reminder", "wrap up now!", 3, 10)
    svc := &AgentServiceImpl{config: cfg}

    // Turn 6: outside threshold (10-6=4 > 3)
    conv := []sdk.Message{}
    injected := svc.injectSystemReminderIfDue(6, &conv)
    assert.True(t, injected)
    content, _ := conv[0].Content.AsMessageContent0()
    assert.Equal(t, "regular reminder", content, "turn 6 is outside threshold, must use regular text")

    // Turn 8: inside threshold (10-8=2 <= 3)
    conv2 := []sdk.Message{}
    injected2 := svc.injectSystemReminderIfDue(8, &conv2)
    assert.True(t, injected2)
    content2, _ := conv2[0].Content.AsMessageContent0()
    assert.Equal(t, "wrap up now!", content2, "turn 8 is inside threshold, must use wrap-up text")
    }

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    • Edit: old_string not found in file /home/runner/work/cli/cli/internal/agent/agent_reminder_emission_test.go

    Possible matches found:

    Near line 132:
    func TestInjectSystemReminderIfDue_WrapUpTextUsedWithinThreshold(t *testing.T) {
    // maxTurns=10, wrapUpThreshold=3, interval=2
    // At turn 8: maxTurns(10) - turns(8) = 2 <= threshold(3) => wrap-up text
    cfg := remindersWithWrapUpConfig(true, 2, "regular reminder", "wrap up now!", 3, 10)
    svc := &AgentServiceImpl{config: cfg}

    Hint: Ensure exact whitespace and indentation match. Use the Read tool to see the current file content.

    Triggered by edenreich · Infer Action

  6. edenreich commented on Jun 17, 2026

    @edenreich
    ContributorAuthor

    @infer Can you finalise the work? Please update the existing pull request title and description and continue your work there.

  7. inference-gateway-maintainer commented on Jun 17, 2026

    @inference-gateway-maintainer
    Contributor

    View Job

    Todos

    • Check out existing PR feat: add wrap-up reminders for agent mode (#628) #635 (branch fix/issue-628) and review current state
    • Understand the codebase structure (config/prompts.go, agent_utils.go, etc.)
    • Implement wrap_up_text and wrap_up_threshold in PromptsAgentRemindersConfig
    • Update shouldInjectSystemReminder to inject wrap_up_text near max_turns
    • Add env var support for the new fields
    • Add unit tests for threshold boundary
    • Update PR title, description, and push changes

    Pull Request

    #635

    ✅ Infer Result: Success

    The task is complete. All acceptance criteria from the issue have been met:

    • Config: wrap_up_text and wrap_up_threshold added to PromptsAgentRemindersConfig with yaml, mapstructure, and env var support
    • Injection logic: Both the streaming agent path (agent_utils.go) and the sync agent loop (cmd/agent.go) correctly switch to wrap-up text when within the threshold
    • Stream events: Tagged with phase: "wrap_up" vs "periodic" for external observers
    • Tests: 4 new tests covering threshold boundary, text switching, and empty fallback — all passing
    • Documentation: Both configuration-reference.md and channels.md updated
    • Build: Compiles cleanly, all tests pass

    Model: ollama_cloud/deepseek-v4-flash · Exit Code: 0 · Duration: 6m 50s

    Tokens: 3,274,544 in · 11,697 out · 3,286,241 total (51 requests)

    Tool calls: 53 total · 100% success rate

    Triggered by edenreich · Infer Action

  8. inference-gateway-releaser commented on Jun 20, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.122.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions