FormaSL — Agent Provider Realization Contract (MP)
Status: STABLE
Authority: DOWNSTREAM PROVIDER REALIZATION CONTRACT — multi-provider SDK realization of the agent provider seam
Ratification: owner dispatch 2026-09-30 — “AUTHORIZED IN PRINCIPLE / R2 CEILING”, conditioned on W0 materializing four binding corrections and six closed decisions (verbatim in §12)
Parent: ../FORMASL.md
Depends on: ARCHITECTURE.md, docs/forma-agent-harness-synthesis-package/HARNESS-CONTRACT.md (E7 provider seam, IC-6.1..6.6), docs/forma-agent-correspondence-remediation-v0.1/CAMPAIGN-STATE.md (CR-01..CR-05 correspondence laws)
Role: freeze how external LLM providers are realized behind the existing CognitiveProvider seam (crates/harness-cognitive/src/cognitive.rs), admit an external SDK (genai) as a permitted realization mechanism, and freeze credentials, correspondence, configuration and failure laws — WITHOUT changing the seam’s semantics, the harness authority limits, the authored JSON-in-text model protocol, or any normative/trust boundary.
1. Core decision
A provider realization is a REALIZATION-PLAN mechanism. A different
realization may change transport, wire dialect, backend and cost without
redefining any semantic contract. The typed exposure boundary of the
agent provider is the CognitiveProvider seam — the trait, the
ProviderExchange, the conformance under the CognitiveOutputContract and
the ProviderExchangeObserved durable carrier — never a particular
network stack. A realization may own its HTTP/TLS stack entirely
(external SDK included). Implementation is a realization of this
contract; it is never a retroactive source of seam meaning.
Gate-2 and Gate-3 — previously named only in code comments
(crates/forma-agent/src/provider.rs) — are MATERIALIZED here as law:
- Gate-2 (exposure/transport): exactly one provider exchange per
cognitive round crosses the seam; it enters as
ProviderExchange(Payload{raw_class, raw_payload}or typedUnavailable(MechanismOutcome)) and is recorded durably asProviderExchangeObserved{request_digest, response_digest}. No hidden retry. Failure is typed mechanism outcome, never a semantic conclusion (IC-6.4). A realization may use its own network stack; the seam remains the single typed boundary. - Gate-3 (credentials): credentials enter a realization ONLY through
formasl-trustresolution (explicit, env-var-named, snapshot-resolved, fail-closed on unmapped/inline references). No realization, and no SDK beneath it, may consult ambient environment for credentials, invent a secret, or make a secret durable (record/log/error bytes carry digests and host identities only).
The rejected shape:
SDK → its own env-var fallback / its own retry / its own tool-calling
semantics → seam meaning silently redefined by the vendor library
2. What changes and what cannot change
Changed by this contract:
- A new product crate
crates/forma-agent-provider-sdkis admitted as the ONLY workspace unit that depends on the external SDKgenai(pinned) and realizesCognitiveProviderfor additional wire dialects (OpenAI-compatible, Anthropic native in v0.1). - New
--provider sdk:<kind>values on the forma-agent CLI. - A non-secret provider profile file, loaded ONLY when
--profile <path>is explicitly passed (no default-file discovery in v0.1). - One additive durable carrier in
harness-record:EntryPayload::RealizationBound(§6).
Frozen (changing any of these is R3 / hard-stop, §10):
- the
CognitiveProvidertrait andProviderExchangesemantics; - conformance (
conform,CognitiveOutputContract) semantics; - the authored JSON-in-text model protocol
(
answer / need_evidence / proposal / final); - governance/exposure enforcement and the governed floor as sole writer;
- all existing realizations (
loopback, hand-rolledopenai) — the hand-rolled path stays the differential anchor and is NOT replaced by the SDK path even after the SDK path is verified; coexistence is part of this campaign’s witness (DC-MP-7).
3. Binding corrections (frozen implementation decisions)
These corrections were set by the owner dispatch and are BINDING:
DC-MP-1 (SDK dependency and client injection). The dependency line is
genai = { version = "=0.6.5", default-features = false, features = ["rustls-tls"] }. Our own reqwest::Client is injected via
ClientBuilder::with_reqwest(reqwest::Client) (the 0.6.5 method name).
The client is built with ClientBuilder::no_proxy(), connect_timeout()
and timeout() set explicitly, TLS backend rustls only.
DC-MP-2 (codec generalization). encode_exchange(content) is
preserved byte-identical (always emits raw_class = "openai/v1") and a
new encode_exchange_with_class(raw_class, content) is introduced; the
original delegates to the general one. OpenAI-compatible realizations
emit openai/v1; the Anthropic realization emits anthropic/v1. The
JSON protocol fields and their semantics are identical across classes.
DC-MP-3 (realization identity carrier). The durable carrier is
RealizationBound { provider_kind: String, model: String, endpoint_identity: String } where endpoint_identity is the SHA-256
hex digest of the canonical endpoint string
scheme://host:effective_port/base_path — effective_port is the
explicit port, else the scheme default (http=80, https=443); base_path
is normalized (empty → /; otherwise starts with /, no trailing
slash); userinfo, query and fragment are REJECTED (fail-closed), not
stripped. Host bytes are recorded only through the digest (and may be
additionally echoed as host-only text; never userinfo).
DC-MP-4 (request correspondence under an SDK). request_digest
MUST be computed over the adapter-owned canonical logical envelope — the
deterministic serialization of exactly the material request fields
(model, system, user) the adapter hands the SDK — BEFORE conversion to
any SDK type. The SDK’s internal serialization order, serde behavior or
wire framing is never part of the correspondence identity. The envelope
must be constructible and digestible without any network or SDK type.
DC-MP-5 (TLS gate scoping). The mandatory TLS gate
(cargo tree -i openssl empty) runs over the new crate’s dependency
closure. The workspace-wide cargo tree -i openssl is recorded as an
observation while it remains empty, and must never be attributed to this
crate a foreign crate’s future OpenSSL dependency.
DC-MP-6 (default-free model). For sdk:<kind> realizations the
model is REQUIRED in the profile. There is no silent model default on
the SDK path (the hand-rolled path’s "gpt-4o-mini" fallback stays as
is — it is frozen legacy behavior).
4. Realization requirements (any realization, any dialect)
- One exchange per round; typed failure only; no hidden retry.
- Provider output enters ONLY as
ProviderExchange::Payload{raw_class, raw_payload}carrying the codec envelope (answer, optionaltool_proposal); conformance proves shape only; candidates carry no standing. - Exposure is request-scoped and rendered from the authored app
(
ExposureSurface/TOOL_NAME_MAPPING); enforcement stays post-hoc through governance. - Credentials only per Gate-3 (§1); for credentialless servers the
profile explicitly declares no
credential-env, and no Authorization material of any kind is emitted. - Errors and logs are scrubbed: no secret material, no Authorization header bytes; endpoint host and response body prefix (≤300 chars) are the maximum diagnostic payload.
5. Credential law (operational)
Resolution order is fixed:
profile.provider.<kind>.credential-env --names--> env var
→ formasl-trust EnvironmentCredentialSource::snapshot([that one key])
→ resolve BEFORE any network contact
→ Resolved → AuthData for the SDK request (memory only)
→ Unresolved → typed Unavailable(ProviderFailure), zero connections
absent credential-env (declared credentialless) → no auth material
The adapter’s target resolver ALWAYS supplies target + auth for every request, so the SDK’s own default env-var resolution is never consulted. Witness MP-OB-05 plants a foreign sentinel env var and proves it never crosses.
6. Correspondence and durability carriers
- Per exchange:
ProviderExchangeObserved{request_digest, response_digest}whererequest_digest= SHA-256 over the canonical logical envelope (DC-MP-4) andresponse_digest= SHA-256 over the raw response content text observed. This is evidence, not a store. - Per session start (sdk realizations):
EntryPayload::RealizationBound{ provider_kind, model, endpoint_identity }per DC-MP-3. - Resume compatibility: the resolved profile realization identity MUST
equal the record’s
RealizationBound; mismatch is a typed rejection naming both identities (never a silent continuation under a foreign realization).
7. Failure mapping (frozen table)
| Condition | Outcome |
|---|---|
| credential resolution fails (before network) | ProviderFailure |
| connection refused / DNS / unreachable | NetworkFailure |
client timeout() elapsed | TimedOut |
| HTTP status ≥ 400 | ProviderFailure |
| response body non-JSON / missing expected content shape | ProviderFailure |
| target/profile resolution defect (misconfig) | ProviderFailure |
| cancelled | Cancelled |
Every row above is a typed MechanismOutcome inside
ProviderExchange::Unavailable and maps (existing law) to the E4 attempt
reasons — never to a semantic conclusion.
8. Obligations and witnesses
| ID | Obligation | Witness |
|---|---|---|
| MP-OB-01 | genai named only in forma-agent-provider-sdk (+ forma-agent feature wiring) | static grep gate test |
| MP-OB-02 | pinned dependency line per DC-MP-1 | Cargo.toml assertion test |
| MP-OB-03 | reqwest client: no_proxy + explicit timeouts + rustls only | source gate + MP-OB-15 |
| MP-OB-04 | credential resolved BEFORE network; missing → typed failure, zero connections | stub negative counting connections |
| MP-OB-05 | all auth via formasl-trust; SDK default env resolution never consulted | foreign-sentinel-env test |
| MP-OB-06 | scrub law: no secret in record bytes / logs / errors | sentinel grep over record + stderr |
| MP-OB-07 | canonical logical envelope digest per DC-MP-4; stable across constructions | digest-stability test + source gate |
| MP-OB-08 | encode_exchange byte-identical legacy; encode_exchange_with_class generalization per DC-MP-2 | golden equality test |
| MP-OB-09 | admitted_class per realization; cross-class payload → typed WrongPayloadClass | conformance negative test |
| MP-OB-10 | RealizationBound additive carrier recorded at session start (sdk path) | record roundtrip test |
| MP-OB-11 | resume/realization mismatch → typed rejection naming both | negative test |
| MP-OB-12 | legacy loopback and openai realizations behaviorally unchanged | digest-pinned differential + full legacy suite green |
| MP-OB-13 | failure table §7 exact; one connection per exchange | stub 401/500/non-JSON/timeout tests asserting outcome + connection count |
| MP-OB-14 | profile: explicit --profile only, fail-closed unknown fields, versioned example file | parser negatives + example-parses test |
| MP-OB-15 | TLS gate on the new crate closure: cargo tree -i openssl empty | gate script recorded in evidence |
| MP-OB-16 | kill -9 during an sdk exchange → resume: lock stolen, serials distinct, no duplicate accepted effect | subprocess kill witness |
| MP-OB-17 | provider-substitution battery: loopback / hand-rolled-openai-stub / sdk-openai-stub yield equivalent loop terminals for identical model content | three-realization test |
| MP-OB-18 | offline CI: every network-touching test #[ignore]; offline suite green | full cargo nextest run --workspace --profile ci |
9. Stage map (FIOP; R0–R2, no owner round-trips)
W0 this contract + branch-local ACTIVE-WP (this commit; no code)
W1 profile parser + RealizationBound + --profile + resume gate
W2 adapter crate + openai-compatible realization + differential vs
hand-rolled over an in-process stub + typed failure negatives
W3 anthropic native realization (anthropic/v1) + loop admitted_class
extension + differential/negatives over anthropic stub
W4 credentials end-to-end (trust → AuthData; MP-OB-04/05/06 witnesses)
W5 adversarial (kill -9, substitution battery, TLS gate) + full
workspace gates + REAL ollama reaccreditation (manual, #[ignore];
executed only if a server is live, otherwise recorded NOT EXECUTED
with the exact reason)
Terminality: the campaign is NOT terminal while any MP-OB row lacks its witness or any W-stage deliverable is open (Terminal completeness rule).
10. R3 / hard-stop conditions
Stop and return to the owner (no repair improvisation) if implementation demonstrates that any of the following is necessary:
- changing
CognitiveProvider/ProviderExchange/conformance semantics; - harness authority changes beyond the additive
RealizationBoundcarrier; - the SDK needing credentials outside formasl-trust resolution, or needing a wire protocol other than the authored JSON-in-text envelope;
- editing
ARCHITECTURE.mdor any normative foundation; - hidden retry, streaming, or native tool-calling entering v0.1 scope.
11. Non-collapses preserved
Realization != Semantic contract (plan-level substitution law)
ProviderRequest != CompletionRequest (IC-6.2)
ProviderOutput -/-> SemanticStanding (candidates carry no standing)
RecordedOccurrence != Truth (digests are evidence, not store)
CredentialReference != SecretMaterial (Gate-3 non-collapse)
Attempt != Commit (E4 law unchanged)
12. Ratification record (owner verbatim, 2026-09-30)
Dispatch: “CAMPAIGN-FORMA-AGENT-MULTIPROVIDER-v0.1 — AUTHORIZED IN
PRINCIPLE / R2 CEILING”, conditioned on W0 materializing: (1) the exact
0.6.5 API (with_reqwest, feature rustls-tls, pinned dep line); (2)
the W3 codec correction (DC-MP-2); (3) the realization identity carrier
upgrade (DC-MP-3); (4) the canonical logical envelope for
request_digest (DC-MP-4). Closed decisions: (a) contract-downstream
not architecture-edit; (b) --provider sdk:<kind> with the hand-rolled
path intact and coexisting as differential anchor; (c) explicit
--profile with no implicit default discovery, example file versioned
in the new crate, fail-closed unknown fields; (d) provider-sdk default
ON, network tests #[ignore]; (e) v0.1 dialects = OpenAI-compatible +
native Anthropic; (f) session_root default stays /tmp with profile
override. Operational: no time-window estimate in the dispatch; WP size
is delimited by cohesion and terminality. PUSH NOT AUTHORIZED. Landing
owner-gated.
13. Four-NO (closure)
substitute a cheaper mechanism for the contracted one? NO — every
MP-OB-01..18 witness executed against the real mechanism: the SDK
realization drives the REAL loop, the REAL product binary (kill/resume
via the CLI), the REAL trust resolution, and a REAL model exchange
(ollama/qwen2.5-coder:7b) with authored completion; stubs exist only
as in-test transport fixtures where a deterministic oracle is required.
weaken any frozen semantic of §2? NO — the seam
(CognitiveProvider/ProviderExchange/conformance), the authored
JSON-in-text protocol, the completion law and governance are untouched;
the codec generalization (DC-MP-2) is byte-identical for the legacy
class (golden witness); loopback and hand-rolled openai coexist
unchanged (substitution battery + legacy suite green).
touch a forbidden surface (§10)? NO — no
ARCHITECTURE.md edit (the contract is downstream, as dispatched); no
harness-authority change beyond the additive RealizationBound carrier;
the SDK never resolves credentials or env on its own (ModelSpec::Target
bypass + sentinel witness); no hidden retry/streaming/native
tool-calling entered v0.1.
claim unverified evidence? NO — every gate
count in the ledger comes from executed nextest/clippy/tree runs in
this branch's commits; the workspace gate is recorded in the closure
commit; the TLS observation (str0m/openssl, foreign) is labeled an
observation, not an adapter property.