Skip to content

Write and check a connector

A connector connects one kind of agent system to CredenceStack's simulated back office. If your framework is not supported, you can write a connector and check it with the conformance kit: ten fixed public scenarios that test the connector, not the agent, including one financial-crime and one KYC scenario that prove the connector binds each scenario's own tool set.

The contract

A connector implements credencestack.connectors.protocol.Connector:

Method What it must do
capabilities() Return Capabilities(step, suspend, human_in_the_loop), truthfully.
start(task, tools, env) Build the agent for this episode. Every tool the agent calls must run through env.call(name, args): that is where faults, injections and the trace happen.
run_until_done(max_steps) Run the agent to its final answer, a dict with decision and explanation. Never raise for agent failures: set RunHandle.error.
step() Advance one action, or raise NotImplementedError (and say step=False).
suspend(reason) Stop the agent and return True, or return False if it cannot be stopped. CredenceStack calls it from inside a tool call when a scenario pulls the kill switch.

Patterns the built-in connectors follow:

  • Tools: wrap each ToolSpec (name, description, JSON Schema) in the framework's native tool type; the wrapper calls env.call and returns the result as JSON, or the ToolError message as a tool error.
  • Events: record each model response as a model_call event with env.record("model_call", result=..., meta={"model": ..., "usage": ...}), using the framework's own hooks, callbacks or middleware. Do not patch framework internals.
  • Approvals: if the framework pauses for human approval, answer the pause with env.review(..., source="hitl"), which records approval_request and approval_decision and applies the scenario's reviewer. Otherwise the agent uses the request_approval tool.
  • Suspension: keep a shared flag. Refuse tool calls in the tool wrapper once it is set, and use the framework's own stop or cancel facility where there is one.
  • Multi-agent: set env.actor to the acting agent's name; tool calls then carry meta.actor. Record handoffs as handoff events with meta.handoff_to.
  • Offline model: provide a scripted model in the framework's own model interface (or its testing facility) that replays credencestack.agents.scripted_safe, so the kit runs with no API key.

Register it

Add an ConnectorSpec to credencestack/connectors/registry.py (name, extra, framework package, targeted version, builder, default conformance agent), and an optional extra in pyproject.toml. Import the framework only inside your connector module, so the core package works without it.

Run the kit

credencestack connectors check --connector <name> --agent my_package.agent:build \
    --model credencestack:scripted --epochs 3 --out conformance/<name>.json

It runs PAY-002, PAY-012, PAY-011, ADV-001, RES-001, RES-004, RES-006 and PAY-019 and checks:

Check Passes when
capture every tool call has its arguments and exactly one result or error; the ledger never holds a payment without a traced pay_invoice call
order sequence numbers are contiguous, simulated time never goes back, calls and results alternate, one final event closes the trace
approvals where a safe agent must ask, an approval_request is followed by an approval_decision
faults the scenario's injected fault appears as a fault event
injection the injected text reaches a tool result
suspension if suspend() returned True, no consequential call followed the signal; if False, that is reported, not failed
capabilities suspend matches what suspend() returned; native approvals imply human_in_the_loop; with step=True, stepping gives the same trace as run_until_done()
errors no episode ended with a connector or agent error
determinism with the scripted model, the same seed gives the same trace (turn off with --no-determinism for real models)
tool_set each scenario's own tool families are bound, and at least one call uses them
otel with the [otel] extra, the first pass emits a valid OpenTelemetry span tree: one scenario span, one invoke_agent span, an execute_tool span per tool call, a chat span per model call, and the fault, control-signal and approval events; not applicable without the extra

The kit needs a cooperative agent: use your safe reference agent. A naive agent that ignores the kill switch fails the suspension check even when the connector is right.

Badges

Verdict Badge
every check passes, suspension supported Conformant
every check passes, suspend() returns False Conformant, suspension unsupported
any check fails not conformant

Commit the JSON report with your connector. credencestack connectors list shows each connector's committed verdict.