Docs / Contact / sdks/nano-agent/api-reference
Nano Agent: API Reference
The Nano Agent communicates via JSON messages over a Unix socket. This page documents every supported message type and the socket protocol.
For shell-based testing, see the tendrl CLI client, which wraps these message types as subcommands.
Socket Protocol#
- Open a
AF_UNIX/SOCK_STREAMconnection to the socket - Write one or more JSON messages (UTF-8 encoded)
- Optionally read the response (for
wait: true,msg_check,state_read) - Close the connection when you're done
The socket is stateless: a single connection can carry multiple messages, so you can either open a fresh connection per message or keep one open and stream many. When you send a request that returns data (wait: true, msg_check, state_read), read its response before sending the next message on the same connection.
Socket Paths#
| Platform | Path |
|---|---|
| Linux/macOS | /var/lib/tendrl/tendrl_agent.sock |
| Windows | C:\ProgramData\tendrl\tendrl_agent.sock |
Message Types#
publish#
Send data to Contact. Messages are queued and batched by default.
{
"msg_type": "publish",
"data": { ... },
"dest": "entity-name",
"context": {
"tags": ["tag1", "tag2"],
"wait": false,
"entity": "entity-id"
}
}
| Field | Required | Description |
|---|---|---|
msg_type |
Yes | Must be "publish" |
data |
Yes | JSON object or string payload |
dest |
No | Target entity name |
context.tags |
No | Routing tags (max 10) |
context.wait |
No | true to wait for server response |
context.entity |
No | Entity identifier |
heartbeat#
Send system metrics. Sent directly (not batched).
{
"msg_type": "heartbeat",
"data": {
"mem_free": 1024.0,
"mem_total": 4096.0,
"disk_free": 50000.0,
"disk_size": 100000.0
}
}
| Field | Type | Description |
|---|---|---|
mem_free |
float | Free memory (MB) |
mem_total |
float | Total memory (MB) |
disk_free |
float | Free disk space (MB) |
disk_size |
float | Total disk space (MB) |
state_new#
Create or replace the entity's state table (PUT).
{
"msg_type": "state_new",
"data": { "key": "value" }
}
state_update#
Merge data into the existing state table (PATCH).
{
"msg_type": "state_update",
"data": { "key": "new_value" }
}
state_read#
Retrieve the entity's current state table.
{
"msg_type": "state_read"
}
Response:
{
"statusTable": { "key": "value" }
}
msg_check#
Poll for incoming messages.
{
"msg_type": "msg_check",
"context": { "limit": 5 }
}
Response (array of messages):
[
{
"msg_type": "publish",
"data": { ... },
"tags": ["tag1"],
"source": "account:region:entity:name",
"timestamp": "2025-01-15T10:30:45Z"
}
]
Returns HTTP status 204 (as a string) when no messages are pending.
Error Responses#
All errors follow this format:
{
"status": "error",
"message": "Description of the error"
}
| Error Message | Cause |
|---|---|
Queue full, try again later |
Message queue at capacity |
Too many tags provided; maximum is 10 |
More than 10 tags in context |
Unknown message type |
msg_type not recognized |
Batching Behavior#
The agent batches messages using dynamic sizing based on system load:
- Batch size adjusts between
minBatchSizeandmaxBatchSizebased on CPU and memory usage - Flush interval ensures messages don't wait longer than the configured interval (default 250ms)
- Heartbeats are always sent immediately (never batched)
- Wait messages (
context.wait: true) are sent immediately and the response is returned to the caller
The agent handles all communication with Contact over HTTPS on your behalf. Your application interacts with the agent through the local Unix socket interface documented above; you never call Contact's HTTP API directly.
Tendrl