strahl.client¶
client
¶
Client helpers for registering tools and analyzing OpenAI tool-call transcripts.
The module-level functions are backed by a process-global default client. Use
the :class:Strahl class directly when you need isolated state, such as one
client per tenant, agent, or test case.
Strahl
¶
An isolated Strahl client holding tool registrations and role labels.
Each instance has its own HTTP client and registration state. The instance methods mirror the module-level helpers, so code can move between the default client and a dedicated client with only the receiver changed.
Create a client with empty registration state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Optional Strahl API key. This is equivalent to calling
:meth: |
None
|
base_url
|
str
|
Base URL for the Strahl API. |
'https://api.strahl.io'
|
from_default
classmethod
¶
Create a new client from the module-level default client's state.
Tools and role labels are copied by value into a fresh client. Later mutations on either client are independent.
copy
¶
Return an independent snapshot of this client.
tool
¶
tool(
name: str | None = None,
*,
requires: Label,
produces: Label,
params: Mapping[str, Label] | None = None,
) -> Callable[[F], F]
Register the decorated Python callable as a Strahl tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional registered tool name. Defaults to the callable's
|
None
|
requires
|
Label
|
Label assigned to the tool call and, by default, each tool-call argument. |
required |
produces
|
Label
|
Label assigned to the tool result. |
required |
params
|
Mapping[str, Label] | None
|
Optional per-parameter requirement labels. |
None
|
add_tool
¶
add_tool(
*,
fn: dict | Callable,
requires: Label,
produces: Label,
params: Mapping[str, Label] | None = None,
name: str | None = None,
)
Register a Python callable or OpenAI function tool schema.
requires labels the pending tool call and is also the default label
for each argument. produces labels the tool result for later turns.
Use params when individual arguments need labels that differ from
the tool-level requires label.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the tool name is already registered, if |
set_role_labels
¶
set_role_labels(labels: Mapping[str, Label])
Set static labels for transcript message roles.
Supported roles are "system", "developer", "user", and
"assistant". Role labels must be static because they apply to a
message role rather than a particular tool-call argument.
analyze
¶
analyze(messages: list[MessageLike]) -> AnalysisResult
Analyze an OpenAI-style transcript ending in pending tool calls.
Call this after an assistant response requests tool calls and before
executing those tools. HTTP failures are propagated as
:class:httpx.HTTPStatusError.
set_role_labels
¶
set_role_labels(labels: Mapping[str, Label])
Set role labels on the default client.
tool
¶
tool(
name: str | None = None,
*,
requires: Label,
produces: Label,
params: Mapping[str, Label] | None = None,
)
Register a tool on the default client via decorator.
add_tool
¶
add_tool(
*,
fn: dict | Callable,
requires: Label,
produces: Label,
params: Mapping[str, Label] | None = None,
name: str | None = None,
)
Register a Python callable or OpenAI function tool schema on the default client.
analyze
¶
analyze(messages: list[MessageLike]) -> AnalysisResult
Analyze an OpenAI-style transcript with the default client.