API Reference¶
Auto-generated from docstrings in the agent_grammar package.
Top-level exports¶
These three symbols are re-exported from agent_grammar and form the surface
you'll touch when annotating a test:
workflow¶
workflow ¶
Decorate a pytest test function to record its HTTP/boundary steps.
The recorder is stashed on the wrapper as _agent_grammar_recorder so the
pytest plugin can collect it after the test passes.
Data flow between steps is not declared by hand; the captured request and response payloads of each step are rendered verbatim (with secrets redacted) so the consuming agent can wire calls together from ground truth.
Source code in src/agent_grammar/testing/decorators.py
step_boundary¶
step_boundary ¶
Mark a non-HTTP step (e.g. database query, external service).
Source code in src/agent_grammar/testing/decorators.py
AgentTestClient¶
AgentTestClient ¶
Bases: TestClient
Drop-in replacement for starlette.testclient.TestClient.
When invoked inside a @workflow-decorated test, each request is
captured as an HttpStep and appended to the active recorder.
Data models¶
HttpStep
dataclass
¶
HttpStep(method: str, path: str, request_json: Any | None, status_code: int, response_json: Any | None, domain: str = 'Core Service')
WorkflowRecord
dataclass
¶
Serving (agent_grammar.serve.fastapi)¶
GrammarRouter¶
GrammarRouter ¶
Return a FastAPI/Starlette router that serves the compiled markdown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
Path to the compiled workflows.md asset. |
required |
reload
|
bool
|
If True, re-read the file on every request (dev mode). If False, cache contents in memory at construction time. |
False
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ImportError
|
If FastAPI is not installed. |
Source code in src/agent_grammar/serve/fastapi.py
AgentTelemetryMiddleware¶
AgentTelemetryMiddleware ¶
Bases: BaseHTTPMiddleware
Detect requests bearing X-Agent-Grammar-Workflow and report them.
The middleware never raises from the telemetry callback — failures are logged and swallowed so business traffic is unaffected.
Source code in src/agent_grammar/serve/fastapi.py
CLI (agent_grammar.cli)¶
The CLI is a Click command group with a
single subcommand, export-agent-docs. See
Configuration → CLI
for flag-by-flag documentation.
export_agent_docs ¶
export_agent_docs(base_url: str, api_version: str, output_dir: str, workflows_path: str | None, platforms: tuple[str, ...]) -> None
Generate platform-specific system prompts for API consumers.