Skip to main content

Environment Management

Create Environment

from agent_diff import AgentDiff

client = AgentDiff()

env = client.init_env(
    templateService="slack",
    templateName="slack_default",
    impersonateUserId="U01AGENBOT9",
    ttlSeconds=3600
)

print(f"Environment ID: {env.environmentId}")
print(f"API URL: {env.environmentUrl}")
print(f"Schema: {env.schemaName}")
print(f"Expires: {env.expiresAt}")
Parameters:
ParameterTypeRequiredDescription
templateServicestringYes*Service type: "slack" or "linear"
templateNamestringYes*Template to clone from (e.g., "slack_default")
impersonateUserIdstringYes*User ID the agent will act as
testIdUUIDYes*Test ID (alternative to template params)
ttlSecondsintNoAuto-cleanup time in seconds (default: 1800)
Either provide templateService + templateName + impersonateUserId, OR provide testId (which includes all template info).

Delete Environment

client.delete_env(envId=env.environmentId)
Always delete environments when done to free up resources. Environments auto-expire after TTL, but explicit cleanup is faster.

Run Management

Start Run

# Start a run (takes "before" snapshot)
run = client.start_run(envId=env.environmentId)

print(f"Run ID: {run.runId}")
print(f"Status: {run.status}")  # "running"
Parameters:
ParameterTypeRequiredDescription
envIdstringYesEnvironment ID to run in
testIdUUIDNoTest ID (for evaluation with assertions)

Get Diff

After your agent has made changes:
# Compute diff between before and after states
diff = client.diff_run(runId=run.runId)

print("New records:", diff.diff['inserts'])
print("Modified records:", diff.diff['updates'])
print("Deleted records:", diff.diff['deletes'])
Parameters:
ParameterTypeRequiredDescription
runIdstringYesRun ID to compute diff for

Evaluate Run

If you have a test with assertions:
# Run assertions against the diff (uses test suite's expectedOutput)
result = client.evaluate_run(runId=run.runId)

print(f"Passed: {result.passed}")
print(f"Score: {result.score}")
Or pass assertions explicitly (no test suite needed):
# Evaluate with explicit expected output
result = client.evaluate_run(
    runId=run.runId,
    expectedOutput={
        "assertions": [{
            "diff_type": "added",
            "entity": "issues",
            "where": {"title": {"contains": "Fix bug"}}
        }],
        "ignore_fields": {
            "global": ["id", "created_at", "updated_at"]
        }
    }
)
Parameters:
ParameterTypeRequiredDescription
runIdstringYesRun ID to evaluate
expectedOutputobjectNoExplicit assertions (if not using test suite)
Expected Output Structure:
FieldTypeDescription
assertionsarrayList of assertions to check
ignore_fieldsobjectFields to ignore: {"global": [...], "entity": [...]}
strictbooleanFail on extra changes (default: false)

Get Results

results = client.get_results_for_run(runId=run.runId)

print(f"Status: {results.status}")
print(f"Failures: {results.failures}")
print(f"Diff: {results.diff}")
Parameters:
ParameterTypeRequiredDescription
runIdstringYesRun ID to get results for

Template Management

List Templates

templates = client.list_templates()

for t in templates.templates:
    print(f"- {t.name} ({t.service})")
    print(f"  Description: {t.description}")
    print(f"  Visibility: {t.visibility}")

Get Template

from uuid import UUID

template = client.get_template(UUID("your-template-uuid"))
print(f"Template: {template.name}")
print(f"Service: {template.service}")

Create Custom Template

# First, create and customize an environment
env = client.init_env(
    templateService="slack",
    templateName="slack_default"
)

# Make customizations via API...
# (add users, channels, etc.)

# Save as new template
custom = client.create_template_from_environment(
    environmentId=env.environmentId,
    service="slack",
    name="my_custom_template",
    description="Customized workspace with extra channels",
    visibility="private"
)

print(f"Created template: {custom.templateId}")
Parameters:
ParameterTypeRequiredDescription
environmentIdstringYesEnvironment ID to create template from
servicestringYesService type: "slack" or "linear"
namestringYesName for the new template
descriptionstringNoDescription of the template
visibilitystringNo"public" or "private" (default: "private")

Test Suite Management

List Test Suites

# List all visible suites
suites = client.list_test_suites()

# Filter by name
suites = client.list_test_suites(name="Slack Bench")

# Filter by visibility
suites = client.list_test_suites(visibility="public")

for suite in suites.testSuites:
    print(f"- {suite.name} (ID: {suite.id})")

Get Test Suite with Tests

# Get suite with expanded test details
suite = client.get_test_suite(suite_id, expand=True)

print(f"Suite: {suite.name}")
for test in suite.tests:
    print(f"  - {test.name}: {test.prompt}")

Get Individual Test

test = client.get_test(test_id="your-test-uuid")
print(f"Test: {test.name}")
print(f"Prompt: {test.prompt}")

Create Test Suite

suite = client.create_test_suite(
    name="My Agent Tests",
    description="Custom tests for my Slack agent",
    visibility="private"
)

print(f"Created suite: {suite.id}")
Parameters:
ParameterTypeRequiredDescription
namestringYesName for the test suite
descriptionstringYesDescription of the suite
visibilitystringNo"public" or "private" (default: "private")

Add Tests to Suite

# Add a single test
test = client.create_test(suite.id, {
    "name": "Post message",
    "prompt": "Post 'Hello' to #general",
    "type": "actionEval",
    "environmentTemplate": "slack_default",
    "impersonateUserId": "U01AGENBOT9",
    "expected_output": {
        "assertions": [{
            "diff_type": "added",
            "entity": "messages",
            "where": {"message_text": {"contains": "Hello"}}
        }],
        "ignore_fields": {
            "global": ["ts", "message_id", "created_at"]
        }
    }
})

# Add another test
test2 = client.create_test(suite.id, {
    "name": "Add reaction",
    "prompt": "React with 👍 to the latest message",
    "type": "actionEval",
    "environmentTemplate": "slack_default",
    "impersonateUserId": "U01AGENBOT9",
    "expected_output": {
        "assertions": [{
            "diff_type": "added",
            "entity": "reactions"
        }]
    }
})

Run Test from Suite

# Get a specific test
test = suite.tests[0]

# Create environment for this test
env = client.init_env(testId=test.id)

# Start run
run = client.start_run(envId=env.environmentId, testId=test.id)

# Run your agent with test.prompt
# ...

# Evaluate against test assertions
result = client.evaluate_run(runId=run.runId)

print(f"Test: {test.name}")
print(f"Passed: {result.passed}")
print(f"Failures: {result.failures}")

Complete Example

from agent_diff import AgentDiff
import requests

client = AgentDiff()

# 1. Create environment
env = client.init_env(
    templateService="slack",
    templateName="slack_default",
    impersonateUserId="U01AGENBOT9"
)

# 2. Start run
run = client.start_run(envId=env.environmentId)

# 3. Make API calls to the isolated environment
response = requests.post(
    f"{env.environmentUrl}/chat.postMessage",
    json={
        "channel": "C01GENERAL99",
        "text": "Hello from my agent!"
    }
)
print(f"API Response: {response.json()}")

# 4. Get diff
diff = client.diff_run(runId=run.runId)

print("\n📊 Changes detected:")
for insert in diff.diff['inserts']:
    print(f"  + [{insert['__table__']}] {insert.get('message_text', insert)}")

# 5. Cleanup
client.delete_env(envId=env.environmentId)
print("\n✓ Environment cleaned up")

Next Steps