Skip to content

Types

These are the shapes of the data Ailoy takes and returns. In Python they are TypedDicts in ailoy.types, in Node.js plain objects typed in types.d.ts, and in Rust structs and enums in the crate. Keys are snake_case in every language. Fields marked optional may be missing.

Import the types

from ailoy.types import Message, MessageOutput, ToolDesc

Message

One message in a conversation. See Messages.

Field Type Description
role Role Who wrote the message.
contents list of Part The content.
thinking string, optional The model’s reasoning. Assistant messages only.
tool_calls list of FunctionPart, optional Tools the model wants to call. Assistant messages only.
id string, optional On a tool message, the id of the call it answers.
signature string, optional The provider’s signature for thinking, sent back unchanged.

Build a message in code

In Python a message is a dict:

query = {"role": "user", "contents": [{"type": "text", "text": "What's in this image?"}, image_part]}

Examples

A user message:

{ "role": "user", "contents": [{ "type": "text", "text": "What's the weather in Seoul?" }] }

An assistant message that calls a tool:

{
"role": "assistant",
"contents": [{ "type": "text", "text": "Let me check the weather." }],
"tool_calls": [
{ "type": "function", "id": "call_01HZX2", "function": { "name": "get_weather", "arguments": { "city": "Seoul" } } }
]
}

The tool’s result, answering the call by its id:

{ "role": "tool", "id": "call_01HZX2", "contents": [{ "type": "value", "value": 12.3 }] }

Reasoning: thinking and signature

Models that reason before answering return that reasoning in thinking, on assistant messages. Some providers also return a signature for it. If you keep a conversation yourself and pass it back, through history or LangModel.infer, keep both fields unchanged: providers that sign reasoning reject a message whose thinking was changed. An agent’s own history already keeps them.

Role

"system", "user", "assistant" or "tool". Rust: ailoy::message::Role.

Part

One piece of content. The type field says which kind.

type Other fields Description
"text" text: string Plain text.
"image" image: { type: "url", url: string } or { type: "embedded", mime_type: string, data: bytes } An image by URL, or as bytes (bytes in Python, Buffer in Node.js).
"function" id: string, function: { name: string, arguments: any } A tool call.
"value" value: any Any JSON value, such as a tool result.

Read the parts

texts = [p["text"] for p in output["message"]["contents"] if p["type"] == "text"]

Image

The image field of an image part is one of:

type Fields Description
"url" url: string An image on the web, by its address.
"embedded" mime_type: string, data: bytes The image’s bytes: bytes in Python, Buffer in Node.js. mime_type is such as "image/png".

These are UrlImage and EmbeddedImage in Python and Node.js. See Send an image or other content.

MessageOutput

What Agent.run and LangModel.infer return: one complete message.

Field Type Description
message Message The message.
finish_reason FinishReason Why the model stopped.
usage TokenUsage, optional Token counts, when the provider reports them.

MessageDeltaOutput

What Agent.run_stream and LangModel.infer_stream return: a piece of a message.

Field Type Description
delta MessageDelta The piece: role (optional), contents (list of part pieces), tool_calls (list of part pieces), and optional id, thinking and signature. Each part piece has a type ("text", "function", "value", "image" or "null") and the fields received so far.
finish_reason FinishReason or null Set on the last piece of a message.
usage TokenUsage or null Token counts, on the last piece when the provider reports them.

MessageDelta and PartDelta

delta is a MessageDelta. Its fields are those of a Message, each holding only what arrived in this piece:

Field Type Description
role Role, optional Set on the first piece of a message.
contents list of PartDelta Pieces of the content parts.
tool_calls list of PartDelta Pieces of tool calls.
thinking string, optional A piece of the reasoning.
id, signature string, optional As on Message.

A PartDelta has a type ("text", "function", "value", "image" or "null") and the fields of that part received so far. To rebuild the message, join the pieces in order: append thinking and text, and continue the last part or tool call while the next piece has the same type. When you only need the finished messages, use run, which does this for you.

To show the reply as it’s written, print each text piece:

async for piece in agent.run_stream(query):
for part in piece["delta"]["contents"]:
if part["type"] == "text":
print(part["text"], end="", flush=True)

FinishReason

Field Type Description
type string "stop" (the model finished), "length" (it hit its output limit), "tool_call" (it asked for tools) or "refusal" (it refused).
reason string, optional With "refusal", why.

TokenUsage

Field Type Description
input_tokens int All input tokens the call processed, cached or not.
output_tokens int Tokens the model wrote.
cache_creation_input_tokens int, optional The part of input_tokens written to a prompt cache.
cache_read_input_tokens int, optional The part of input_tokens read from a prompt cache.

ToolDesc

A tool’s description, as the model sees it.

Field Type Description
name string The name the model calls the tool by.
description string, optional What the tool does. The model reads this to decide when to call it.
parameters JSON schema The tool’s arguments.
returns JSON schema, optional What the tool returns.

Rust: ailoy::tool::ToolDesc, built with ToolDescBuilder.

AgentSpec

An agent’s definition as JSON, for Agent.from_spec.

Field Type Description
model string The model, <org>/<name>.
instruction string, optional The system prompt.
tools list of ToolDesc, optional The agent’s tools, including any sandbox tools.
model_options LangModelOptions, optional Thinking effort and output schema.
web_search_engines list of WebSearchEngine, optional The engines for web_search.
skills list of strings, optional Skill folders, as paths in the sandbox.
memory Memory, optional The memory folder on this machine, and its size limit.

Rust: ailoy::agent::AgentSpec, which also has builder methods (AgentSpec::new(model).instruction(...)) and .sandbox_tools().

LangModelOptions

Field Type Description
thinking_effort "low", "medium" or "high", optional How much the model reasons. If unset, the model’s default.
output_schema JSON schema, optional A schema the model’s answers must match.

Backend

"cli", "api", "bedrock", "openrouter" or "self-hosted". Rust: ailoy::model::Backend. See Backends.

LangModelServer

Your own model server for one org, passed to set_lang_model_provider.

Field Type Description
backend "self-hosted" Always "self-hosted".
base_url string The server’s URL, including /v1, such as "http://localhost:11434/v1".
api_key string, optional The key, if the server requires one.
models map of string to string, optional Maps model names to the ids the server uses, such as {"Llama-3.3-70B-Instruct": "llama3.3:70b"}.

Rust: LangModelServer::new(base_url)?.with_api_key(...).with_model(name, id).

WebSearchEngine

"Bing", "Brave", "DuckDuckGo", "Google", "Mojeek", "Naver", "Startpage", "Yahoo" or "Yandex". Rust: ailoy::tool::WebSearchEngineKind.

Memory

The memory folder in an AgentSpec, and the settings of AgentBuilder.memory.

Field Type Description
dir string A folder on this machine. Ailoy keeps the notes in MEMORY.md in it.
limit int, optional The most characters the notes can hold. Default 3,000.

Rust: ailoy::agent::Memory, created with Memory::new(dir).with_limit(n).

ThinkingEffort

"low", "medium" or "high": how much a model reasons before it answers. Used in LangModelOptions and AgentBuilder.thinking_effort.

Value

Any value JSON can hold: a string, number, boolean, null, list or object. Tool arguments, tool results and JSON schemas are Values. Any in Python, any in Node.js, and ailoy::datatype::Value in Rust.

Use plain Python values: dict, list, str, int, float, bool and None.

schema = {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}