# ai/chat
Multi-turn conversation with tool use. Appends the user message, runs the
tool-use loop against the MCP tool registry, and returns the extended
message list. The provider comes from the cfg (registry form) or is passed
explicitly (low-level form).
## Syntax
import "deft/stdext/ai/registry" as ai set cfg [ai/default-cfg] set msgs [await [ai/chat $cfg @{} "Hello!"]] set msgs [await [ai/chat $cfg $msgs "Now refactor that."]]
## Parameters
- `$cfg` — config map (`:provider` selects the provider plugin)
- `$messages` — prior conversation messages (`@{}` to start)
- `"user-text"` — the new user message
- optional `$tools` / `$max-iters` — pre-filtered tool schemas and loop cap
(used by subagents)
## Returns
The extended message vector, or `%Err{:message}`. Tool schema dialect
(`:openai` / `:anthropic`) is chosen by the provider's `tool-format`.
## See Also
`ai/ask`, `ai/models`, `ai/subagent` (low-level, explicit-provider chat)