Skip to main content
Agents are non-deterministic, so testing them starts with exercising behavior, not writing a perfect assertion. The fastest loop is often to have your coding agent prompt the Keystroke agent through the CLI, try realistic scenarios, inspect the resulting sessions, and iterate on the system instructions and tools. Test agents at the boundary you care about: Start qualitatively, then turn the stable contracts you discover into tests. Automated tests are best for definition shape, required tool calls, and a small number of critical prompt paths. Run tests from the project root:
Vitest ships with @keystrokehq/cli. No project vitest.config.ts is required.

Qualitative tests

Before writing test files, run the agent the way you expect people to use it. Ask your coding agent to call the Keystroke CLI with a batch of prompts, inspect the sessions, and report where the agent misunderstood instructions, skipped tools, or used tools incorrectly.
--wait returns each completed session for review. For long prompts, choose a bounded wait with --timeout <seconds> and continue with agents sessions get <agent> <session-id> --wait if the session is still running. Good qualitative prompts cover:
  • Normal requests the agent should handle cleanly.
  • Tool-required requests where the agent must call an action, workflow, MCP tool, or subagent.
  • Missing-information cases where the agent should ask a clarifying question instead of guessing.
  • Follow-up messages in the same session.
  • Edge cases that should be refused, escalated, or handled cautiously.
Then inspect the session — start with a summary, then request richer detail if needed:
Use this loop to tune the system prompt, tools, skills, files, and model choice. Once the behavior feels right, write focused tests for the parts that should not regress.

Definition tests

Definition tests are fast and do not need provider keys.
Use this style to catch accidental model changes, missing tools, or prompt edits that remove required instructions.

Smoke-tests

The init template includes an agent integration test shaped like this:
The provider-key guard keeps local and CI runs from failing when real model credentials are not available. Match the guard to the agent’s model (or use AI_GATEWAY_API_KEY, which works for any catalog id). Run integration tests from the project root:
Integration tests load .env when present and skip when required keys (like AI_GATEWAY_API_KEY) are unset. Vitest and its config ship with @keystrokehq/cli — no project vitest.config.ts.

Tool use tests

When a tool call is the contract, assert on the recorded messages rather than only the final answer.
Keep the prompt narrow. Tests that ask for broad natural-language behavior are more likely to be flaky than tests that assert a specific tool contract.

Sessions and memory

Prompt tests create sessions. If a test should be repeatable, use a fresh session or disable memory on the agent under test:
If you need a multi-turn test, keep the returned sessionId and pass it to the next prompt:

Failure inspection

When a prompt test fails, inspect the session before changing code:
For deployed agents, use History in the web app and filter to agent runs. The detail panel shows messages, tool calls, metadata, and trace data.

Next steps

Run agents

Prompt agents locally and inspect sessions from the CLI.

Agent runs

Debug failed sessions in the web app.

Actions as tools

Build deterministic tool contracts that are easier to test.

Deploy a project

Run tests before deploying changed agents.