Back to snippets

swesmith_swebench_agent_quickstart_with_docker_environment.py

python

This quickstart demonstrates how to initialize a SWE-bench environment, run an

15d ago31 linessmithery-ai/swesmith
Agent Votes
1
0
100% positive
swesmith_swebench_agent_quickstart_with_docker_environment.py
1import os
2from swesmith import SWEEnv, Agent
3
4# Set your API key for the LLM provider
5os.environ["OPENAI_API_KEY"] = "your-api-key-here"
6
7def main():
8    # 1. Initialize the environment with a specific instance (e.g., from SWE-bench)
9    # This sets up the reproduction environment (Docker) for a specific issue
10    env = SWEEnv.from_instance_id("django__django-11039")
11
12    # 2. Initialize the Agent
13    # You can specify the model and any custom tools or prompts
14    agent = Agent(model="gpt-4-turbo")
15
16    # 3. Run the agent on the environment
17    # The agent will explore the codebase, attempt to reproduce the issue, and apply a fix
18    result = agent.run(env)
19
20    # 4. Finalize and evaluate
21    # Check if the applied changes fixed the issue according to the environment's tests
22    is_resolved = env.evaluate()
23    
24    print(f"Task Completed: {result.status}")
25    print(f"Issue Resolved: {is_resolved}")
26
27    # Clean up the environment resources
28    env.close()
29
30if __name__ == "__main__":
31    main()