# Tools

A reply can call the tools a request offers (`--tools`, setting `defaultTools`; see [the command
line reference](../reference/cli.md)). How each call is journaled is in
[durability](../dev/durability.md). Beside Pi's tools, `send_message` lets a conversation message
another ([peers](peers.md)), and `wake` lets the model start a monitor, or a loop or a goal once you
agree, and end a goal ([loops](loops.md)).

## Parallel tool calls

The tool calls of one reply run at the same time, as in Pi (its `toolExecution` "parallel", the
default). Each call's PreToolUse hooks run first, one call after another in call order; then the
calls run together, each in a process forked from pic, and each is journaled as a lone call is:
intent, started, result, every step its own short transaction. Results commit as calls finish, but
reach the transcript (and the model) in call order. `tool_execution_start` comes for every call
before any runs; `tool_execution_update` and `tool_execution_end` come as each call goes. A crash
mid-batch is recovered per call: a started command becomes unknown and is never run again, a started
read, write or edit runs again, and a finished call keeps its one result. Esc, Ctrl-C and the RPC
`abort` abort every running call. Calls on the same file wait for each other in call order when
either changes it (Pi queues only edits and writes to one file; pic also keeps a read of that file
in its place). `pic settings toolExecution sequential` (or Tool execution in `/settings`) runs the
calls one by one instead. A [codemode](codemode.md) script's calls run the same way.

## Web fetch

`web_fetch {url, max_chars}` reads a public web page: pic does the request itself (its own HTTP and
TLS, nothing to install), and the model gets text. It is on by default; `--exclude-tools web_fetch`
or `-web_fetch` leaves it out, and the `offline` setting refuses it, saying so.

- HTML becomes markdown: headings, links (made absolute), lists, code blocks, quotes and tables
  stay; scripts, styles and navigation go. Plain text and JSON come back as they are. Images, PDFs
  and other binary types are refused with their type and size.
- It follows up to five redirects, gives up at 5 MB or after 30 seconds, and takes `http://` and
  `https://` only. A page behind a login is not reachable: there are no cookies or credentials.
- It will not fetch from your own machine or network: addresses that are private (10.x, 192.168.x,
  172.16-31.x), loopback, link-local, carrier-grade NAT, multicast or reserved, and cloud metadata
  addresses such as 169.254.169.254, are refused. The check is made on the address pic connects to,
  so a name that resolves to one is refused too, and so is a redirect to one. To read something on
  your network, use `bash` and `curl`.
- The text is cut to `max_chars` (default 20000, at most 50000), and the notice says where the whole
  page is kept: read it with `read` and an offset and limit, as with a long command's output.

The call is a GET, so after a crash a call that had started runs again. PreToolUse hooks and the
secret guard see it like any tool call, so a hook can refuse a URL ([hooks](hooks.md)).

## Web search

`web_search {query, count}` searches the web. The model sees one tool by that name; what answers it
depends on the model.

**Cost, and how to turn it off.** When the model's provider has its own search, that provider runs
it and **charges for each search on your account there**, besides the tokens the results use
(Anthropic's is $10 per 1,000 searches on its API; check each provider's current pricing). It is on
by default. `pic settings webSearch brave` makes every search Brave's, which spends nothing on the
provider's meter; `--exclude-tools web_search` (or `-web_search`, or the same in `defaultTools`)
removes the tool altogether; `offline` refuses it.

- **The provider's own search**, for Anthropic, OpenAI (with an API key), xAI and OpenRouter models.
  pic declares the provider's search tool in place of its own, the provider runs the searches, and
  its answer carries them with their sources. The search and its citations are kept in the
  conversation as they came, so a resumed conversation sends them back and a crash never searches
  twice for a reply that was recorded. The transcript shows the query and a list of sources, with
  control characters dropped.
- **Brave Search**, otherwise: pic's own function (below), when a Brave key is set.
- A ChatGPT sign-in is not known to allow the provider's search, and Gemini's needs more than pic
  sends today, so both use Brave.

The tool is offered when a Brave key exists or the model in use can search through its provider;
`--tools +web_search` offers it regardless (without either it says how to add a key). A conversation
fixes its tools at its first request, so which model it started on decides this for good: switching
model later neither adds `web_search` nor takes it away (after a switch it is whichever of the
provider's search or Brave's function the new model can use). Before the first request, `/tools`
and the RPC tool list do not show `web_search` for a provider's search; it appears once the first
request has been made.

The provider's search is used only when pic can decide beforehand: in `ask-all` and `read-only` the
call is Brave's, which [permission modes](permissions.md) ask about or refuse as they do
`web_fetch`, since pic cannot ask before a call the provider makes itself. **Under those two modes
search therefore needs a Brave key**; with none, the tool says so and the model has no search. If
the mode, the setting or `offline` changes in a conversation that already searched through its
provider, those searches are sent back as plain text (the query and the sources), and a reply
that also called a tool is sent as another model would be sent it, without its reasoning.

**What pic cannot see.** A search the provider runs is part of the model's reply: pic never runs it,
so [PreToolUse hooks](hooks.md) do not see it, the secret guard cannot check its query, and a
permission mode cannot ask about it (hence the rule above). The query is whatever the provider's
model wrote, and it may include text from your conversation. To keep queries under pic's hooks and
guard, set `webSearch` to `brave`: Brave's search is a call pic makes, which they see.

### Brave Search

pic's own `web_search` asks [Brave Search](https://brave.com/search/api/) and returns a numbered
list: a title, the address and a short snippet for each result. The model reads a page it likes with
`web_fetch`.

- It needs a Brave Search API key. Add it once with `pic login brave-search` (or
  `/login brave-search`), which seals it as it does any key ([credentials](credentials.md)), or
  set `BRAVE_API_KEY`. With neither, the tool is offered only when a provider's own search can serve it. pic reads the key stored under its
  default name, so a key saved only with `--as NAME` leaves the tool out. A conversation already
  open keeps the tools it started with: a key added meanwhile counts from the next conversation.
  The key is sent to Brave only, as a header, and is never shown to the model or written to the
  journal.
- `count` is how many results, 5 by default and at most 10. The query is at most 400 characters.
  A reply over 2 MB or a search that takes over 20 seconds fails. Snippets are cut to 500 characters.
- Markup and entities in titles and snippets become plain text and control characters are dropped,
  because the words come from the open web.
- A failure says which: a refused key, an exhausted quota (HTTP 429, with the wait Brave names), or
  Brave's status.

The query leaves your machine for Brave, so [permission modes](permissions.md) count the call as a
change: `ask-all` asks, `read-only` refuses. A call that had started runs again after a crash.
PreToolUse hooks and the secret guard see it like any tool call (the hook name is `WebSearch`; the
provider's own searches are not calls pic runs, so hooks do not see them).

## Search ignores nothing

`grep`, `find` and the file lists behind `@` completion and file pickers (the RPC command
`list_files`) return files that `.gitignore`, `.ignore`, `.fdignore`, `.zitignore`, `.fslignore` and
the `ignore-glob` settings list. Those files keep files out of commits; they do not keep them out
of what the agent can look at, so the tools' descriptions no longer say "Respects .gitignore".
Version-control folders (`.git`, `.zit`, `_FOSSIL_`, `.fslckout`) are not project files and stay
out. Pi's limits and result text are unchanged.

To keep something from the agent, list it in a `.picignore`: gitignore syntax, in any folder, and a
nested one covers only its own folder. It is read by `grep`, `find` and `list_files`, and nothing is
left out unless one says so. The same rule will apply to full-text search. [Differences from Pi](differences-from-pi.md) lists
this.

## A file another conversation changed

When [several pics work in one project](sessions.md#several-pics-in-one-project), two conversations
can change the same file. pic does not merge. It knows from the journal which conversation edited
or wrote which file, and tells the agent when it meets another's change: one made while this pic
was running the request, after this conversation last read, edited or wrote the file.

- **`edit`** that cannot find its text, or finds it more than once, in such a file: Pi's error,
  then `PATH was changed by another pic conversation (ID) after this one last read it`, and the file
  as `read` would return it, so the agent can redo the edit. An edit whose text still matches is
  applied as usual.
- **`write`** to such a file is not performed the first time: the result is an error that says the
  same and shows the file. Having been shown it, the agent's next write to that file goes through.

Changes made by commands (`bash`) are not tracked, nor are changes made while this conversation
was idle. With one pic at a time none of this happens, forks included, and the tools behave as
Pi's.
