Skip to main content

Agent Mode

Agent Mode outputs structured NDJSON instead of the interactive terminal UI. It's how AI coding agents (Claude Code, Codex CLI, Gemini CLI) consume Kane CLI results: parse events programmatically, extract the final result, and present it to the user.

Enable Agent Mode

Add --agent to any run command:

kane-cli run "Verify the checkout flow completes successfully" \
--url https://myapp.com \
--agent \
--headless

When --agent is active:

  • The interactive TUI is fully suppressed (no boot screen, no menus)
  • Stdin is not used (no interactive prompts)
tip

Always combine --agent with --headless in non-interactive environments (CI/CD, agent contexts) to avoid display server errors.


Output Format

Kane CLI outputs one JSON object per line (NDJSON) to stdout:

{"type":"run_start","objective":"Verify checkout","timestamp":"2026-04-14T10:30:45Z"}
{"type":"step_start","index":0,"objective":"Navigate to cart page"}
{"type":"step_event","index":0,"event":"action","detail":"Navigated to /cart","success":true}
{"type":"step_event","index":0,"event":"screenshot","detail":"Screenshot captured"}
{"type":"step_end","index":0,"status":"passed","duration":2.3,"summary":"Navigated to cart"}
{"type":"step_start","index":1,"objective":"Click checkout button"}
...
{"type":"run_end","status":"passed","summary":"...","duration":45.2,...}

Event Schema

Step Events

TypeKey FieldsDescription
step_startindex, objective, child_id*Step began
step_eventindex, event**, detail, success*Activity within a step
step_endindex, status (passed|failed), duration, summaryStep completed

*optional
**event values: screenshot, reasoning, action, vision, assertion, evaluation

Flow Events

TypeKey FieldsDescription
run_startobjective, timestampRun started
bifurcationflows[], countAgent branched into sub-flows
child_agent_startchild_id, objective, parent_stepChild agent spawned
child_agent_endchild_id, success, steps_taken, summaryChild agent finished
ask_userquestion, step_index, options*Agent needs input (auto-disabled when stdin is not TTY)
errormessageError occurred
run_end(see below)Terminal event: always the last line

The run_end Event

run_end is always the last line. It contains the complete test result:

{
"type": "run_end",
"status": "passed",
"summary": "Searched for laptop and added first result to cart",
"one_liner": "Searched for laptop on Amazon and added to cart",
"reason": "Objective completed",
"duration": 45.2,
"final_state": {
"price": "$29.99",
"product_name": "Wireless Headphones"
},
"context": {
"memory": {},
"variables": {},
"pointer": "(passed) Searched for laptop on Amazon"
},
"token_usage": {
"reasoning_input": 12000,
"reasoning_output": 800,
"vision_input": 5000,
"vision_output": 200
},
"session_dir": "~/.testmuai/kaneai/sessions/2026-04-14_10-30-45_a1b2c3",
"run_dir": "~/.testmuai/kaneai/sessions/2026-04-14_10-30-45_a1b2c3/runs/0",
"test_url": "https://test-manager.lambdatest.com/projects/123/test-cases/456"
}

Key Fields

FieldDescription
status"passed" or "failed"
summaryFull description of what the agent did
one_linerShort single-sentence summary
reasonWhy the run stopped (present on failure)
final_stateValues extracted via "store as" objectives
test_urlLink to the TestMu AI dashboard for this run
session_dirPath to session-level logs
run_dirPath to run-level logs, step JSON, screenshots
token_usageToken consumption breakdown

Parsing Output

Get the run_end event:

# Get just the final result
kane-cli run "..." --agent 2>/dev/null | tail -1 | jq .

# Extract status
kane-cli run "..." --agent 2>/dev/null | tail -1 | jq -r '.status'

# Extract a stored value
kane-cli run "go to example.com, store the price as 'price'" --agent 2>/dev/null \
| tail -1 | jq -r '.final_state.price'

Handling ask_user Events

If an objective requires user input mid-run, Kane CLI fires ask_user:

{"type": "ask_user", "question": "Which item should I select?", "options": ["Small", "Medium", "Large"]}
note

ask_user is auto-disabled when stdin is not a TTY. In CI/CD and AI agent contexts, stdin is never a TTY, so ask_user never fires. Write objectives that don't require interactive prompts.

If stdin IS a TTY, respond by writing JSON to stdin:

{"type": "user_response", "answer": "Medium"}

To cancel:

{"type": "cancel"}

Agent Mode vs Interactive Mode

Agent Mode (--agent)Interactive Mode
TUISuppressedFull terminal UI
OutputNDJSON to stdoutFormatted text
StderrLogs onlyLogs + progress UI
Use caseAI agents, programmatic toolsHuman development

Next Steps

  • Error Codes: Complete reference of result_code values and recommended actions
  • Parallel Execution: Run multiple tests concurrently
  • Skills: Install the Kane CLI skill for Claude, Codex, or Gemini
  • CLI Reference: Full flag and command reference

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles