Skip to content

Comments

feat: add --agent mode flag#1618

Merged
KRRT7 merged 8 commits intomainfrom
agent-mode-flag
Feb 20, 2026
Merged

feat: add --agent mode flag#1618
KRRT7 merged 8 commits intomainfrom
agent-mode-flag

Conversation

@KRRT7
Copy link
Collaborator

@KRRT7 KRRT7 commented Feb 20, 2026

Summary

  • Adds --agent CLI flag for Claude / agents: suppresses Rich UI, emits plain-text/XML output, skips checkpoint and concolic tests, implies --no-pr and --worktree.

Add --agent CLI flag for AI agent integrations that skips all
interactive prompts. In agent mode, checkpoint resume is skipped
entirely so each run starts fresh. Also gates the existing checkpoint
prompt behind --yes.
In agent mode, disable all Rich output (panels, spinners, progress bars,
syntax highlighting) and use a plain StreamHandler for logging. Optimization
results with explanation and unified diff are written to stdout. A log
filter strips LSP prefixes and drops noisy test/file-path messages.
Also skip checkpoint creation and suppress Python warnings in agent mode.
…oncolic tests

- --agent now implies --no-pr and --worktree so source files stay clean
- Output uses structured XML (codeflash-optimization) with optimized-code
  for the consuming agent to apply via Edit/Write
- Skip concolic test generation in agent mode
- Skip patch file creation in worktree + agent mode
@KRRT7 KRRT7 requested a review from aseembits93 February 20, 2026 20:19
@misrasaurabh1
Copy link
Contributor

why dont you use the word --subagent? agent mode within codeflash means something else

)

if is_agent_mode():
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The is_agent_mode() early return is placed after all the computation (building the summary string, counting callees, etc.). Consider moving this check to the top of the function, alongside the if not total_functions: return guard, to avoid wasted work in agent mode.

Suggested change
return
if is_agent_mode():
return
if is_LSP_enabled():

Comment on lines 2216 to 2227
if is_agent_mode():
agent_log_optimization_result(
function_name=new_explanation.function_name,
file_path=new_explanation.file_path,
perf_improvement_line=new_explanation.perf_improvement_line,
original_runtime_ns=new_explanation.original_runtime_ns,
best_runtime_ns=new_explanation.best_runtime_ns,
raw_explanation=new_explanation.raw_explanation_message,
original_code=original_code_combined,
new_code=new_code_combined,
review=opt_review_result.review,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: When is_agent_mode() is true, the function writes the XML result to stdout and then falls through to the raise_pr / staging_review logic below. Since --agent implies --no-pr, the PR logic is skipped in practice. But if a future change decouples --agent from --no-pr, this could lead to both an XML output and a PR being created. Consider adding an explicit return or a comment documenting this dependency.

@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Feb 20, 2026

⚡️ Codeflash found optimizations for this PR

📄 71% (0.71x) speedup for code_print in codeflash/cli_cmds/console.py

⏱️ Runtime : 796 milliseconds 465 milliseconds (best of 8 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch agent-mode-flag).

Static Badge

@claude
Copy link
Contributor

claude bot commented Feb 20, 2026

PR Review Summary

Prek Checks

Passed after auto-fix. One formatting issue in codeflash/cli_cmds/logging_config.py was auto-fixed by ruff (multi-line args collapsed to single line). Fix committed and pushed.

Mypy: 189 errors found across changed files, but all are pre-existing (primarily self.args being Namespace | None union-attr issues and Rich library typing mismatches). No new type errors introduced by this PR.

Code Review

No critical bugs or security issues found. Two minor observations left as inline comments:

  1. console.py:390call_graph_summary performs full computation before the is_agent_mode() early return. The check should be moved earlier to avoid wasted work.
  2. function_optimizer.py:2216-2227 — In agent mode, XML result is written to stdout but execution continues into the raise_pr / staging_review logic. Currently safe because --agent implies --no-pr, but fragile if decoupled later.

Overall: The implementation is well-structured. The pattern of setting CODEFLASH_AGENT_MODE env var early in main.py before imports, then using the lru_cache-backed is_agent_mode() check throughout, is clean. The new agent-mode code mirrors the existing LSP mode pattern consistently.

Test Coverage

File Coverage Missed Lines
codeflash/cli_cmds/cli.py 38.6% 151
codeflash/cli_cmds/console.py 20.7% 192
codeflash/cli_cmds/logging_config.py 19.0% 17
codeflash/code_utils/checkpoint.py 85.5% 12
codeflash/lsp/helpers.py 40.4% 28
codeflash/optimization/function_optimizer.py 18.5% 956
codeflash/optimization/optimizer.py 19.1% 365
Overall (all files) 78.4%

Analysis: No new files were added — all changes modify existing files. The new agent-mode code paths (console suppression, XML output, concolic test skip) are not covered by unit tests, which matches the existing pattern for LSP-mode paths in the same files. The overall suite coverage (78.4%) is unaffected. Test failures (8 in test_tracer.py) are pre-existing and unrelated to this PR.


Last updated: 2026-02-20

Rename the CLI flag, env var (CODEFLASH_SUBAGENT_MODE), helper
(is_subagent_mode), and related symbols to avoid confusion with
CodeFlash's own agent terminology.
Avoids computing the full summary (callee counts, string formatting)
only to discard it when running in subagent mode.
Include a <verification> block with per-test-type pass/fail counts
in the XML emitted by subagent_log_optimization_result, matching
the correctness table shown in GitHub PR comments.
@KRRT7 KRRT7 merged commit e4a2844 into main Feb 20, 2026
25 of 28 checks passed
@KRRT7 KRRT7 deleted the agent-mode-flag branch February 20, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants