# Written by the agent's code, never by a model; merge by key keeps the other fields
written = conversation.agent_state.put({"offer": {"plan": "familia-plus", "status": "shown"}})
if not written.stored:
print(written.reason) # over_cap or not_declared_field, never an exception// Written by the agent's code, never by a model; merge by key keeps the other fields
const written = await convo.agentState.put({ offer: { plan: "familia-plus", status: "shown" } });
if (!written.stored) console.log(written.reason); // over_cap or not_declared_field, never a rejectioncurl --request PUT \
--url https://{space}.{region}.api.niadra.com/v1/agent-state \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent": "<string>",
"body": {},
"scope": {
"id": "<string>"
},
"if_version": 1,
"subject": {
"value": "<string>",
"scope": "<string>"
}
}
'const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent: '<string>',
body: JSON.stringify({}),
scope: {id: '<string>'},
if_version: 1,
subject: {value: '<string>', scope: '<string>'}
})
};
fetch('https://{space}.{region}.api.niadra.com/v1/agent-state', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{space}.{region}.api.niadra.com/v1/agent-state",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'agent' => '<string>',
'body' => [
],
'scope' => [
'id' => '<string>'
],
'if_version' => 1,
'subject' => [
'value' => '<string>',
'scope' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{space}.{region}.api.niadra.com/v1/agent-state"
payload := strings.NewReader("{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://{space}.{region}.api.niadra.com/v1/agent-state")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{space}.{region}.api.niadra.com/v1/agent-state")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"stored": true,
"version": 123,
"reason": "over_cap"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"detail": "<string>",
"request_id": "<string>",
"type": "about:blank"
}Gravar a memória de trabalho
O estado de trabalho de um agente, escrito pelo código dele e nunca por um modelo: cas troca o estado inteiro numa versão, merge_by_key troca os campos nomeados. Acima do teto responde stored: false, nunca erro. Funcionalidade agent_state.
# Written by the agent's code, never by a model; merge by key keeps the other fields
written = conversation.agent_state.put({"offer": {"plan": "familia-plus", "status": "shown"}})
if not written.stored:
print(written.reason) # over_cap or not_declared_field, never an exception// Written by the agent's code, never by a model; merge by key keeps the other fields
const written = await convo.agentState.put({ offer: { plan: "familia-plus", status: "shown" } });
if (!written.stored) console.log(written.reason); // over_cap or not_declared_field, never a rejectioncurl --request PUT \
--url https://{space}.{region}.api.niadra.com/v1/agent-state \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent": "<string>",
"body": {},
"scope": {
"id": "<string>"
},
"if_version": 1,
"subject": {
"value": "<string>",
"scope": "<string>"
}
}
'const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent: '<string>',
body: JSON.stringify({}),
scope: {id: '<string>'},
if_version: 1,
subject: {value: '<string>', scope: '<string>'}
})
};
fetch('https://{space}.{region}.api.niadra.com/v1/agent-state', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{space}.{region}.api.niadra.com/v1/agent-state",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'agent' => '<string>',
'body' => [
],
'scope' => [
'id' => '<string>'
],
'if_version' => 1,
'subject' => [
'value' => '<string>',
'scope' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{space}.{region}.api.niadra.com/v1/agent-state"
payload := strings.NewReader("{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://{space}.{region}.api.niadra.com/v1/agent-state")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{space}.{region}.api.niadra.com/v1/agent-state")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent\": \"<string>\",\n \"body\": {},\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"if_version\": 1,\n \"subject\": {\n \"value\": \"<string>\",\n \"scope\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"stored": true,
"version": 123,
"reason": "over_cap"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"detail": "<string>",
"request_id": "<string>",
"type": "about:blank"
}Autorizações
nia_sk_...
Corpo
Uma escrita do estado de trabalho de um agente, pelo código dele e nunca por um modelo: cas troca o estado inteiro em if_version (0 quando ele ainda não pode existir); merge_by_key troca cada campo de primeiro nível que nomeia e remove um campo escrito exatamente como {"$delete": true}.
1 - 256cas, merge_by_key A que um estado de trabalho pertence. O id viaja no corpo, nunca numa URL: um id de conversa pode parecer um telefone.
Show child attributes
Show child attributes
x >= 0O cliente de que o estado trata, quando o escopo não o nomeia: apagar o cliente e o pacote de dados dele acham o estado por aqui.
Show child attributes
Show child attributes

