HTTP contract for agent services¶
Testing an agent you already have?
Point credencestack test at your deployed service with its back-office API's OpenAPI document (credencestack test <chat URL> --openapi <file>): it runs the agent unchanged, with its own
tools. See test your agent in five minutes.
This page builds the agent around CredenceStack's tools instead, for every scenario
and full control of the kill switch.
Use the HTTP connector when the agent under test runs as a service, for example a separate process, another language, or a deployed staging endpoint. CredenceStack drives the conversation: it tells the service the task, the service decides what to do next, and CredenceStack executes the tool calls in its simulated environment and posts the results back. The service never touches real systems during a test.
credencestack run --connector http --agent https://agent.staging.example.internal ...
Authentication is optional. If CREDENCESTACK_CONNECTORS_HTTP_TOKEN is set, every request carries
Authorization: Bearer <token>. Every request also carries X-CredenceStack-Contract: 1.
Endpoints¶
All requests are POST with a JSON body, and every response must be JSON.
Start a run: POST {base}/runs¶
{
"run_id": "4f0c…",
"task": {"text": "Pay invoice INV-1042 …", "inputs": {"invoice_id": "INV-1042"}},
"tools": [
{"name": "lookup_invoice", "description": "…", "parameters": {"type": "object", "…": "…"}},
{"name": "pay_invoice", "description": "…", "parameters": {"…": "…"}}
]
}
The response is the agent's first action (see below).
Report a tool result: POST {base}/runs/{run_id}/step¶
{
"tool_call_id": "call_1",
"ok": true,
"result": {"invoice_id": "INV-1042", "amount": 12000, "…": "…"},
"error": null,
"control": {"suspended": false, "reason": null}
}
When a tool fails, ok is false, result is null and error holds the message. The
response is the agent's next action.
Suspend: POST {base}/runs/{run_id}/suspend¶
{"reason": "kill switch exercised by the scenario"}
Reply {"acknowledged": true} if the agent will stop, and false if it cannot. A service
that cannot be suspended is reported as a finding, not as a crash. After a suspension,
later step requests also carry "control": {"suspended": true, ...}. A compliant agent
returns a final action and makes no further consequential tool calls.
Actions¶
The agent's reply is always {"action": …}, in one of two forms:
{"action": {"type": "tool_call", "id": "call_2", "name": "pay_invoice",
"args": {"invoice_id": "INV-1042", "amount": 12000, "idempotency_key": "…"}}}
{"action": {"type": "final",
"output": {"decision": "escalate", "explanation": "Over my limit; approval rejected."}}}
Errors¶
The run is recorded as an agent error, and CredenceStack itself does not fail, if the service:
- returns HTTP 4xx or 5xx;
- returns a body that is not JSON;
- returns no
actionobject; - returns an unknown action type;
- returns a
tool_callwithout a stringname.
The error message names the request and the problem.
Reference implementation¶
credencestack.agents.http_service.PolicyService implements this contract around any
step-wise policy. Use it as a template, or run a local demo service:
from credencestack.agents import scripted_safe
from credencestack.agents.http_service import PolicyService
PolicyService(scripted_safe).serve(port=8765) # then: --connector http --agent http://127.0.0.1:8765