Skip to main content

Overview

LangChain is a popular framework for building LLM applications. Agent Diff provides native tool support for LangChain agents.

Installation

pip install agent-diff "langchain[anthropic]"

Basic Integration

from agent_diff import AgentDiff, PythonExecutorProxy, create_langchain_tool
from langchain.agents import create_agent

# Initialize client and environment
client = AgentDiff()
env = client.init_env(
    templateService="slack",
    templateName="slack_default",
    impersonateUserId="U01AGENBOT9"
)

# Create executor and LangChain tool
python_executor = PythonExecutorProxy(env.environmentId, base_url=client.base_url)
python_tool = create_langchain_tool(python_executor)

# Create agent
agent = create_agent(
    model="claude-sonnet-4-5-20250929",
    tools=[python_tool],
    system_prompt="""You are a Slack assistant. Use the execute_python tool to 
    interact with Slack API at https://slack.com/api/*. 
    Authentication is handled automatically."""
)

# Start run and execute
run = client.start_run(envId=env.environmentId)
result = agent.invoke({
    "messages": [{"role": "user", "content": "Post 'Hello World!' to #general"}]
})

# Get diff
diff = client.diff_run(runId=run.runId)
print(diff.diff['inserts'])

# Cleanup
client.delete_env(envId=env.environmentId)

With Bash Executor

from agent_diff import BashExecutorProxy, create_langchain_tool
from langchain.agents import create_agent

bash_executor = BashExecutorProxy(env.environmentId, base_url=client.base_url)
bash_tool = create_langchain_tool(bash_executor)

agent = create_agent(
    model="claude-sonnet-4-5-20250929",
    tools=[bash_tool],
    system_prompt="Use execute_bash with curl to interact with Slack API at https://slack.com/api/*"
)

Running Evaluations

from agent_diff import AgentDiff, PythonExecutorProxy, create_langchain_tool
from langchain.agents import create_agent

client = AgentDiff()

# Get test suite
suites = client.list_test_suites(name="Slack Bench")
suite = client.get_test_suite(suites.testSuites[0].id, expand=True)

results = []

for test in suite.tests:
    env = client.init_env(testId=test.id)
    run = client.start_run(envId=env.environmentId, testId=test.id)
    
    # Create tool and agent
    executor = PythonExecutorProxy(env.environmentId, client.base_url)
    tool = create_langchain_tool(executor)
    
    agent = create_agent(
        model="claude-sonnet-4-5-20250929",
        tools=[tool],
        system_prompt="Use execute_python to interact with Slack at https://slack.com/api/*"
    )
    
    # Run
    agent.invoke({
        "messages": [{"role": "user", "content": test.prompt}]
    })
    
    # Evaluate
    result = client.evaluate_run(runId=run.runId)
    results.append({"test": test.name, "passed": result.passed})
    
    client.delete_env(envId=env.environmentId)

# Print results
for r in results:
    print(f"{'✓' if r['passed'] else '✗'} {r['test']}")

Next Steps