Where do these values come from? The templateName and impersonateUserId must match data in the template. See Environments & Templates for available templates and user IDs (e.g., U01AGENBOT9 is the agent bot user in slack_default).
Copy
from agent_diff import AgentDiff# For hosted version, pass explicility or add environment variablesclient = AgentDiff( base_url="https://api.agentdiff.dev", api_key="ak_your_api_key" # From dashboard)# Create isolated Slack environmentenv = client.init_env( templateService="slack", templateName="slack_default", impersonateUserId="U01AGENBOT9", # User your agent will act as ttlSeconds=3600 # Auto-cleanup after 1 hour)print(f"Environment: {env.environmentId}")print(f"API URL: {env.environmentUrl}")
from agent_diff import PythonExecutorProxy, create_openai_toolfrom agents import Agent, Runner# Start run (takes "before" snapshot)run = client.start_run(envId=env.environmentId)# Create code executor that intercepts API callspython_executor = PythonExecutorProxy(env.environmentId, base_url=client.base_url, api_key=client.api_key)python_tool = create_openai_tool(python_executor)# Your agent with the toolagent = Agent( name="Slack Assistant", instructions="""Use execute_python tool to interact with Slack API at https://slack.com/api/*. Authentication is handled automatically.""", tools=[python_tool])# Run the agentresponse = await Runner.run(agent, "Post 'Hello World!' to #general")# Get the diff (what changed)diff = client.diff_run(runId=run.runId)print("Inserts:", diff.diff['inserts']) # New messages createdprint("Updates:", diff.diff['updates']) # Records modifiedprint("Deletes:", diff.diff['deletes']) # Records removed# Cleanupclient.delete_env(envId=env.environmentId)