Expand description
The standard client a Host uses to run model rounds, list models, and search the web through the PromptForge Gateway.
GatewayBroker is the [harness::InferenceBroker] that a Host using
the Gateway passes to Harness::new. It runs every model round on a
GatewayChat under the Engine’s default run limits, and it lists the
Gateway’s models through fetch_model_catalog. A Host that shows a
reply as it forms runs the round through
GatewayBroker::chat_streaming, which hands each StreamDelta to
the Host’s callback as it arrives.
GatewayChat is the HTTP client that sends a Chat effect’s round
to one Gateway URL. It presents the Gateway’s shared bearer key when
built with one. Every request streams: the Gateway’s
/chat/completions endpoint answers with server-sent events (SSE).
GatewayChat::complete sends the request body and reads the stream
within the client’s byte cap and per-receive timeout. It calls the
caller’s delta callback as each piece arrives and returns the one
completion the round produced. fetch_model_catalog fetches the
Gateway’s model list as a typed ModelCatalog. The client holds no
credential except the Gateway’s shared key. The model vendor’s
credential stays in the Gateway.
GatewaySearch is the [harness_web::SearchProvider] that a Host
using the Gateway supplies for web search. It sends each search through
the Gateway’s /tools/web_search relay with a 30-second deadline and
maps the reply into the provider’s results. The search vendor’s
credential also stays in the Gateway.
Under the client sits the OpenAI chat-completions wire code. It turns a
round into a request body, a streamed reply into a
Completion, and a failed response
into the CompletionError the round fails with.
build_request_bodybuilds the JSON body that every round sends.read_completion_streamreads a streamed reply from aChunkSourcethe caller supplies, up to its[DONE]sentinel and within a byte cap. It forwards each live delta, assembles the stream into one completion, and checks that turn against one strict set of rules.read_body_cappedreads, within a byte cap, a body that the caller decodes whole.escape_controlscuts a backend error body to a length limit and escapes its control characters.classify_http_failureturns a failure status and its body into aCompletionErrorof the matching kind.classify_stream_errordoes the same for an error envelope that arrives inside the stream.
The client, or another broker, owns the connection and supplies the wire code’s chunks and clock.
§Invariants
- Every
CompletionandToolCallis built through the Engine’s public validating constructors, so the Engine’s model-independent reply checks run on every decoded turn. - A Gateway bearer key is never written to logs,
Debug,Display, or error text. - A backend error body is bounded and control-escaped before it is
kept. A chat round keeps it only in the opt-in
CompletionError::detail, and a search keeps it in theGatewaySearchErrormessage. - A client sends requests without a key only when the caller builds it
with
GatewayChat::keyless, which does not check the endpoint’s address, or whenGatewayChat::from_envfinds no key for a loopback URL. A client built withGatewayChat::disabledalso holds no key, but it sends no requests.
Structs§
- Completion
Error - The error a model round or a catalog fetch fails with.
- Gateway
Broker - A model broker that sends the Harness’s model rounds to the PromptForge Gateway and lists the Gateway’s models.
- Gateway
Chat - A client that sends chat completion requests to one gateway URL.
- Gateway
Endpoint - A validated base URL for the gateway’s OpenAI-compatible API (its
/v1root). - Gateway
Search - The [
SearchProvider] a Host supplies to search the web through the Gateway. - Gateway
Search Error - An error from a failed Gateway web search, with its kind, a message, and the underlying cause when there is one.
- Secret
String - A bearer credential whose contents never appear in
DebugorDisplayoutput or in logs.
Enums§
- Completion
Error Kind - The kind of failure a model round ended with.
- Gateway
Config Error - The error returned when setting up the gateway client fails because an environment variable, the bearer key, or the endpoint URL is missing or unusable.
- Gateway
Search Error Kind - Which side of a Gateway web search failed.
- Secret
Error - The reason constructing a
SecretStringfailed. - Stream
Delta - One piece of a streamed model reply, delivered as it arrives.
Traits§
- Chunk
Source - A response body that a transport supplies one chunk at a time.
Functions§
- build_
request_ body - Builds the JSON body of a streaming chat-completions request.
- classify_
http_ failure - Classifies a failed HTTP response into a
CompletionError. - classify_
stream_ error - Classifies an error envelope that arrives inside a 200 response stream.
- escape_
controls - Truncates a backend response body and escapes its control characters so it is safe to show in a diagnostic.
- fetch_
model_ catalog - Fetches a [
ModelCatalog] from the Gateway’s/modelsendpoint. - read_
body_ capped - Reads a whole response body from
source, refusing it once it would exceedcapbytes. - read_
completion_ stream - Reads a streamed model reply from
sourceand assembles it into a [Completion].