Skip to main content

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.slug
  • application.id
  • variant.slug
  • variant.id
  • variant.version
  • environment.slug
  • environment.id
  • environment.version

The values should be the slug, id, or version of the application, variant, and environment respectively.

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