mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
feat: round-limit handling — Continue affordance at the cap + configurable cap (#1999)
* feat: round-limit handling — Continue affordance at the cap + configurable cap
When the agent loop runs out of rounds (per-message step cap, default 20)
while still actively using tools, it stopped silently mid-task. Now:
1. The loop emits a `rounds_exhausted` SSE event at the cap, and the UI shows
a "Continue" pill at the bottom of the chat that resumes the task from where
it left off. Repeated cap-hits each get a fresh Continue (multiple continues
in a row).
2. The cap is configurable in Settings → Agent ("Max steps per message"),
validated on the client, at the save endpoint, and at the read site.
- src/agent_loop.py: track `_exhausted_rounds` (set only when a full
tool-executing round completes on the last allowed round — i.e. the agent
wanted to keep going); emit `{"type":"rounds_exhausted","rounds":N}` (logged).
- routes/chat_routes.py: read `agent_max_rounds` (clamped 1..200), pass as
`max_rounds`; forward the new event through the SSE relay.
- routes/auth_routes.py: validate numeric settings on save (int + clamp;
agent_max_rounds 1..200, agent_max_tool_calls 0..1000; 400 on non-int).
- src/settings.py: default `agent_max_rounds = 20`.
- static/: Settings input + client-side clamp; the Continue pill (reuses the
existing .stopped-indicator / .continue-btn classes and theme vars
--border/--fg/--bg/--accent); appended to the chat container so it survives
the message re-render at stream finalize. chat.js cache version bumped.
* test: cover rounds_exhausted emission (cap-hit vs normal finish)
Drives the real stream_agent_loop with mocked LLM stream / tool exec / settings:
a tool block every round exhausts the cap and must emit rounds_exhausted; a
plain answer hits the done-break and must not. Guards the for/else logic.
This commit is contained in:
committed by
GitHub
parent
a54f41037d
commit
64d65b73c1
@@ -1836,6 +1836,44 @@ import createResearchSynapse from './researchSynapse.js';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (json.type === 'rounds_exhausted') {
|
||||
// The agent hit the per-turn step limit while still working.
|
||||
// Offer a Continue button instead of stalling silently.
|
||||
// NOTE: append to the chat-history container (bottom), NOT the
|
||||
// message body — the body innerHTML is re-rendered at stream
|
||||
// finalize, which would wipe a note placed inside it.
|
||||
const _chatBox = document.getElementById('chat-history');
|
||||
if (!_isBg && _chatBox) {
|
||||
// Drop any prior box so repeated cap-hits each get a fresh
|
||||
// Continue at the bottom (multiple continues in a row).
|
||||
const _old = _chatBox.querySelector('.rounds-exhausted');
|
||||
if (_old) _old.remove();
|
||||
const note = document.createElement('div');
|
||||
note.className = 'stopped-indicator rounds-exhausted';
|
||||
const label = document.createElement('span');
|
||||
label.className = 'rounds-exhausted-label';
|
||||
label.textContent = `Reached the ${json.rounds || ''}-step limit — not finished.`;
|
||||
note.appendChild(label);
|
||||
const contBtn = document.createElement('button');
|
||||
contBtn.className = 'continue-btn';
|
||||
contBtn.title = 'Continue the task';
|
||||
contBtn.textContent = 'Continue ▸';
|
||||
const _holder = currentHolder;
|
||||
contBtn.addEventListener('click', () => {
|
||||
note.remove();
|
||||
_hideUserBubble = true;
|
||||
_pendingContinue = _holder;
|
||||
const msgInput = uiModule.el('message');
|
||||
if (msgInput) {
|
||||
msgInput.value = 'You hit the step limit before finishing — the task is not complete. Continue from exactly where you left off and keep going until it is done. Do NOT repeat work already done.';
|
||||
const sb = document.querySelector('.send-btn');
|
||||
if (sb) sb.click();
|
||||
}
|
||||
});
|
||||
note.appendChild(contBtn);
|
||||
_chatBox.appendChild(note);
|
||||
try { note.scrollIntoView({ block: 'end', behavior: 'smooth' }); } catch (_) { uiModule.scrollHistory && uiModule.scrollHistory(); }
|
||||
}
|
||||
} else if (json.type === 'attachments') {
|
||||
if (_isBg) continue;
|
||||
// Update user bubble — replace file chips with image previews
|
||||
|
||||
Reference in New Issue
Block a user