Python decorators
The supported launch path uses two decorators. Both work with regular and async def functions.
@st.agent
Put @st.agent on the entry point for one agent run. It creates the root span and gives nested provider and tool spans the same trace ID.
@st.agent
def research(query: str) -> str:
return answer(query)
@st.agent(name="billing-agent", tags=["billing"])
async def bill(account_id: str) -> str:
return await process(account_id)@st.tool
Put @st.tool on the Python function that performs tool work. The decorator records the actual duration, status, arguments, return value, and propagated exception.
@st.tool
def search_docs(query: str) -> list[str]:
return index.search(query)
@st.tool(name="publish_report")
async def publish_report(report_id: str) -> bool:
return await reports.publish(report_id)@st.tool observes execution. It does not run Guard by itself. Provider-proposed tools are evaluated in supported patched provider loops; direct calls need an explicit st.guard() check when they require enforcement.
Provider patches retain proposal IDs to link a later tool-result continuation. They do not infer execution duration, success, output, or errors from the gap between model calls.
Parameters
| Parameter | Default | Description |
|---|---|---|
name | Function name | Span and tool label. |
tags | None | String tags stored in span metadata. |
metadata | None | Additional serializable span metadata. |
capture_input | True | Record function arguments. |
capture_output | True | Record the return value. |
Both bare and configured forms work:
@st.agent
def run() -> None: ...
@st.tool(name="lookup", capture_output=False)
def lookup(account_id: str) -> dict: ...Errors
When the wrapped function raises or an async task is cancelled, Staso marks the span as an error, records available exception details, and propagates the original exception or cancellation.
Capture controls
Set capture_input=False or capture_output=False to omit that decorator payload. This is capture suppression, not content redaction.
The local flag is combined with the global category policy:
| Decorator payload | Required global category |
|---|---|
@st.agent or @st.trace arguments | request |
@st.tool arguments | tool_arguments |
| Any decorated return value | output |
| Caller-provided decorator metadata | request |
A local False always wins. When effective input capture is off, the wrapper does not materialize function arguments for telemetry. Error prose is omitted whenever the effective content policy is not fully enabled; the exception class and error status remain operational.