fix(copilot): make the step budget real, configurable and visible

The graph passed remaining_steps=20 (50 for injection) in the run inputs.
RemainingSteps is a LangGraph managed value derived from recursion_limit,
so the input was ignored and the real budget was 25 (100 for injection).
No one could see those numbers, and a turn that hit the cap ended on a
bare tool result with no explanation.

- Remove the dead remaining_steps input.
- Add resolve_recursion_limit(): max_steps from the LLM model config wins;
  otherwise 25 teaching_assistant, 50 lab_automation_assistant, 100
  troubleshooting_injection.
- When fewer than 4 steps remain after a tool run, route to the new
  budget_wrapup node. The next llm_call binds no tools and gets a wrap-up
  instruction, so the turn ends with a short summary of what was done and
  what remains.
- should_continue skips the title call after a wrap-up (no step left).
- budget_exhausted is reset at the start of every user turn.
- Add max_steps to the LLM config schemas. The config is a JSON column,
  so no migration is needed.
- Tests: 16 new tests cover the resolver, the routing, the tool-free
  wrap-up call and the removed input. Docs updated.
This commit is contained in:
YueGuobin committed 2026-11-03 23:16:26 +08:00
1 parent e8462507a5
commit 5a294461e8
6 files changed
+282 -37

No files matched your search

+4 -3
View File
@@ -821,15 +821,16 @@ OpenAI-compatible message model.
3. First interaction without title → `title_generator_node`
4. Otherwise → `END`
- **recursion_limit_continue** (after `tool_node`): Routes to `llm_call` or `END` based on:
- **recursion_limit_continue** (after `tool_node`): Routes to `llm_call`, `budget_wrapup` or `END` based on:
1. Check abort flag → `END`
2. Remaining steps < 4 → `END` (prevent infinite loops)
2. Remaining steps < 4 → `budget_wrapup` (one final summary call, no tools)
3. Otherwise → `llm_call`
**State** (`MessagesState`):
- `messages`: Conversation messages (cumulative with `operator.add`)
- `llm_calls`: LLM invocation counter
- `remaining_steps`: Recursion depth tracker (initial: 20)
- `remaining_steps`: LangGraph managed value (`recursion_limit - step`); the limit is the per-mode default or `max_steps` from the LLM config. Passing it in inputs has no effect
- `budget_exhausted`: Set by `budget_wrapup`, reset at the start of every user turn
- `conversation_title`: Auto-generated title
- `topology_info`: GNS3 project topology data
- `session_id`: Session identifier (for abort tracking)
@@ -225,6 +225,7 @@ For a complete list of LangChain-supported providers, see: https://python.langch
| `max_tokens` | integer | **⚠️ Reserved for future use, not currently implemented** |
| `context_strategy` | string | Context trimming strategy: "conservative" (60%), "balanced" (75%), "aggressive" (85%). Default: "balanced" |
| `copilot_mode` | string | GNS3-Copilot mode: "teaching_assistant" (diagnostics only, default) or "lab_automation_assistant" (full configuration access) |
| `max_steps` | integer | Step budget of one copilot turn, as the LangGraph recursion limit (1 LLM call + 1 tool run = 2 steps). Defaults: 25 teaching_assistant, 50 lab_automation_assistant, 100 troubleshooting_injection |
| `is_default` | boolean | Set as default (default: false) |
**Important Notes:**
@@ -253,6 +254,7 @@ For a complete list of LangChain-supported providers, see: https://python.langch
| `context_strategy` | string (optional) | Context trimming strategy |
| `is_default` | boolean (optional) | Default flag |
| `copilot_mode` | string (optional) | GNS3-Copilot mode: "teaching_assistant" or "lab_automation_assistant" |
| `max_steps` | integer (optional) | Step budget of one copilot turn (LangGraph recursion limit). Leave empty for the per-mode default |
| `expected_version` | integer (optional) | **Optimistic locking version** |
**Note:** When using `expected_version`, the API will verify the version hasn't changed since you read the data. If it has, you'll receive a 409 Conflict error.
@@ -261,7 +263,7 @@ For a complete list of LangChain-supported providers, see: https://python.langch
- `max_tokens`: Reserved for future implementation. Currently not used by the system. The maximum output tokens are controlled automatically by the LLM provider based on the model and input size.
**Update Limitations:**
- `context_strategy` and `copilot_mode` can be set to new values but **cannot be cleared to null** via update. This is because the API filters out null values before processing.
- `context_strategy`, `copilot_mode` and `max_steps` can be set to new values but **cannot be cleared to null** via update. This is because the API filters out null values before processing.
### LLMModelConfigResponse