Reference Prompt Versions
You can link a span to an application, variant, and environment by calling ag.tracing.store_refs().
Applications, variants, and environments can be referenced by their slugs, versions, and commit IDs (for specific versions).
Basic usage
You can link a span to an application and variant like this:
import agenta as ag
@ag.instrument(spankind="workflow")
def generate(country: str):
prompt = f"What is the capital of {country}"
formatted_prompt = prompt.format(country=country)
completion = client.chat.completions.create(
model='gpt-4',
messages=[
{'role': 'user', 'content': formatted_prompt},
],
)
ag.tracing.store_refs(
{
"application.slug": "capital-app",
"environment.slug": "production",
}
)
return completion.choices[0].message.content
Available reference keys
ag.tracing.store_refs() takes a dict with keys from:
application.slugapplication.idvariant.slugvariant.idvariant.versionenvironment.slugenvironment.idenvironment.version
The values should be the slug, id, or version of the application, variant, and environment respectively.
Why link traces?
Linking traces to applications and variants allows you to:
- Filter traces by application, variant, or environment in the UI
- Compare performance across different variants
- Track production behavior by environment
- Create test sets from production traces with proper context
Next steps
- Learn how to redact sensitive data
- Understand how to track costs
- Explore distributed tracing across services
