Skip to main content
POST
/
api
/
v2
/
sessions
/
{id}
/
tool_results
Send tool results
curl --request POST \
  --url https://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "kind": "<string>",
  "tool_req": {},
  "error": "<string>",
  "origin": "<string>",
  "type": "<string>",
  "results": [
    {}
  ]
}
'
import requests

url = "https://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results"

payload = {
"kind": "<string>",
"tool_req": {},
"error": "<string>",
"origin": "<string>",
"type": "<string>",
"results": [{}]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
kind: '<string>',
tool_req: {},
error: '<string>',
origin: '<string>',
type: '<string>',
results: [{}]
})
};

fetch('https://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results', 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://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'kind' => '<string>',
'tool_req' => [

],
'error' => '<string>',
'origin' => '<string>',
'type' => '<string>',
'results' => [
[

]
]
]),
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://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results"

payload := strings.NewReader("{\n \"kind\": \"<string>\",\n \"tool_req\": {},\n \"error\": \"<string>\",\n \"origin\": \"<string>\",\n \"type\": \"<string>\",\n \"results\": [\n {}\n ]\n}")

req, _ := http.NewRequest("POST", 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.post("https://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"kind\": \"<string>\",\n \"tool_req\": {},\n \"error\": \"<string>\",\n \"origin\": \"<string>\",\n \"type\": \"<string>\",\n \"results\": [\n {}\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://agp.eu.hcompany.ai/api/v2/sessions/{id}/tool_results")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"kind\": \"<string>\",\n \"tool_req\": {},\n \"error\": \"<string>\",\n \"origin\": \"<string>\",\n \"type\": \"<string>\",\n \"results\": [\n {}\n ]\n}"

response = http.request(request)
puts response.read_body
Sends results for pending custom tool calls. When the agent calls a custom tool, the session waits on awaiting_tool_results; posting a result for every pending call lets the run continue. The SDK run helpers call this endpoint for you. Results are relayed to the agent as-is: the API doesn’t check tool_req.id against the pending calls, so echo the request faithfully. Settling a call on a paused session leaves it paused; resume it separately. Returns 202 Accepted. The result is delivered asynchronously: the agent resumes once every pending call has one.

Path parameters

id
string
required
The session ID.

Request body

Send either a single settled call or a batch. A single call is a tool_result on success or an error_event on failure, discriminated by kind, and a batch wraps a list of them. Each call echoes back the full pending tool_req from pending_tool_calls ({ tool_name, args, id }) rather than only its id.

Tool result (success)

kind
string
required
Must be "tool_result".
tool_req
object
required
The pending tool call this answers, echoed back from pending_tool_calls: { tool_name, args, id }.
result
JSON-serializable tool output, shown to the model.

Tool error (failure)

kind
string
required
Must be "error_event".
error
string
required
Error text shown to the model.
origin
string
required
Component that produced the error, e.g. "custom_tools".
tool_req
object
required
The pending tool call this answers, echoed back from pending_tool_calls.

Batch

type
string
required
Must be "batch".
results
array
required
Array of tool_result and/or error_event objects.

Examples

Send a single result

curl -X POST https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/tool_results \
  -H "Authorization: Bearer $HAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "tool_result",
    "tool_req": { "tool_name": "lookup_order", "args": { "order_id": "A1" }, "id": "call_1" },
    "result": "shipped"
  }'
from hai_agents import Client, ToolRequest, ToolResultEvent

client = Client()

client.sessions.send_session_tool_results(
    session_id,
    request=ToolResultEvent(
        tool_req=ToolRequest(tool_name="lookup_order", args={"order_id": "A1"}, id="call_1"),
        result="shipped",
    ),
)
import { HaiAgentsClient } from "hai-agents";

const client = new HaiAgentsClient();

await client.sessions.sendSessionToolResults({
  id: sessionId,
  body: {
    kind: "tool_result",
    toolReq: { toolName: "lookup_order", args: { order_id: "A1" }, id: "call_1" },
    result: "shipped",
  },
});

Send a batch of results

curl -X POST https://agp.eu.hcompany.ai/api/v2/sessions/$SESSION_ID/tool_results \
  -H "Authorization: Bearer $HAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "batch",
    "results": [
      {"kind": "tool_result", "tool_req": {"tool_name": "lookup_order", "args": {}, "id": "call_1"}, "result": "shipped"},
      {"kind": "error_event", "error": "Order not found", "origin": "custom_tools", "tool_req": {"tool_name": "lookup_order", "args": {}, "id": "call_2"}}
    ]
  }'
from hai_agents import Client, ErrorEvent, ToolRequest, ToolResultBatch, ToolResultEvent

client = Client()

client.sessions.send_session_tool_results(
    session_id,
    request=ToolResultBatch(
        results=[
            ToolResultEvent(
                tool_req=ToolRequest(tool_name="lookup_order", args={}, id="call_1"),
                result="shipped",
            ),
            ErrorEvent(
                error="Order not found",
                origin="custom_tools",
                tool_req=ToolRequest(tool_name="lookup_order", args={}, id="call_2"),
            ),
        ],
    ),
)
import { HaiAgentsClient } from "hai-agents";

const client = new HaiAgentsClient();

await client.sessions.sendSessionToolResults({
  id: sessionId,
  body: {
    type: "batch",
    results: [
      {
        kind: "tool_result",
        toolReq: { toolName: "lookup_order", args: {}, id: "call_1" },
        result: "shipped",
      },
      {
        kind: "error_event",
        error: "Order not found",
        origin: "custom_tools",
        toolReq: { toolName: "lookup_order", args: {}, id: "call_2" },
      },
    ],
  },
});

Errors

StatusCause
404Session not found, or you don’t have access.
409The session already finished; its pending calls were resolved at run end.
422Malformed request body.