Kiwi Code Docs

How Kiwi Code Works

The agentic loop — how Kiwi Code thinks, acts, and iterates to complete your tasks.

How Kiwi Code Works

When you send a message to Kiwi Code, the AI doesn't just generate text — it enters an agentic loop where it thinks, uses tools, observes results, and repeats until your task is done.

The Agentic Loop

Every interaction follows this cycle:

  You send a message


  ┌─────────────┐
  │  AI Thinks   │ ← Analyzes your request + context
  └──────┬───────┘


  ┌─────────────┐     ┌──────────────────┐
  │  Tool Call?  │────→│  Execute Tool     │
  │  (yes/no)   │     │  (on your machine │
  └──────┬───────┘     │   or in cloud)    │
         │             └────────┬──────────┘
         │                      │
         │              ┌───────▼──────────┐
         │              │  Observe Result   │
         │              │  (feed back to AI)│
         │              └───────┬──────────┘
         │                      │
         │               ┌──────▼──────┐
         │               │  Loop Again  │──→ back to "AI Thinks"
         │               └─────────────┘

         ▼ (no more tool calls)
  ┌─────────────┐
  │  Response    │ ← Final answer streamed to you
  └─────────────┘

The AI keeps looping — thinking, calling tools, observing results — until it has enough information to give you a complete answer or has finished making all the changes you asked for.

A Real Example

When you ask "Add input validation to the User model", here's what happens:

Think

The AI reads your message and decides it needs to see the current code first.

Act — Read the file

Tool call: read file src/models/user.py

The runtime reads the file on your machine and sends the contents back.

Observe

The AI sees the current User model code and plans the changes.

Act — Edit the file

Tool call: write file src/models/user.py with the updated code including validation.

Act — Run tests

Tool call: run command pytest tests/test_user.py

The runtime executes the tests on your machine.

Observe

Tests pass. The AI is satisfied the changes work.

Respond

The AI explains what it changed and why. Loop ends.

This entire sequence — 3 tool calls, multiple think-observe cycles — happens automatically from a single message.

Tools the AI Can Use

Each iteration of the loop, the AI can call any of these tools on your machine through the runtime:

ToolWhat it does
Run commandsExecute any shell command — build, test, lint, install packages
Read filesRead file contents, search within files, list directories
Write filesCreate, edit, or delete files — apply diffs, find-and-replace
Search codeGrep across your codebase with pattern matching
Web searchSearch the web for documentation, examples, or solutions
Fetch URLsRead web pages, API docs, or online resources

Tools are automatic

You don't need to tell the AI which tools to use. It decides based on your request — ask it to "fix the tests" and it will read the test file, run the tests, read the errors, edit the code, and re-run until they pass.

Loop Limits

The AI doesn't loop forever. Built-in limits keep things under control:

LimitValue
Max iterations20 per message (50 for coding tasks)
Command timeoutUp to 600 seconds per command
Response timeout15 minutes per AI call

If the AI hits the iteration limit, it stops and tells you what it accomplished and what's left to do. You can continue by sending another message.

Real-Time Updates

While the loop runs, you see live updates in the TUI:

  • "Thinking" — the AI is processing
  • "Executing" — a tool is running on your machine
  • "Streaming" — the AI's response is being generated

Open the runtime logs (Ctrl+O) to see exactly which commands are being executed.

How It Differs by Agent

All agents use the same agentic loop, but with different AI models:

  • Deep Thinker agents spend more time in the "Think" phase — better for hard problems
  • Flash agents think faster — better for simple tasks
  • Standard agents balance speed and depth

The tools and loop mechanics are identical across all agents.

On this page