marvin.beta.observability.openai
This module enables tracing Marvin agent calls to OpenAI’s observability dashboard.
When running inside Prefect flows/tasks, it automatically captures runtime context
(flow_run_id, task_run_id, etc.) and sends it as request metadata.
Installation
uv add “marvin[prefect]” Or with pip: pip install “marvin[prefect]“Usage
The main function isobservable(). Call it on an agent inside a Prefect task
to automatically capture the current runtime context:
What gets captured
When you callobservable(agent) inside a Prefect run, the following metadata
is automatically sent to OpenAI:
prefect.flow_run.id- UUID of the flow runprefect.flow_run.name- Human-readable name (e.g., “happy-tiger”)prefect.flow_run.flow_name- Name of the flow functionprefect.task_run.id- UUID of the task run (if inside a task)prefect.task_run.name- Human-readable task run nameprefect.task_run.task_name- Name of the task functionprefect.deployment.id- Deployment UUID (if deployed)prefect.deployment.name- Deployment name (if deployed)
Viewing in OpenAI
After running your flow, view the requests at: https://platform.openai.com/logs Filter by any of the metadata fields above, e.g.:- Filter by
prefect.flow_run.idto see all AI calls from one flow run - Filter by
prefect.task_run.task_nameto see calls from a specific task type
Advanced: Custom metadata
If you need to add additional metadata beyond what Prefect provides:Note
This module is in beta and only works with OpenAI models. The metadata is sent via OpenAI’s stored completions feature (store=True).Functions
get_prefect_context
observable() instead.
observable
openai_request_kwargs
store and metadata keys for OpenAI API calls.
Parent Module:
observability