100XZX001 commited on
Commit
794782d
Β·
verified Β·
1 Parent(s): 9909ce6

Delete Demo.py

Browse files
Files changed (1) hide show
  1. Demo.py +0 -76
Demo.py DELETED
@@ -1,76 +0,0 @@
1
- # Cell 11: Demo – Realistic Agent Behaviour (with failure, improvement, author negotiation)
2
- # This demo shows the agent reasoning, trying a wrong fix, seeing tests fail, then improving.
3
- # It uses the environment’s tools and the author’s feedback.
4
-
5
- print("\n" + "="*70)
6
- print("🎬 DEMO: Code Review Agent – Learning to Fix Bugs")
7
- print("="*70)
8
-
9
- env = CodeReviewEnv()
10
- env.set_task("easy")
11
- obs = env.reset()
12
-
13
- print(f"\nπŸ“Œ TASK: {obs.pr_title}")
14
- print(f"πŸ“ DESCRIPTION: {obs.pr_description}")
15
- print(f"\nπŸ’» INITIAL CODE:\n{obs.code_snippet}\n")
16
-
17
- # ------------------------------------------------------------------
18
- # Step 1: Agent runs tests to see the failure
19
- # ------------------------------------------------------------------
20
- print("πŸ”§ STEP 1: Agent runs tests (run_tests)")
21
- action = RunTests()
22
- obs, reward, done, _ = env.step(action)
23
- print(f"πŸ’¬ Test output:\n{obs.last_tool_output[:200]}...")
24
- print(f"πŸ† Reward: {reward.value:.3f}\n")
25
-
26
- # ------------------------------------------------------------------
27
- # Step 2: Agent inspects the code and decides on a (wrong) fix
28
- # ------------------------------------------------------------------
29
- print("πŸ”§ STEP 2: Agent inspects the code and attempts a fix (WRONG)")
30
- # Simulate a bad fix (e.g., adding a print instead of fixing null check)
31
- bad_fix = "def get_user(id):\n print('debug')\n return users[id]"
32
- action = ProposeFix(fix_code=bad_fix)
33
- obs, reward, done, _ = env.step(action)
34
- print(f"πŸ’¬ Proposed fix:\n{bad_fix}")
35
- print(f"πŸ’¬ Test results:\n{obs.last_tool_output[:200]}...")
36
- print(f"πŸ† Reward: {reward.value:.3f} (low – tests failed)\n")
37
-
38
- # ------------------------------------------------------------------
39
- # Step 3: Agent consults documentation to learn
40
- # ------------------------------------------------------------------
41
- print("πŸ”§ STEP 3: Agent queries documentation (query_docs: 'null check')")
42
- action = QueryDocs(query_topic="null check")
43
- obs, reward, done, _ = env.step(action)
44
- print(f"πŸ’¬ Docs response:\n{obs.last_tool_output}")
45
- print(f"πŸ† Reward: {reward.value:.3f}\n")
46
-
47
- # ------------------------------------------------------------------
48
- # Step 4: Agent writes a comment to negotiate with the author
49
- # ------------------------------------------------------------------
50
- print("πŸ”§ STEP 4: Agent comments to convince the author")
51
- action = WriteComment(comment_text="I checked the docs – a missing key will raise KeyError. We should add a condition: if id in users: return users[id] else: handle missing key.")
52
- obs, reward, done, _ = env.step(action)
53
- # Author's response is stored in env._comments
54
- author_resp = [c for c in env._comments if "Author" in c][-1] if env._comments else ""
55
- print(f"πŸ’¬ Agent comment delivered")
56
- print(f"πŸ’¬ Author response: {author_resp}")
57
- print(f"πŸ† Reward: {reward.value:.3f}\n")
58
-
59
- # ------------------------------------------------------------------
60
- # Step 5: Agent proposes the correct fix
61
- # ------------------------------------------------------------------
62
- print("πŸ”§ STEP 5: Agent proposes the correct fix")
63
- good_fix = "def get_user(id):\n if id in users:\n return users[id]"
64
- action = ProposeFix(fix_code=good_fix)
65
- obs, reward, done, _ = env.step(action)
66
- print(f"πŸ’¬ Proposed fix:\n{good_fix}")
67
- print(f"πŸ’¬ Test results:\n{obs.last_tool_output[:300]}")
68
- print(f"πŸ† Final Reward: {reward.value:.3f}\n")
69
-
70
- # ------------------------------------------------------------------
71
- # Step 6: Show final reward breakdown (optional)
72
- # ------------------------------------------------------------------
73
- print("="*70)
74
- print("βœ… Demo complete. The agent learned from test failures, used documentation,")
75
- print(" negotiated with the author, and finally fixed the bug correctly.")
76
- print("="*70)