The client's quickstart
The client, stalwart_agents.client, in five minutes. To build an agent instead, start with
Build an agent.
Install the package, set your key, and activate the licensed runtime once:
pip install stalwart-agents
export QLS_API_KEY=qls_live_...
stalwart licence activate
The runtime reads each turn and checks each tool call on this machine. Stalwart's hosted API does neither.
Route a conversation
from stalwart_agents.client import Client
client = Client()
chat = client.session("desk", catalogue=catalogue) # your tools: `stalwart catalogue import` writes them
plan = chat.read("show me the stock in depot HB-7")
for step in plan.steps:
if step.kind == "tool":
print("call", step.selection.tool, dict(step.selection.arguments))
elif step.kind == "ask":
print("ask", step.selection.question)
Each step names the rule that made it in step.decided_by. A plan whose outcome is
declined runs nothing.
Stream a long solve
for event in client.verify_guardrail("policy.co", "execute_transfer_funds", "is_authenticated",
profile="enumerate", stream=True):
print(event.type, event.data)
The iterator ends at the job's terminal event. A dropped connection is resumed where it
stopped; if streaming keeps failing through your network, the iterator yields one
stream_degraded event and carries on by polling.
Test your routing offline
from stalwart_agents.client.testing import replay
with Client(api_key="unused", transport=replay(cassette_path)) as offline:
with open("policy.co", encoding="utf-8", newline="") as policy:
rules = offline.compile_rulebook(policy.read()) # answered from the cassette
plan = offline.session("desk", catalogue=catalogue, rulebook=rules).read("show me the stock")
Record the cassette once against the service, with stalwart_agents.client.testing.record(path)
as the transport. A replay answers the service's calls from the cassette -- a rulebook compiled,
a solve -- and a call that was not recorded raises CassetteMiss. Plans and tool checks are
never in a cassette: the runtime answers them on this machine with no request, so they are as
exact offline as online.