KosmoKrator

other

Mistralai Lua API for KosmoKrator Agents

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

7 functions 3 read 4 write API key auth

Lua Namespace

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

Agent-Facing Lua Docs

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

MistralAI — Lua API Reference

chat

Generate a chat completion using a MistralAI model.

Parameters

NameTypeRequiredDescription
modelstringyesModel ID (e.g., "mistral-large-latest", "mistral-small-latest", "open-mistral-nemo")
messagesarrayyesArray of message objects with role and content
temperaturenumbernoSampling temperature 0.0–1.0 (default: 0.7)
max_tokensintegernoMaximum tokens to generate

Message Roles

  • "system" — Set the assistant’s behavior and personality
  • "user" — User input
  • "assistant" — Previous assistant responses (for multi-turn)

Examples

Single-turn chat

local result = app.integrations.mistralai.chat({
  model = "mistral-large-latest",
  messages = {
    { role = "user", content = "Explain quantum computing in one paragraph." }
  },
  temperature = 0.7
})

for _, choice in ipairs(result.choices) do
  print(choice.content)
end

Multi-turn conversation

local result = app.integrations.mistralai.chat({
  model = "mistral-small-latest",
  messages = {
    { role = "system", content = "You are a helpful coding assistant." },
    { role = "user", content = "Write a Python function to reverse a string." },
    { role = "assistant", content = "Here's a simple way..." },
    { role = "user", content = "Can you make it handle Unicode?" }
  }
})

create_embedding

Generate text embeddings for semantic search, similarity, or clustering.

Parameters

NameTypeRequiredDescription
modelstringyesEmbedding model (e.g., "mistral-embed")
inputstringyesText to embed, or JSON array of strings for batch

Examples

Single text embedding

local result = app.integrations.mistralai.create_embedding({
  model = "mistral-embed",
  input = "The quick brown fox jumps over the lazy dog"
})

print("Embedding dimensions: " .. result.embeddings[1].dimensions)

Batch embeddings

local result = app.integrations.mistralai.create_embedding({
  model = "mistral-embed",
  input = '["First text", "Second text", "Third text"]'
})

print("Generated " .. result.embeddingCount .. " embeddings")

list_models

List all models available in your MistralAI account.

Parameters

None.

Example

local result = app.integrations.mistralai.list_models()

for _, model in ipairs(result.models) do
  print(model.id .. " (owned by: " .. (model.owned_by or "unknown") .. ")")
end

print("Total models: " .. result.total)

finetune

Create a fine-tuning job to train a custom model.

Parameters

NameTypeRequiredDescription
modelstringyesBase model to fine-tune (e.g., "open-mistral-7b")
training_filesarrayyesArray of uploaded training file IDs
hyperparametersstringnoJSON-encoded hyperparameters (e.g., {"n_epochs": 3})
suffixstringnoSuffix for the resulting model name

Example

local result = app.integrations.mistralai.finetune({
  model = "open-mistral-7b",
  training_files = { "file-abc123" },
  hyperparameters = '{"n_epochs": 3, "learning_rate": 0.0001}',
  suffix = "my-custom-model"
})

print("Job ID: " .. result.id)
print("Status: " .. result.status)

list_agents

List all MistralAI agents in your account.

Parameters

None.

Example

local result = app.integrations.mistralai.list_agents()

for _, agent in ipairs(result.agents) do
  print(agent.name .. " (" .. agent.model .. ")")
end

print("Total agents: " .. result.total)

create_agent

Create a new MistralAI agent with custom instructions.

Parameters

NameTypeRequiredDescription
namestringyesAgent name (e.g., "Support Bot")
modelstringyesModel to use (e.g., "mistral-large-latest")
instructionsstringyesSystem instructions defining agent behavior
descriptionstringnoShort description of the agent’s purpose

Example

local result = app.integrations.mistralai.create_agent({
  name = "Code Reviewer",
  model = "mistral-large-latest",
  instructions = "You are an expert code reviewer. Analyze code for bugs, performance issues, and best practices. Be concise and actionable.",
  description = "Reviews code for quality and issues"
})

print("Created agent: " .. result.name .. " (ID: " .. result.id .. ")")

get_current_user

Get information about the authenticated MistralAI user.

Parameters

None.

Example

local result = app.integrations.mistralai.get_current_user()

print("User info retrieved successfully")

Multi-Account Usage

If you have multiple MistralAI accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.mistralai.chat({...})

-- Explicit default (portable across setups)
app.integrations.mistralai.default.chat({...})

-- Named accounts
app.integrations.mistralai.production.chat({...})
app.integrations.mistralai.development.chat({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# MistralAI — Lua API Reference

## chat

Generate a chat completion using a MistralAI model.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | string | yes | Model ID (e.g., `"mistral-large-latest"`, `"mistral-small-latest"`, `"open-mistral-nemo"`) |
| `messages` | array | yes | Array of message objects with `role` and `content` |
| `temperature` | number | no | Sampling temperature 0.0–1.0 (default: 0.7) |
| `max_tokens` | integer | no | Maximum tokens to generate |

### Message Roles

- `"system"` — Set the assistant's behavior and personality
- `"user"` — User input
- `"assistant"` — Previous assistant responses (for multi-turn)

### Examples

#### Single-turn chat

```lua
local result = app.integrations.mistralai.chat({
  model = "mistral-large-latest",
  messages = {
    { role = "user", content = "Explain quantum computing in one paragraph." }
  },
  temperature = 0.7
})

for _, choice in ipairs(result.choices) do
  print(choice.content)
end
```

#### Multi-turn conversation

```lua
local result = app.integrations.mistralai.chat({
  model = "mistral-small-latest",
  messages = {
    { role = "system", content = "You are a helpful coding assistant." },
    { role = "user", content = "Write a Python function to reverse a string." },
    { role = "assistant", content = "Here's a simple way..." },
    { role = "user", content = "Can you make it handle Unicode?" }
  }
})
```

---

## create_embedding

Generate text embeddings for semantic search, similarity, or clustering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | string | yes | Embedding model (e.g., `"mistral-embed"`) |
| `input` | string | yes | Text to embed, or JSON array of strings for batch |

### Examples

#### Single text embedding

```lua
local result = app.integrations.mistralai.create_embedding({
  model = "mistral-embed",
  input = "The quick brown fox jumps over the lazy dog"
})

print("Embedding dimensions: " .. result.embeddings[1].dimensions)
```

#### Batch embeddings

```lua
local result = app.integrations.mistralai.create_embedding({
  model = "mistral-embed",
  input = '["First text", "Second text", "Third text"]'
})

print("Generated " .. result.embeddingCount .. " embeddings")
```

---

## list_models

List all models available in your MistralAI account.

### Parameters

None.

### Example

```lua
local result = app.integrations.mistralai.list_models()

for _, model in ipairs(result.models) do
  print(model.id .. " (owned by: " .. (model.owned_by or "unknown") .. ")")
end

print("Total models: " .. result.total)
```

---

## finetune

Create a fine-tuning job to train a custom model.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | string | yes | Base model to fine-tune (e.g., `"open-mistral-7b"`) |
| `training_files` | array | yes | Array of uploaded training file IDs |
| `hyperparameters` | string | no | JSON-encoded hyperparameters (e.g., `{"n_epochs": 3}`) |
| `suffix` | string | no | Suffix for the resulting model name |

### Example

```lua
local result = app.integrations.mistralai.finetune({
  model = "open-mistral-7b",
  training_files = { "file-abc123" },
  hyperparameters = '{"n_epochs": 3, "learning_rate": 0.0001}',
  suffix = "my-custom-model"
})

print("Job ID: " .. result.id)
print("Status: " .. result.status)
```

---

## list_agents

List all MistralAI agents in your account.

### Parameters

None.

### Example

```lua
local result = app.integrations.mistralai.list_agents()

for _, agent in ipairs(result.agents) do
  print(agent.name .. " (" .. agent.model .. ")")
end

print("Total agents: " .. result.total)
```

---

## create_agent

Create a new MistralAI agent with custom instructions.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | Agent name (e.g., `"Support Bot"`) |
| `model` | string | yes | Model to use (e.g., `"mistral-large-latest"`) |
| `instructions` | string | yes | System instructions defining agent behavior |
| `description` | string | no | Short description of the agent's purpose |

### Example

```lua
local result = app.integrations.mistralai.create_agent({
  name = "Code Reviewer",
  model = "mistral-large-latest",
  instructions = "You are an expert code reviewer. Analyze code for bugs, performance issues, and best practices. Be concise and actionable.",
  description = "Reviews code for quality and issues"
})

print("Created agent: " .. result.name .. " (ID: " .. result.id .. ")")
```

---

## get_current_user

Get information about the authenticated MistralAI user.

### Parameters

None.

### Example

```lua
local result = app.integrations.mistralai.get_current_user()

print("User info retrieved successfully")
```

---

## Multi-Account Usage

If you have multiple MistralAI accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.mistralai.chat({...})

-- Explicit default (portable across setups)
app.integrations.mistralai.default.chat({...})

-- Named accounts
app.integrations.mistralai.production.chat({...})
app.integrations.mistralai.development.chat({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.mistralai.mistralai_chat({
  model = "example_model",
  messages = "example_messages",
  temperature = 1,
  max_tokens = 1
})
print(result)

Functions

mistralai_chat

Generate a chat completion using a MistralAI model. Send a list of messages (with roles "system", "user", or "assistant") and receive a model-generated response. Use temperature to control creativity (0 = deterministic, 1 = creative).

Operation
Write write
Full name
mistralai.mistralai_chat
ParameterTypeRequiredDescription
model string yes The model to use (e.g., "mistral-large-latest", "mistral-small-latest", "open-mistral-nemo").
messages array yes Array of message objects with "role" (system, user, assistant) and "content" fields. Example: [{"role": "user", "content": "Hello"}]
temperature number no Sampling temperature between 0.0 and 1.0. Lower values are more deterministic, higher values more creative. Default: 0.7.
max_tokens integer no Maximum number of tokens to generate in the response.

mistralai_create_embedding

Generate text embeddings using a MistralAI embedding model. Converts text into numerical vectors for semantic search, similarity comparison, or clustering. Supports single strings or arrays of strings.

Operation
Write write
Full name
mistralai.mistralai_create_embedding
ParameterTypeRequiredDescription
model string yes The embedding model to use (e.g., "mistral-embed").
input string yes The text to embed. Can be a single string or JSON array of strings for batch embedding.

mistralai_list_models

List all models available in your MistralAI account. Returns model IDs, creation timestamps, and capabilities. Use this to discover which models you can use for chat completions or embeddings.

Operation
Read read
Full name
mistralai.mistralai_list_models
ParameterTypeRequiredDescription
No parameters.

mistralai_finetune

Create a fine-tuning job on MistralAI. Upload training data and select a base model to create a custom fine-tuned model. The job runs asynchronously — check the returned job ID for status updates.

Operation
Write write
Full name
mistralai.mistralai_finetune
ParameterTypeRequiredDescription
model string yes The base model to fine-tune (e.g., "open-mistral-7b", "open-mixtral-8x7b").
training_files array yes Array of training file IDs (previously uploaded to MistralAI).
hyperparameters string no JSON-encoded hyperparameters object (e.g., {"n_epochs": 3, "learning_rate": 0.0001}).
suffix string no Suffix for the fine-tuned model name.

mistralai_list_agents

List all MistralAI agents in your account. Returns agent IDs, names, models, and descriptions. Agents are AI assistants with custom instructions and tools.

Operation
Read read
Full name
mistralai.mistralai_list_agents
ParameterTypeRequiredDescription
No parameters.

mistralai_create_agent

Create a new MistralAI agent. Specify a name, model, and instructions to define how the agent should behave. Agents are persistent AI assistants that can be used for conversations with custom personalities and capabilities.

Operation
Write write
Full name
mistralai.mistralai_create_agent
ParameterTypeRequiredDescription
name string yes The agent name (e.g., "Support Bot", "Code Assistant").
model string yes The model to use for the agent (e.g., "mistral-large-latest", "mistral-small-latest").
instructions string yes System instructions that define the agent's behavior, personality, and constraints.
description string no A short description of what the agent does.

mistralai_get_current_user

Get information about the currently authenticated MistralAI user. Returns account details, subscription tier, and usage information.

Operation
Read read
Full name
mistralai.mistralai_get_current_user
ParameterTypeRequiredDescription
No parameters.