Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c3a2a1a
merge
wangxingjun778 Oct 13, 2026
950b941
ok Merge branch 'feat/mhs' of github.com:modelscope/leapflow into fea…
wangxingjun778 Oct 15, 2026
acd9464
ok Merge branch 'feat/mhs' of github.com:modelscope/leapflow into fea…
wangxingjun778 Oct 15, 2026
78a2563
remove unused content
wangxingjun778 Oct 16, 2026
6a5aea3
refactor and enhance hardware framework
wangxingjun778 Oct 19, 2026
e5b133d
add enhance hardware skills
wangxingjun778 Oct 20, 2026
1093d18
ok Merge branch 'feat/mhs' of github.com:modelscope/leapflow into fea…
wangxingjun778 Oct 20, 2026
ade894a
refactor hardware drivers
wangxingjun778 Oct 22, 2026
6da5b04
bump version
wangxingjun778 Oct 22, 2026
cb8866b
refine hardware skills and support for new sdk for piper-x
wangxingjun778 Oct 23, 2026
9186fea
refactor and refine hardware for specific sys topology
wangxingjun778 Oct 24, 2026
8a8d51e
refactor & enhance hardware module and add multi-source for media sig…
wangxingjun778 Oct 26, 2026
42dcf8a
feat(vision): share camera capture and harden preview lifecycle
wangxingjun778 Oct 27, 2026
304d5fc
add new module: LeapCalib
wangxingjun778 Oct 27, 2026
30740ec
enhance LeapCalib
wangxingjun778 Oct 30, 2026
9191107
chore: normalize author identity via .mailmap
wangxingjun778 Nov 5, 2026
0bcc6ac
ok Merge branch 'feat/mhs' of github.com:modelscope/leapflow into fea…
wangxingjun778 Nov 5, 2026
e1c1170
chore(repo): ignore .qoder and normalize mislabeled author identity
wangxingjun778 Nov 5, 2026
d11b604
chore(repo): drop obsolete mailmap entry for the rewritten identity
wangxingjun778 Nov 5, 2026
8cd639c
refactor leapcalib
wangxingjun778 Nov 12, 2026
d20bde2
fix leapd arm halt issue
wangxingjun778 Nov 12, 2026
faf1c17
grasp box success
wangxingjun778 Nov 12, 2026
0916784
fix worker leakage
wangxingjun778 Nov 13, 2026
dbb8eef
add leapboard stop and manage
wangxingjun778 Nov 13, 2026
2c5420c
add plan-time reach pre-check to motion.sequence
wangxingjun778 Nov 13, 2026
36104c7
refine pipeline for NL control devices
wangxingjun778 Nov 13, 2026
86404e5
fix hang issue and real jetson board deployment
wangxingjun778 Nov 16, 2026
2669bb8
fix tui terminal crash
wangxingjun778 Nov 16, 2026
577426a
fix vision capabilities
wangxingjun778 Nov 16, 2026
32281f8
ok Merge branch 'main' of github.com:modelscope/leapflow into feat/mhs
wangxingjun778 Nov 16, 2026
524841a
bump version
wangxingjun778 Nov 16, 2026
6f87152
fix hw_skill_run args issue
wangxingjun778 Nov 16, 2026
5eaffb1
fix piper-x halt policy and add hold-in-place policy
wangxingjun778 Nov 17, 2026
5857393
fix tui crash; enhance grasp async-batch perception
wangxingjun778 Nov 17, 2026
55c4408
fix config health classification and guard live preview lifecycle
wangxingjun778 Nov 17, 2026
ebef553
fix candidates and leapboard monitor
wangxingjun778 Nov 17, 2026
33090e4
ok Merge branch 'main' of github.com:modelscope/leapflow into feat/mhs
wangxingjun778 Nov 18, 2026
bfe94fd
bump version
wangxingjun778 Nov 18, 2026
b50bb59
feat: licensed hardware observation policy and graceful node stop
wangxingjun778 Nov 18, 2026
5569933
ok Merge branch 'main' of github.com:modelscope/leapflow into feat/mhs
wangxingjun778 Nov 18, 2026
a95f2be
bump version
wangxingjun778 Nov 18, 2026
5c08f60
fix: supervise unregistered fleet nodes, explain leapd shutdowns, blo…
wangxingjun778 Nov 19, 2026
5ab1186
fix(daemon): separate backend RPC failures from connection loss, refu…
wangxingjun778 Nov 19, 2026
66b523c
feat(monitor): bounded critical-only delivery with durable incident i…
wangxingjun778 Nov 19, 2026
c20805d
ok Merge branch 'main' of github.com:modelscope/leapflow into feat/mhs
wangxingjun778 Nov 19, 2026
d151b8e
bump version
wangxingjun778 Nov 19, 2026
8a7d097
fix(engine): isolate guardrails and extend productive tool turns
wangxingjun778 Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/leapflow/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,7 @@ async def _archive_to_semantic(messages: List[Dict[str, Any]]) -> None:
max_consecutive_same=settings.guardrail_max_consecutive_same,
argument_scoped_tools=settings.guardrail_argument_scoped_tools,
max_calls_per_turn=settings.guardrail_max_calls_per_turn,
max_calls_per_turn_hard=settings.guardrail_max_calls_per_turn_hard,
)
logger.debug("Tool loop guardrails enabled")
else:
Expand Down
6 changes: 6 additions & 0 deletions src/leapflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ class Settings:
guardrail_stagnation_window: int = 10
guardrail_min_success_rate: float = 0.2
guardrail_max_calls_per_turn: int = 50
guardrail_max_calls_per_turn_hard: int = 150
guardrail_calls_extension_step: int = 25

# ── Session Persistence ──
session_persistence_enabled: bool = True
Expand Down Expand Up @@ -1704,6 +1706,8 @@ def _build_settings_from_env(
guardrail_stagnation_window = int(os.getenv("LEAPFLOW_GUARDRAIL_STAGNATION_WINDOW", "10"))
guardrail_min_success_rate = float(os.getenv("LEAPFLOW_GUARDRAIL_MIN_SUCCESS_RATE", "0.2"))
guardrail_max_calls_per_turn = int(os.getenv("LEAPFLOW_GUARDRAIL_MAX_CALLS_PER_TURN", "50"))
guardrail_max_calls_per_turn_hard = int(os.getenv("LEAPFLOW_GUARDRAIL_MAX_CALLS_PER_TURN_HARD", "150"))
guardrail_calls_extension_step = int(os.getenv("LEAPFLOW_GUARDRAIL_CALLS_EXTENSION_STEP", "25"))

# Session Persistence
session_persistence_enabled = _bool("LEAPFLOW_SESSION_PERSISTENCE_ENABLED", "true")
Expand Down Expand Up @@ -2229,6 +2233,8 @@ def _tuple_env(key: str, default: tuple) -> tuple:
guardrail_stagnation_window=guardrail_stagnation_window,
guardrail_min_success_rate=guardrail_min_success_rate,
guardrail_max_calls_per_turn=guardrail_max_calls_per_turn,
guardrail_max_calls_per_turn_hard=guardrail_max_calls_per_turn_hard,
guardrail_calls_extension_step=guardrail_calls_extension_step,
# Session Persistence
session_persistence_enabled=session_persistence_enabled,
session_resume_cache_policy=session_resume_cache_policy,
Expand Down
4 changes: 3 additions & 1 deletion src/leapflow/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ class ConfigSnapshot:
"guardrail.max_consecutive_same": "Consecutive uses of the same tool that trigger a diversify nudge (suppressed while progressing, so batch/sequential work is not penalized).",
"guardrail.stagnation_window": "Window of recent genuine tool results over which the low-success-rate stagnation warning is computed.",
"guardrail.min_success_rate": "Minimum tool success rate within the stagnation window before a stagnation warning is emitted.",
"guardrail.max_calls_per_turn": "Hard ceiling on total tool invocations in a single agent turn; exceeding it halts unconditionally regardless of progress.",
"guardrail.max_calls_per_turn": "Soft ceiling on total tool invocations in a single agent turn; productive windows extend it by calls_extension_step up to max_calls_per_turn_hard.",
"guardrail.max_calls_per_turn_hard": "Absolute turn tool-call ceiling; reaching it halts regardless of progress. Set equal to max_calls_per_turn to disable extensions; smaller values are clamped to the soft ceiling.",
"guardrail.calls_extension_step": "Additional tool calls granted per productive window while resource budgets allow continuation, bounded by max_calls_per_turn_hard.",
"tools.ripgrep_autoinstall": "Best-effort seamless ripgrep auto-install for code_search when missing (macOS/Homebrew, no sudo, background, non-fatal). code_search always works via the pure-Python fallback regardless; disabling this just skips the accelerator install and shows a manual hint.",
"tools.test_command": "Explicit command for the test_run tool (empty => auto-detect pytest/npm/go/cargo from project markers).",
"tools.lint_command": "Explicit command for the lint_check tool (empty => auto-detect ruff/eslint/go vet/clippy from project markers).",
Expand Down
42 changes: 35 additions & 7 deletions src/leapflow/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
wrappers. Behavior is progressively extracted into delegate components and
sub-packages; the remaining length is loop-iteration state shared across
those components, which resists further splitting without indirection that
costs more than it saves."""
costs more than it saves. Guardrail stop context is handed from that loop to
its existing tool-free finalization helpers; cap policy stays in tools/."""

from __future__ import annotations

Expand Down Expand Up @@ -246,6 +247,9 @@ def __init__(

# Tool loop guardrails (injected by CLI)
self._guardrail: Optional[Any] = None
# The guardrail violation that stopped the current turn, if any; read by
# the forced-finalize path so the user is told why and how to resume.
self._last_guardrail_halt: Optional[Any] = None

# Optional override for dynamic tool result budget (set by CLI wiring)
self._tool_result_budget: Optional[int] = None
Expand Down Expand Up @@ -2362,6 +2366,7 @@ async def _run_agent_loop(
break

if self._tool_dispatch._check_guardrail(messages) == "halt":
content = "" # A text tool request is not a final answer.
break

if status == BudgetStatus.SOFT_LIMIT and not self._should_extend_budget(
Expand Down Expand Up @@ -2417,7 +2422,10 @@ async def _run_agent_loop(
fallback = (
_app_onboarding_recovery_message(messages)
or _last_tool_failures_recovery_message(messages, include_generic=False)
or await self._synthesize_forced_answer(messages)
or await self._synthesize_forced_answer(
messages, stop_reason=getattr(self._last_guardrail_halt, "reason", None)
)
or (self._budget_exhausted_response(messages) if self._last_guardrail_halt else "")
or _last_tool_failures_recovery_message(messages)
or fatal_error
or self._budget_exhausted_response(messages)
Expand Down Expand Up @@ -2533,7 +2541,9 @@ async def _handle_llm_recovery(

# ── Helpers ──────────────────────────────────────────────────────────

async def _synthesize_forced_answer(self, messages: List[Dict[str, Any]]) -> str:
async def _synthesize_forced_answer(
self, messages: List[Dict[str, Any]], *, stop_reason: str | None = None
) -> str:
"""One tool-free LLM round to answer with what the turn already gathered.

A turn can stop before the model has written a final answer: a detected
Expand All @@ -2549,7 +2559,17 @@ async def _synthesize_forced_answer(self, messages: List[Dict[str, Any]]) -> str
"""
try:
prompt = list(messages)
prompt.append(build_user_message_text(_FORCED_FINALIZE_PROMPT))
finalize_prompt = _FORCED_FINALIZE_PROMPT
if stop_reason:
finalize_prompt += (
f"\nThis turn stopped because: {stop_reason}. "
"In the user's language, distinguish completed steps from steps not yet executed. "
"Explain that replying 'continue' resumes the remaining work in a new turn. "
"Do not claim the task is complete without evidence. "
"Completed or uncertain side effects must be verified before repeating actions; "
"continuation does not bypass existing safety or approval gates."
)
prompt.append(build_user_message_text(finalize_prompt))
compressed = self._prompt_assembler._prepare_llm_messages(
self._healer.heal(prompt), tools=None, round_number=0
)
Expand All @@ -2571,9 +2591,17 @@ def _budget_exhausted_response(self, messages: List[Dict[str, Any]]) -> str:
open-question count and next step so the stop is informative and
continuable (not a bare dead-stop); otherwise the plain notice.
"""
base = (
"I've reached my reasoning step limit. Here's my best answer based on progress so far."
)
halt = getattr(self, "_last_guardrail_halt", None)
if halt is not None:
base = (
f"This turn stopped: {halt.reason}. "
"Reply 'continue' to continue the remaining work in a new turn. "
"Completed or uncertain actions must be verified before they are repeated."
)
else:
base = (
"I've reached my reasoning step limit. Here's my best answer based on progress so far."
)
led = self._research_ledger
if led.is_empty or led.open_question_count == 0:
return base
Expand Down
1 change: 1 addition & 0 deletions src/leapflow/engine/prompt_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _begin_turn_context(self, user_text: str) -> None:
# reflect calls made in THIS turn, not the full session.
if self._engine._guardrail is not None:
self._engine._guardrail.reset()
self._engine._last_guardrail_halt = None
self._engine._current_command_id = self._engine._current_task_contract.task_id
self._engine._tool_execution_ledger.reset(store=self._engine._conversation_store)
try:
Expand Down
10 changes: 10 additions & 0 deletions src/leapflow/engine/session/session_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@ def build_session_engine(
engine._usage_tracker = TurnUsageTracker()
_wire_plugin_stats_sink(engine._usage_tracker)
engine._recovery_coordinator = RecoveryCoordinator()
# Guards hold per-turn baselines; a shared instance lets one session's turn
# start reset the tool-call count another session is enforcing.
_base_guardrail = getattr(base_engine, "_guardrail", None)
if _base_guardrail is not None:
if callable(getattr(_base_guardrail, "fresh", None)):
engine._guardrail = _base_guardrail.fresh()
else:
engine._guardrail = copy.deepcopy(_base_guardrail)
engine._guardrail.reset()
engine._last_guardrail_halt = None
engine._last_context_snapshot = {}
engine._last_turn_tool_categories = frozenset()
# Clean per-turn state slate (each turn also reassigns these, but a fresh
Expand Down
28 changes: 27 additions & 1 deletion src/leapflow/engine/tool_dispatch_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
Size note (>800-line registered exception per AGENTS.md): dispatch, catalog
assembly, side-effect batch gating, and guardrail evaluation share one
dispatch state machine; splitting them would fork the failure path the
gating exists to protect.
gating exists to protect. Productive turn-cap extension remains part of this
shared evaluation path, before its terminal verdict is handed to the loop.
"""

from __future__ import annotations
Expand Down Expand Up @@ -98,9 +99,12 @@ def _check_guardrail(
# trip, leaving a genuine no-op loop to spin until the budget is spent.
frame = self._engine._active_frame
stalled = bool(frame is not None and getattr(frame, "stalled_rounds", 0) >= 1)
if violation.severity == "halt" and self._try_extend_turn_cap(violation):
return None
if violation.severity == "halt" and (
getattr(violation, "progress_independent", False) or stalled
):
self._engine._last_guardrail_halt = violation
messages.append(
build_user_message_text(
f"SYSTEM GUARDRAIL: {violation.reason}. {violation.suggestion}"
Expand All @@ -113,6 +117,28 @@ def _check_guardrail(
build_user_message_text(f"SYSTEM WARNING: {violation.reason}. {violation.suggestion}")
)
return None

def _try_extend_turn_cap(self, violation: Any) -> bool:
"""Lift a productive soft turn-cap halt while resource budgets allow it.

Nothing is appended to the conversation: the extension is invisible to
the model, so the cached prompt prefix is unaffected.
"""
if not getattr(violation, "extendable", False):
return False
if not self._engine._within_resource_limits():
return False
extend = getattr(self._engine._guardrail, "extend_turn_cap", None)
if not callable(extend):
return False
settings = getattr(self._engine, "_settings", None)
step = int(getattr(settings, "guardrail_calls_extension_step", 25) or 25)
new_cap = extend(step)
if new_cap is None:
return False
logger.info("guardrail: turn tool-call cap extended to %d (progress-gated)", new_cap)
return True

def _evaluate_tool_failures(
self,
failed_items: List[tuple[str, Dict[str, Any]]],
Expand Down
Loading
Loading