KosmoKrator

data

Tavily Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Tavily KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.tavily.*. Use lua_read_doc("integrations.tavily") inside KosmoKrator to discover the same reference at runtime.

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Tavily workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("tavily"))' --json
kosmo integrations:lua --eval 'print(docs.read("tavily.search"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local tavily = app.integrations.tavily
local result = tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.tavily, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.tavily.default.* or app.integrations.tavily.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Tavily, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Tavily — Lua API Reference

The tavily integration exposes Tavily’s AI-oriented search, extraction, crawl, map, research, and usage APIs.

Use it when an agent needs current web information, clean source content, a site map, documentation crawl material, or a longer asynchronous research report.

All calls require a Tavily API key. If a project_id is configured, the integration sends it as X-Project-ID so usage can be tracked per project.

Execute a web search and return Tavily’s JSON response. Results are kept in Tavily’s native shape: top-level query, optional answer, optional images, results, response_time, optional usage, and request_id.

Parameters

NameTypeRequiredDescription
querystringyesSearch query.
search_depthstringnobasic, advanced, fast, or ultra-fast.
chunks_per_sourceintegernoChunks per source for advanced search, 1-3.
max_resultsintegernoMaximum results, 0-20.
topicstringnogeneral, news, or finance.
time_rangestringnoday, week, month, year, or shorthand d, w, m, y.
start_datestringnoStart date in YYYY-MM-DD format.
end_datestringnoEnd date in YYYY-MM-DD format.
include_answerbooleanstringno
include_raw_contentbooleanstringno
include_imagesbooleannoInclude query and per-result images.
include_image_descriptionsbooleannoInclude image descriptions when images are enabled.
include_faviconbooleannoInclude result favicons.
include_domainsstring[]noOnly include these domains.
exclude_domainsstring[]noExclude these domains.
countrystringnoBoost results from a Tavily-supported country value.
auto_parametersbooleannoLet Tavily pick some search parameters.
exact_matchbooleannoRequire exact quoted phrases in results.
include_usagebooleannoInclude credit usage details.
safe_searchbooleannoEnterprise-only unsafe-content filtering.

Example

local result = app.integrations.tavily.search({
  query = "latest Laravel release notes",
  search_depth = "advanced",
  include_answer = "basic",
  include_raw_content = "markdown",
  include_favicon = true,
  max_results = 5
})

for _, item in ipairs(result.results or {}) do
  print(item.title .. " " .. item.url)
end

extract

Extract clean content from one or more URLs. The output keeps Tavily’s native results, failed_results, response_time, optional usage, and request_id fields.

Parameters

NameTypeRequiredDescription
urlsstringstring[]yes
querystringnoIntent used to rerank extracted chunks.
chunks_per_sourceintegernoChunks per source when query is supplied, 1-5.
extract_depthstringnobasic or advanced.
include_imagesbooleannoInclude extracted images.
include_faviconbooleannoInclude favicon URL for each result.
formatstringnomarkdown or text.
timeoutnumbernoTimeout in seconds, 1-60.
include_usagebooleannoInclude credit usage details.

Example

local extracted = app.integrations.tavily.extract({
  urls = {
    "https://example.test/docs/getting-started",
    "https://example.test/docs/api"
  },
  extract_depth = "advanced",
  format = "markdown"
})

crawl

Crawl a site and extract content from discovered pages. Use this for RAG ingestion or documentation snapshots when full content is needed.

Parameters

NameTypeRequiredDescription
urlstringyesRoot URL.
instructionsstringnoNatural language crawl instructions.
chunks_per_sourceintegernoChunks per source when instructions are supplied, 1-5.
max_depthintegernoCrawl depth, 1-5.
max_breadthintegernoLinks followed per level, 1-500.
limitintegernoTotal links to process.
select_pathsstring[]noRegex path patterns to include.
select_domainsstring[]noRegex domain patterns to include.
exclude_pathsstring[]noRegex path patterns to exclude.
exclude_domainsstring[]noRegex domain patterns to exclude.
allow_externalbooleannoWhether external links may be included.
include_imagesbooleannoInclude images in results.
extract_depthstringnobasic or advanced.
formatstringnomarkdown or text.
include_faviconbooleannoInclude favicon URL for each result.
timeoutnumbernoTimeout in seconds, 10-150.
include_usagebooleannoInclude credit usage details.

Example

local crawl = app.integrations.tavily.crawl({
  url = "https://example.test/docs",
  instructions = "Find API reference pages",
  select_paths = {"/docs/.*"},
  max_depth = 2,
  limit = 25,
  format = "markdown"
})

map

Map a website and return discovered URLs only. Use this before extract or crawl when the agent needs to decide which URLs matter.

Parameters

NameTypeRequiredDescription
urlstringyesRoot URL.
instructionsstringnoNatural language mapping instructions.
max_depthintegernoMapping depth, 1-5.
max_breadthintegernoLinks followed per level, 1-500.
limitintegernoTotal links to process.
select_pathsstring[]noRegex path patterns to include.
select_domainsstring[]noRegex domain patterns to include.
exclude_pathsstring[]noRegex path patterns to exclude.
exclude_domainsstring[]noRegex domain patterns to exclude.
allow_externalbooleannoWhether external links may be included.
timeoutnumbernoTimeout in seconds, 10-150.
include_usagebooleannoInclude credit usage details.

Example

local mapped = app.integrations.tavily.map({
  url = "https://example.test/docs",
  select_paths = {"/docs/.*"},
  limit = 100
})

create_research_task

Queue an asynchronous Tavily Research task. The result includes request_id, which can be passed to get_research_task.

Streaming is not supported by this integration tool because Tavily streaming returns Server-Sent Events rather than a JSON tool result.

Parameters

NameTypeRequiredDescription
inputstringyesResearch task or question.
modelstringnomini, pro, or auto.
output_schemaobjectnoJSON Schema with properties and optional required.
citation_formatstringnonumbered, mla, apa, or chicago.

Example

local task = app.integrations.tavily.create_research_task({
  input = "Compare current EU AI Act compliance guidance for SaaS vendors",
  model = "pro",
  citation_format = "numbered"
})

print(task.request_id)

get_research_task

Retrieve status or completed content for a research task.

Parameters

NameTypeRequiredDescription
request_idstringyesTavily research request ID.

Example

local report = app.integrations.tavily.get_research_task({
  request_id = "123e4567-e89b-12d3-a456-426614174111"
})

print(report.status)
print(report.content)

get_usage

Retrieve API key and account usage. The response contains key and account usage objects when available.

Parameters

None.

Example

local usage = app.integrations.tavily.get_usage()
print(usage.key and usage.key.usage)

Multi-Account Usage

If multiple Tavily accounts are configured, use account-specific namespaces:

app.integrations.tavily.search({ query = "default account search" })
app.integrations.tavily.default.search({ query = "explicit default account" })
app.integrations.tavily.research.search({ query = "named account search" })
Raw agent markdown
# Tavily — Lua API Reference

The `tavily` integration exposes Tavily's AI-oriented search, extraction, crawl, map, research, and usage APIs.

Use it when an agent needs current web information, clean source content, a site map, documentation crawl material, or a longer asynchronous research report.

All calls require a Tavily API key. If a `project_id` is configured, the integration sends it as `X-Project-ID` so usage can be tracked per project.

## search

Execute a web search and return Tavily's JSON response. Results are kept in Tavily's native shape: top-level `query`, optional `answer`, optional `images`, `results`, `response_time`, optional `usage`, and `request_id`.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | yes | Search query. |
| `search_depth` | string | no | `basic`, `advanced`, `fast`, or `ultra-fast`. |
| `chunks_per_source` | integer | no | Chunks per source for advanced search, 1-3. |
| `max_results` | integer | no | Maximum results, 0-20. |
| `topic` | string | no | `general`, `news`, or `finance`. |
| `time_range` | string | no | `day`, `week`, `month`, `year`, or shorthand `d`, `w`, `m`, `y`. |
| `start_date` | string | no | Start date in `YYYY-MM-DD` format. |
| `end_date` | string | no | End date in `YYYY-MM-DD` format. |
| `include_answer` | boolean|string | no | `true`, `basic`, or `advanced` to include an answer. |
| `include_raw_content` | boolean|string | no | `true`, `markdown`, or `text` to include page content. |
| `include_images` | boolean | no | Include query and per-result images. |
| `include_image_descriptions` | boolean | no | Include image descriptions when images are enabled. |
| `include_favicon` | boolean | no | Include result favicons. |
| `include_domains` | string[] | no | Only include these domains. |
| `exclude_domains` | string[] | no | Exclude these domains. |
| `country` | string | no | Boost results from a Tavily-supported country value. |
| `auto_parameters` | boolean | no | Let Tavily pick some search parameters. |
| `exact_match` | boolean | no | Require exact quoted phrases in results. |
| `include_usage` | boolean | no | Include credit usage details. |
| `safe_search` | boolean | no | Enterprise-only unsafe-content filtering. |

### Example

```lua
local result = app.integrations.tavily.search({
  query = "latest Laravel release notes",
  search_depth = "advanced",
  include_answer = "basic",
  include_raw_content = "markdown",
  include_favicon = true,
  max_results = 5
})

for _, item in ipairs(result.results or {}) do
  print(item.title .. " " .. item.url)
end
```

## extract

Extract clean content from one or more URLs. The output keeps Tavily's native `results`, `failed_results`, `response_time`, optional `usage`, and `request_id` fields.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `urls` | string|string[] | yes | URL or URLs to extract. |
| `query` | string | no | Intent used to rerank extracted chunks. |
| `chunks_per_source` | integer | no | Chunks per source when `query` is supplied, 1-5. |
| `extract_depth` | string | no | `basic` or `advanced`. |
| `include_images` | boolean | no | Include extracted images. |
| `include_favicon` | boolean | no | Include favicon URL for each result. |
| `format` | string | no | `markdown` or `text`. |
| `timeout` | number | no | Timeout in seconds, 1-60. |
| `include_usage` | boolean | no | Include credit usage details. |

### Example

```lua
local extracted = app.integrations.tavily.extract({
  urls = {
    "https://example.test/docs/getting-started",
    "https://example.test/docs/api"
  },
  extract_depth = "advanced",
  format = "markdown"
})
```

## crawl

Crawl a site and extract content from discovered pages. Use this for RAG ingestion or documentation snapshots when full content is needed.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `url` | string | yes | Root URL. |
| `instructions` | string | no | Natural language crawl instructions. |
| `chunks_per_source` | integer | no | Chunks per source when instructions are supplied, 1-5. |
| `max_depth` | integer | no | Crawl depth, 1-5. |
| `max_breadth` | integer | no | Links followed per level, 1-500. |
| `limit` | integer | no | Total links to process. |
| `select_paths` | string[] | no | Regex path patterns to include. |
| `select_domains` | string[] | no | Regex domain patterns to include. |
| `exclude_paths` | string[] | no | Regex path patterns to exclude. |
| `exclude_domains` | string[] | no | Regex domain patterns to exclude. |
| `allow_external` | boolean | no | Whether external links may be included. |
| `include_images` | boolean | no | Include images in results. |
| `extract_depth` | string | no | `basic` or `advanced`. |
| `format` | string | no | `markdown` or `text`. |
| `include_favicon` | boolean | no | Include favicon URL for each result. |
| `timeout` | number | no | Timeout in seconds, 10-150. |
| `include_usage` | boolean | no | Include credit usage details. |

### Example

```lua
local crawl = app.integrations.tavily.crawl({
  url = "https://example.test/docs",
  instructions = "Find API reference pages",
  select_paths = {"/docs/.*"},
  max_depth = 2,
  limit = 25,
  format = "markdown"
})
```

## map

Map a website and return discovered URLs only. Use this before `extract` or `crawl` when the agent needs to decide which URLs matter.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `url` | string | yes | Root URL. |
| `instructions` | string | no | Natural language mapping instructions. |
| `max_depth` | integer | no | Mapping depth, 1-5. |
| `max_breadth` | integer | no | Links followed per level, 1-500. |
| `limit` | integer | no | Total links to process. |
| `select_paths` | string[] | no | Regex path patterns to include. |
| `select_domains` | string[] | no | Regex domain patterns to include. |
| `exclude_paths` | string[] | no | Regex path patterns to exclude. |
| `exclude_domains` | string[] | no | Regex domain patterns to exclude. |
| `allow_external` | boolean | no | Whether external links may be included. |
| `timeout` | number | no | Timeout in seconds, 10-150. |
| `include_usage` | boolean | no | Include credit usage details. |

### Example

```lua
local mapped = app.integrations.tavily.map({
  url = "https://example.test/docs",
  select_paths = {"/docs/.*"},
  limit = 100
})
```

## create_research_task

Queue an asynchronous Tavily Research task. The result includes `request_id`, which can be passed to `get_research_task`.

Streaming is not supported by this integration tool because Tavily streaming returns Server-Sent Events rather than a JSON tool result.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `input` | string | yes | Research task or question. |
| `model` | string | no | `mini`, `pro`, or `auto`. |
| `output_schema` | object | no | JSON Schema with `properties` and optional `required`. |
| `citation_format` | string | no | `numbered`, `mla`, `apa`, or `chicago`. |

### Example

```lua
local task = app.integrations.tavily.create_research_task({
  input = "Compare current EU AI Act compliance guidance for SaaS vendors",
  model = "pro",
  citation_format = "numbered"
})

print(task.request_id)
```

## get_research_task

Retrieve status or completed content for a research task.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `request_id` | string | yes | Tavily research request ID. |

### Example

```lua
local report = app.integrations.tavily.get_research_task({
  request_id = "123e4567-e89b-12d3-a456-426614174111"
})

print(report.status)
print(report.content)
```

## get_usage

Retrieve API key and account usage. The response contains `key` and `account` usage objects when available.

### Parameters

None.

### Example

```lua
local usage = app.integrations.tavily.get_usage()
print(usage.key and usage.key.usage)
```

## Multi-Account Usage

If multiple Tavily accounts are configured, use account-specific namespaces:

```lua
app.integrations.tavily.search({ query = "default account search" })
app.integrations.tavily.default.search({ query = "explicit default account" })
app.integrations.tavily.research.search({ query = "named account search" })
```
Metadata-derived Lua example
local result = app.integrations.tavily.search({query = "example_query", search_depth = "example_search_depth", chunks_per_source = 1, max_results = 1, topic = "example_topic", time_range = "example_time_range", start_date = "example_start_date", end_date = "example_end_date"})
print(result)

Functions

extract Read

Extract clean markdown or text content from one or more URLs with Tavily. Use after search or map when an agent needs full page content.

Lua path
app.integrations.tavily.extract
Full name
tavily.tavily_extract
ParameterTypeRequiredDescription
urls string,array yes URL or array of URLs to extract.
query string no Optional user intent for reranking extracted content chunks.
chunks_per_source integer no Chunks per source when query is provided. Range: 1-5.
extract_depth string no Extraction depth. advanced retrieves more data with higher latency/cost.
include_images boolean no Include images extracted from URLs.
include_favicon boolean no Include favicon URL for each result.
format string no Output format for raw_content.
timeout number no Extraction timeout in seconds. Range: 1-60.
include_usage boolean no Include credit usage details.
crawl Read

Crawl a website with Tavily and return extracted content from discovered pages. Use for documentation ingestion, RAG source collection, and targeted site extraction.

Lua path
app.integrations.tavily.crawl
Full name
tavily.tavily_crawl
ParameterTypeRequiredDescription
url string yes Root URL to begin the crawl.
instructions string no Natural language crawl instructions. Increases mapping cost when supplied.
chunks_per_source integer no Chunks per source when instructions are supplied. Range: 1-5.
max_depth integer no Maximum crawl depth. Range: 1-5.
max_breadth integer no Maximum links to follow per level. Range: 1-500.
limit integer no Maximum number of links to process.
select_paths array no Regex path patterns to include.
select_domains array no Regex domain patterns to include.
exclude_paths array no Regex path patterns to exclude.
exclude_domains array no Regex domain patterns to exclude.
allow_external boolean no Whether external links may appear in final results.
include_images boolean no Include images in crawl results.
extract_depth string no Extraction depth for crawled pages.
format string no Output format for raw_content.
include_favicon boolean no Include favicon URL for each result.
timeout number no Crawl timeout in seconds. Range: 10-150.
include_usage boolean no Include credit usage details.
map Read

Map a website with Tavily and return discovered URLs without extracting full page content. Use before targeted extract or crawl jobs.

Lua path
app.integrations.tavily.map
Full name
tavily.tavily_map
ParameterTypeRequiredDescription
url string yes Root URL to begin mapping.
instructions string no Natural language mapping instructions. Increases cost when supplied.
max_depth integer no Maximum mapping depth. Range: 1-5.
max_breadth integer no Maximum links to follow per level. Range: 1-500.
limit integer no Maximum number of links to process.
select_paths array no Regex path patterns to include.
select_domains array no Regex domain patterns to include.
exclude_paths array no Regex path patterns to exclude.
exclude_domains array no Regex domain patterns to exclude.
allow_external boolean no Whether external links may appear in final results.
timeout number no Map timeout in seconds. Range: 10-150.
include_usage boolean no Include credit usage details.
create_research_task Read

Create a Tavily Research task for comprehensive multi-source research. The returned request_id can be passed to tavily_get_research_task.

Lua path
app.integrations.tavily.create_research_task
Full name
tavily.tavily_create_research_task
ParameterTypeRequiredDescription
input string yes Research question or task to investigate.
model string no Research agent model. mini is targeted, pro is comprehensive, auto lets Tavily choose.
output_schema object no Optional JSON Schema with properties and optional required fields for structured output.
citation_format string no Citation format for the research report.
stream boolean no Not supported by this tool. Tavily streaming returns SSE rather than JSON.
get_research_task Read

Get the current status and, when complete, the content and sources for a Tavily Research task by request_id.

Lua path
app.integrations.tavily.get_research_task
Full name
tavily.tavily_get_research_task
ParameterTypeRequiredDescription
request_id string yes Research task request_id returned by tavily_create_research_task.
get_usage Read

Get Tavily API key and account usage details, including per-endpoint credit usage and plan limits.

Lua path
app.integrations.tavily.get_usage
Full name
tavily.tavily_get_usage
ParameterTypeRequiredDescription
No parameters.