Skip to content

Tools

KosmoKrator ships with a full suite of built-in tools that the agent uses to read, write, search, and execute code. This page is the complete reference for every tool, its parameters, and typical usage patterns.

Tools requiring approval (file_write, file_edit, apply_patch, bash, shell_start, shell_write, and execute_lua) depend on your permission mode. In Prometheus mode governed prompts are auto-approved, but blocked paths and explicit deny rules are still enforced.

Read a file from the project with line numbers. Supports partial reads via offset/limit and includes an automatic caching layer: if a file has not changed since the last read, the tool returns [Unchanged since last file_read of path (lines X-Y); content omitted to save tokens] instead of re-sending the full contents. Files larger than 10 MB are streamed line-by-line to avoid memory pressure.

ParameterTypeRequiredDescription
pathstringYesAbsolute or project-relative path to the file.
offsetintNoLine number to start reading from (1-based). Omit to start from the beginning.
limitintNoMaximum number of lines to return. Omit to read the entire file.

Example: Read lines 50–80 of a controller:

Terminal window
file_read path="src/Controller/UserController.php" offset=50 limit=30

When the agent is exploring a large file it will often use offset and limit to read only the relevant section, keeping the context window lean.

Create a new file or completely overwrite an existing one. Any missing parent directories are created automatically. Returns the total line count of the written file.

ParameterTypeRequiredDescription
pathstringYesAbsolute or project-relative path for the file.
contentstringYesThe full content to write.

Example: Create a new configuration file:

Terminal window
file_write path="config/cache.yaml" content="cache:\n driver: redis\n ttl: 3600\n"

Perform a targeted find-and-replace within a file. The old_string must appear exactly once in the file; if it matches zero or more than one location the edit is rejected. Returns the edit summary with separate removed and added line counts (e.g., "Edited path (-5, +3 lines)").

ParameterTypeRequiredDescription
pathstringYesPath to the file to edit.
old_stringstringYesThe exact text to find. Must match exactly once.
new_stringstringYesThe replacement text.

Example: Rename a method call:

Terminal window
file_edit path="src/Service/Mailer.php" \
old_string="$this->sendLegacy($message)" \
new_string="$this->send($message)"

The agent prefers file_edit over file_write for surgical changes because it only transmits the diff, keeping token usage low and making approval review easier.

Apply a structured patch to one or more files. Uses KosmoKrator’s custom patch format with *** Begin Patch / *** End Patch delimiters and file-level markers: *** Add File:, *** Update File:, and *** Delete File:. Supports multi-file, multi-hunk patches. The parser streams the patch content for memory efficiency, making it suitable for large changesets.

ParameterTypeRequiredDescription
patchstringYesThe patch content using *** Begin Patch / *** End Patch format.

Example: Apply a multi-file patch:

Terminal window
apply_patch patch="*** Begin Patch
*** Update File: src/Model/User.php
@@ -12,6 +12,7 @@ class User
public string $name;
public string $email;
+ public ?string $avatar = null;
public function __construct(string $name)
*** Update File: tests/UserTest.php
@@ -8,4 +8,10 @@ class UserTest extends TestCase
{
$this->assertInstanceOf(User::class, new User('Ada'));
}
+
+ public function test_avatar_defaults_to_null(): void
+ {
+ $user = new User('Ada');
+ $this->assertNull($user->avatar);
+ }
}
*** End Patch"

Fast file-name pattern matching across the project tree. Automatically skips common non-project directories (.git, vendor, node_modules). Returns up to 200 matching file paths, sorted by name.

ParameterTypeRequiredDescription
patternstringYesGlob pattern to match (e.g. **/*.php, src/Model/*.php).
pathstringNoBase directory to search from. Defaults to the project root.

Example: Find all migration files:

Terminal window
glob pattern="database/migrations/*.php"

Regex-powered content search. Uses ripgrep when available on the system for maximum speed; falls back to GNU grep otherwise. Returns up to 50 matches per file, capped at 100 output lines, each with file path and line number.

ParameterTypeRequiredDescription
patternstringYesRegular expression pattern to search for.
pathstringNoFile or directory to search in. Defaults to the project root.
globstringNoFile name filter (e.g. *.php, *.ts).

Example: Find all usages of a deprecated method in PHP files:

Terminal window
grep pattern="->sendLegacy\(" glob="*.php"

The agent typically combines glob and grep in sequence: first glob to discover which files exist, then grep to find specific patterns inside them.

KosmoKrator keeps native web_fetch separate from optional external web providers. External search, extract, and crawl tools are disabled by default and only run after you enable the related web.* settings or configure a provider with web:configure.

Search the web through Tavily, Firecrawl, Exa, Brave Search, Parallel, Jina, SearXNG, Perplexity, OpenAI native web search, or Anthropic native web search.

ParameterTypeRequiredDescription
querystringYesSearch query.
providerenumNoOverride web.search.provider.
max_resultsintNoDefaults to web.search.max_results.
modeenumNoProvider hint such as fast, deep, cached, or live.
allowed_domains, blocked_domainsarrayNoDomain filters when supported.
Terminal window
web_search query="Symfony TUI latest release" provider="tavily" max_results=5

Fetch or extract a specific URL through an external provider. This does not replace native web_fetch; native fetch remains the default for providers that expose it directly. External fetch is approval-gated by default.

ParameterTypeRequiredDescription
urlstringYesURL to fetch.
providerenumNoOverride web.fetch.provider.
formatenumNomarkdown, text, or html.
Terminal window
web_fetch_external url="https://symfony.com/blog/" provider="firecrawl" format="markdown"

Crawl multiple pages from a site with Tavily or Firecrawl. Crawling is disabled by default and approval-gated because it can expand one user request into many external fetches.

ParameterTypeRequiredDescription
urlstringYesStarting URL.
providerenumNoOverride web.crawl.provider.
max_pagesintNoDefaults to web.crawl.max_pages.
instructionsstringNoOptional provider-specific crawl instructions.
Terminal window
web_crawl url="https://docs.example.com" provider="tavily" max_pages=10

Execute a shell command in the project directory. Output (combined stdout and stderr) is streamed via a progress callback so the UI can display it in real time. The result includes the full output text and the process exit code.

ParameterTypeRequiredDescription
commandstringYesThe shell command to execute.
timeoutintNoMaximum execution time in seconds. Default: 120. Maximum: 7200 (2 hours).

Example: Run the test suite with a generous timeout:

Terminal window
bash command="php vendor/bin/phpunit --testdox" timeout=300

Interactive persistent shell sessions allow the agent to start long-running processes (dev servers, watchers, REPLs) and interact with them over time. Each session gets a unique ID and persists until explicitly killed or the agent session ends.

Start a new interactive shell session.

ParameterTypeRequiredDescription
commandstringYesThe command to start (e.g. php artisan tinker, npm run dev).
cwdstringNoWorking directory for the session. Defaults to the project root.
timeoutintNoInactivity timeout in seconds before the session is auto-terminated.
wait_msintNoMilliseconds to wait for initial output after starting.

Send input to a running shell session.

ParameterTypeRequiredDescription
session_idstringYesThe session ID returned by shell_start.
inputstringYesThe text to send to the session’s stdin.
submitbooleanNoWhether to append a newline after the input. Defaults to true.
wait_msintNoMilliseconds to wait for output after writing.

Read buffered output from a running shell session.

ParameterTypeRequiredDescription
session_idstringYesThe session ID.
wait_msintNoMilliseconds to wait for new output before returning.

Terminate a running shell session.

ParameterTypeRequiredDescription
session_idstringYesThe session ID to terminate.

Example: Start a dev server, verify it boots, then tear it down:

Terminal window
# Start the server
shell_start command="php artisan serve --port=8080" wait_ms=2000
# Returns: { session_id: "sess_abc123", output: "Starting development server..." }
# Check that it is responding
shell_read session_id="sess_abc123" wait_ms=1000
# Shut it down when done
shell_kill session_id="sess_abc123"

Spawn a child agent that runs in its own context window. Subagents inherit the project’s tool set and permission mode but operate independently. They can run in the foreground (await) or background, form dependency chains, and be grouped for batch execution. See Agents for the full subagent architecture guide.

ParameterTypeRequiredDescription
taskstringNoNatural-language description of what the subagent should accomplish.
typestringNoAgent type: general (full tool access, default), explore (read-only tools), or plan (no tools, planning only).
modestringNoawait (block until complete, default) or background (run concurrently).
idstringNoCustom identifier for referencing in dependency chains.
depends_onarrayNoList of subagent IDs that must complete before this one starts.
groupstringNoSequential execution group — agents in the same group run one at a time.
agentsarrayNoBatch mode: array of agent specs to run concurrently. Each spec is an object with task (required), type, id, depends_on, and group. When set, the top-level task, type, id, depends_on, and group parameters are ignored.

Example: Fan out three explore agents, then merge their findings:

Terminal window
# Phase 1: parallel exploration
subagent task="Map the authentication flow" type="explore" mode="background" id="auth"
subagent task="Map the payment flow" type="explore" mode="background" id="pay"
subagent task="Map the notification flow" type="explore" mode="background" id="notify"
# Phase 2: plan based on all three
subagent task="Design a unified event system based on the auth, payment, and notification flows" \
type="plan" mode="await" depends_on=["auth","pay","notify"]

Persist a piece of knowledge to the memory store so it survives across sessions. Memories are stored as Markdown files and can be scoped to the project, the user, or tagged as architectural decisions.

ParameterTypeRequiredDescription
typestringYesMemory scope: project (codebase facts, architecture), user (preferences, workflow), or decision (architectural choices, trade-offs).
titlestringYesShort descriptive title for the memory.
contentstringYesMarkdown content — the knowledge to persist.
classstringNoMemory class: priority, working, or durable (default).
pinnedbooleanNoWhether the memory should be favored during recall.
expires_daysnumberNoOptional expiry in days — useful for working memory.
idstringNoExisting memory ID to update. Omit to create a new memory.

Example: Record an architectural decision:

Terminal window
memory_save type="decision" \
title="Use event sourcing for orders" \
content="## Context\nOrder history is critical for auditing.\n\n## Decision\nAll order mutations go through an event store."

Search and list saved memories. Use to recall project facts, user preferences, or past decisions before asking the user. Returns ranked results with title, type, and content preview.

ParameterTypeRequiredDescription
querystringNoText to search for in memory titles and content.
typestringNoFilter by memory type: project, user, decision, or compaction.
classstringNoFilter by memory class: priority, working, or durable.
scopestringNoSearch scope: memories (default), history, or both.

Example: Recall a previous decision about caching:

Terminal window
memory_search query="caching strategy"

Session tools let the agent browse and search prior KosmoKrator conversations for the current project. They are useful when a user refers to earlier work, asks what happened last time, or wants the agent to reuse decisions from a previous session.

Browse recent sessions or search across saved session history. With no query, it returns recent sessions with IDs, titles, dates, message counts, and a preview. With a query, it performs keyword search and groups matches by session.

ParameterTypeRequiredDescription
querystringNoSearch terms, exact phrases in quotes, or file paths. Omit to browse recent sessions.
limitintegerNoMaximum number of sessions or search groups to return. Defaults to 5, max 10.

Example: Find previous work on authentication:

Terminal window
session_search query="authentication middleware" limit=5

Load a prior session transcript by full ID or unique prefix. Use this after session_search when the agent needs the detailed context from a specific past conversation.

ParameterTypeRequiredDescription
session_idstringYesSession ID or unique prefix. session_search shows short prefixes in brackets.
limitintegerNoMaximum messages to return. Defaults to 50, max 200.

Example: Read a matching session:

Terminal window
session_read session_id="a1b2c3d4" limit=80

The task system lets the agent track multi-step work items. Tasks persist in the session and appear in the UI’s context bar so both the agent and the user can see progress at a glance.

Create one or more tasks to track work progress. Use subject for a single task, or tasks (JSON array) to create multiple at once. Each task can optionally be nested under a parent. Provide either subject or tasks, but not both.

ParameterTypeRequiredDescription
subjectstringNo*Task title (for creating a single task).
descriptionstringNoTask details or acceptance criteria (single task mode).
active_formstringNoPresent-continuous label for the spinner, e.g. "Running tests" (single task mode).
parent_idstringNoParent task ID for nesting (single task mode).
tasksstringNo*JSON array of task objects for batch creation. Each object: {"subject": "...", "description": "...", "active_form": "...", "parent_id": "..."}. Only subject is required per object.

* Must provide either subject (single) or tasks (batch), but not both.

Example:

Terminal window
task_create subject="Migrate user table to UUIDs" description="Replace auto-increment IDs with UUIDv7 primary keys."

Example: Batch-create multiple tasks:

Terminal window
task_create tasks='[{"subject":"Add avatar column","active_form":"Adding avatar column"},{"subject":"Update user factory","active_form":"Updating user factory"}]'

Update a task’s status, subject, description, or dependencies. Status flow: pendingin_progresscompleted | cancelled.

ParameterTypeRequiredDescription
idstringYesThe task ID.
statusstringNoNew status: pending, in_progress, completed, or cancelled.
subjectstringNoUpdated task title.
descriptionstringNoUpdated task details.
active_formstringNoUpdated spinner label.
add_blocked_bystringNoJSON array of task IDs that block this task.
add_blocksstringNoJSON array of task IDs this task blocks.

Example:

Terminal window
task_update id="task_001" status="completed"

Retrieve full details of a single task.

ParameterTypeRequiredDescription
idstringYesThe task ID to retrieve.

Example:

Terminal window
task_get id="task_001"

List all tasks in the current session. Returns every task with its ID, title, status, and creation timestamp. Takes no parameters.

ParameterTypeRequiredDescription
No parameters.

Example:

Terminal window
task_list

The Lua scripting tools let the agent execute Lua code inside a sandboxed environment with access to integration APIs and native tools. Always start by discovering available namespaces with lua_list_docs, then read detailed docs with lua_read_doc before writing code.

For the full Lua model — host-side Lua tools, app.integrations.*, app.mcp.*, app.tools.*, multi-account namespaces, and discovery workflow — see Lua.

Execute Lua code with app.* namespace access. Use app.integrations.* for OpenCompany integration calls, app.mcp.* for configured MCP server calls, and app.tools.* for native tools (file_read, glob, grep, bash, subagent, etc.). Always use lua_read_doc first to look up function names and parameters. Use print() or dump() for output.

ParameterTypeRequiredDescription
codestringYesLua code to execute. Use print()/dump() for output. Access integrations via app.integrations.{name}.{function}() and MCP tools via app.mcp.{server}.{tool}().
memoryLimitintegerNoMemory limit in bytes. Default: 33554432 (32 MB).
cpuLimitnumberNoCPU time limit in seconds. Default: 30.0.

Example: Query an integration and print the result:

Terminal window
execute_lua code="local stats = app.integrations.plausible.query_stats({site_id='example.com'})
print(stats.visitors)"

Example: Call an MCP server tool from Lua:

Terminal window
lua_read_doc page="mcp.github"
execute_lua code="local repos = app.mcp.github.search_repositories({query='kosmokrator'})
dump(repos)"

List available Lua API namespaces and functions. Each namespace maps to an integration (plausible, coingecko, celestial, etc.), MCP server, or native Lua tool namespace. Shows function signatures with parameter names. Use this first to discover what is available.

ParameterTypeRequiredDescription
namespacestringNoFilter to a specific namespace (e.g. "integrations.plausible" or "mcp.github"). Omit to list all.

Example: List all available namespaces:

Terminal window
lua_list_docs

Example: Show functions in a specific integration:

Terminal window
lua_list_docs namespace="integrations.plausible"

Example: Show functions in a specific MCP server:

Terminal window
lua_list_docs namespace="mcp.github"

Search the Lua scripting API documentation by keyword. Searches function names, descriptions, and parameter info across all available namespaces and supplementary docs.

ParameterTypeRequiredDescription
querystringYesThe search query (e.g. "send message", "analytics", "query stats").
limitintegerNoMaximum number of results. Default: 10.

Example:

Terminal window
lua_search_docs query="analytics" limit=5

Read Lua API documentation for a namespace, function, or guide.

  • Namespace (e.g. "integrations.plausible" or "mcp.github") → full API reference with all functions and parameters
  • Function (e.g. "integrations.plausible.query_stats" or "mcp.github.search_repositories") → detailed single-function docs
  • Guide (e.g. "overview", "examples") → supplementary documentation

Always use lua_read_doc before writing Lua code to confirm function names and parameters.

ParameterTypeRequiredDescription
pagestringYesPage to read: namespace (e.g. "integrations.plausible"), function path (e.g. "integrations.plausible.query_stats" or "mcp.github.search_repositories"), or guide name (e.g. "overview", "examples").

Example:

Terminal window
lua_read_doc page="integrations.plausible.query_stats"

Example:

Terminal window
lua_read_doc page="mcp.github.search_repositories"

Interactive tools let the agent ask the user for input mid-task. This is useful when the agent encounters an ambiguous situation and needs clarification rather than guessing.

Pose a free-form question to the user. The agent pauses and waits for the user’s typed response before continuing.

ParameterTypeRequiredDescription
questionstringYesThe question to display to the user.

Example:

Terminal window
ask_user question="The tests reference a 'staging' database. Should I use the local SQLite DB or set up a MySQL container?"

Present a set of discrete choices to the user. The UI renders them as a numbered list (ANSI mode) or selectable options (TUI mode). Each choice is a JSON object with label (required), detail (optional description), and recommended (optional boolean to highlight the suggested option).

ParameterTypeRequiredDescription
questionstringYesThe question or prompt text.
choicesstringYesJSON array of choice objects. Each object: {"label": "...", "detail": "...", "recommended": true/false}. Only label is required per object.

Example: Let the user pick a database driver:

Terminal window
ask_choice \
question="Which database driver should this project use?" \
choices='[{"label":"SQLite","detail":"Lightweight, zero config","recommended":true},{"label":"MySQL","detail":"Production-grade"},{"label":"PostgreSQL","detail":"Advanced features"}]'

This section describes how KosmoKrator executes tool calls under the hood. Understanding the pipeline is helpful when debugging unexpected behaviour, tuning performance, or writing custom tool integrations.

When the LLM response contains one or more tool calls, KosmoKrator processes them through a multi-stage pipeline:

  1. ToolExecutor receives tool calls — the executor collects all tool calls from the parsed LLM response. Each call includes the tool name and a map of parameters.
  2. Permission check — before any tool runs, the Permissions system validates the call against the active policy. Calls that require approval are queued for user confirmation (or rejected outright in strict mode).
  3. Concurrent partitioning — independent tool calls are grouped and executed in parallel (see Concurrent Execution below).
  4. Results streamed back — tool results are returned to the LLM as part of the conversation, enabling the next reasoning step.

Tip: The entire pipeline is visible in the TUI’s Tools panel. You can watch each stage — permission check, execution, and result — in real time as the agent works.

The executor partitions tool calls into groups based on their dependencies and runs independent groups concurrently:

PartitionBehaviourExamples
Independent callsRun in parallel when no file paths overlap.Reading src/A.php and src/B.php simultaneously.
Overlapping file callsSerialized to prevent race conditions.A file_read followed by file_edit on the same file.
Subagent spawnsHandled on a separate worker pool; do not block regular tools.subagent calls for parallel research or delegated work.

Maximum parallelism is configurable via the --max-parallel-tools CLI flag (default: 4). Increasing this value can speed up large refactoring tasks but consumes more memory and API tokens.

Every tool result passes through a series of post-processors before being added to the conversation context:

StageLimitsPurpose
OutputTruncator2,000 lines / 50 KB capPrevents oversized results from flooding the context window. The full output is saved to a temporary file on disk and a summary is injected in place.
ToolResultDeduplicatorRemoves results that have been superseded by a later call to the same tool with the same parameters (e.g. re-reading a file after editing it).
ContextPrunerConfigurable budgetReplaces old, low-value tool results with short placeholders to free up context window space for new information.

Tip: For a deep dive into how context is managed, see the Context and Sessions & Memory docs. They cover pruning strategy, memory persistence, and how to tune the context budget for your workflow.

The file_read tool maintains a lightweight cache of previously read files. On subsequent reads:

  • If the file has not been modified since the last read, the tool returns [Unchanged since last file_read of path (lines X-Y); content omitted to save tokens] instead of re-sending the full content — saving context window tokens and reducing latency.
  • If the file has been modified (by file_edit, file_write, or an external process), the full updated content is returned.
  • Large files exceeding 10 MB are streamed line-by-line to avoid memory spikes and to respect the OutputTruncator limits.

This caching behaviour is automatic and transparent to the LLM. The agent always sees the correct file state, but avoids wasting context on redundant re-reads.

Tip: If you need to force a fresh read (for example, after an external build tool modifies a generated file), the agent can use file_read with offset=1 to bypass the cache.