Skip to content

Commit 70dd457

Browse files
Phase 17: Affordable Model Optimization
1 parent 5854316 commit 70dd457

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

.mythic/memory.sqlite

0 Bytes
Binary file not shown.

mythic/ai/provider_calls.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
{"routing_attempt": true, "from_provider": "copy-paste", "to_provider": "copy-paste", "role": "Companion Shell", "task_type": "conversation", "packet_id": "shell", "succeeded": true, "error": "", "skipped_reason": ""}
88
{"routing_attempt": true, "from_provider": "copy-paste", "to_provider": "copy-paste", "role": "Companion Shell", "task_type": "conversation", "packet_id": "shell", "succeeded": true, "error": "", "skipped_reason": ""}
99
{"routing_attempt": true, "from_provider": "copy-paste", "to_provider": "copy-paste", "role": "Companion Shell", "task_type": "conversation", "packet_id": "shell", "succeeded": true, "error": "", "skipped_reason": ""}
10+
{"routing_attempt": true, "from_provider": "copy-paste", "to_provider": "copy-paste", "role": "Companion Shell", "task_type": "conversation", "packet_id": "shell", "succeeded": true, "error": "", "skipped_reason": ""}

mythic_vibe_cli/repl.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ def _known_command_names(_main: Callable[[list[str]], int]) -> set[str]:
371371
- Always use `workspace diff` to review your own changes before making a commit.
372372
- You must ask the user for explicit confirmation before executing `workspace commit` or `workspace push`.
373373
374+
Formatting & Efficiency:
375+
- When writing code changes, use minimal patching tools if available, or print only the modified snippets with context instead of re-dumping entire files. Be extremely concise.
376+
374377
Always use your tools when you need to read files, run tests, or modify code.
375378
When the user asks you a question or gives you a task, you can invoke multiple tools in sequence.
376379
Once you have accomplished the goal, provide a conversational summary to the user.
@@ -440,10 +443,20 @@ def _answer_with_selected_model(prompt: str, stdout: IO[str], context: ShellCont
440443
providers = ProviderRegistry(root=context.project_root).providers()
441444

442445
MAX_ITERATIONS = 10
446+
MAX_RETRIES = 3
447+
MAX_HISTORY_LEN = 20
448+
MAX_TOOL_OUTPUT_LEN = 2000
449+
443450
final_content = ""
444451
lines: list[str] = []
452+
consecutive_errors = 0
445453

446454
for iteration in range(MAX_ITERATIONS):
455+
# Prune history if it gets too long
456+
if len(history) > MAX_HISTORY_LEN:
457+
# keep the first two (could be initial prompt and first reply) and the last N
458+
history = history[:2] + history[-(MAX_HISTORY_LEN - 2):]
459+
447460
packet = {
448461
"text": prompt if iteration == 0 else "Continue with the next step or provide your final answer.",
449462
"packet_id": "shell",
@@ -474,10 +487,17 @@ def _answer_with_selected_model(prompt: str, stdout: IO[str], context: ShellCont
474487
root=context.project_root,
475488
dry_run=False,
476489
)
490+
consecutive_errors = 0 # Reset on success
477491
except Exception as exc: # noqa: BLE001
478-
rendered = f"Model call failed: {exc}"
479-
print(rendered, file=stdout)
480-
return rendered
492+
consecutive_errors += 1
493+
if consecutive_errors >= MAX_RETRIES:
494+
rendered = f"Model call failed after {MAX_RETRIES} retries: {exc}"
495+
print(rendered, file=stdout)
496+
return rendered
497+
else:
498+
print(f" [Model call failed: {exc}. Retrying...]", file=stdout)
499+
history.append({"role": "user", "content": f"System error communicating with model: {exc}. Please try again."})
500+
continue
481501

482502
response = result.response
483503
if result.fell_back and iteration == 0:
@@ -504,17 +524,24 @@ def _answer_with_selected_model(prompt: str, stdout: IO[str], context: ShellCont
504524
try:
505525
import json
506526
args = json.loads(args_str)
507-
except Exception:
508-
args = {}
527+
except Exception as exc:
528+
print(f" [Failed to parse arguments for {tool_name}]", file=stdout)
529+
history.append({"role": "user", "content": f"Failed to parse tool arguments for {tool_name} as JSON: {exc}. Please fix the formatting."})
530+
continue
509531

510532
print(f" [Executing {tool_name}...]", file=stdout)
511533
try:
512534
tool_output = execute_tool(tool_name, args)
513535
except Exception as exc:
514536
tool_output = f"Tool execution error: {exc}"
515537

538+
# Truncate large tool outputs
539+
tool_output_str = str(tool_output)
540+
if len(tool_output_str) > MAX_TOOL_OUTPUT_LEN:
541+
tool_output_str = tool_output_str[:MAX_TOOL_OUTPUT_LEN] + f"\n... [Truncated for brevity. Original length: {len(str(tool_output))} chars]"
542+
516543
# We append tool output to history as 'user' role so the LLM sees it
517-
history.append({"role": "user", "content": f"Tool {tool_name} returned:\n{tool_output}"})
544+
history.append({"role": "user", "content": f"Tool {tool_name} returned:\n{tool_output_str}"})
518545

519546
# Loop again!
520547
continue

0 commit comments

Comments
 (0)