Demo: Edit an existing file.
()
| 61 | |
| 62 | |
| 63 | async def demo_edit_tool(): |
| 64 | """Demo: Edit an existing file.""" |
| 65 | print("\n" + "=" * 60) |
| 66 | print("Demo 3: EditTool - Edit file content") |
| 67 | print("=" * 60) |
| 68 | |
| 69 | with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as f: |
| 70 | f.write("Python is great!\nI love Python programming.") |
| 71 | temp_path = f.name |
| 72 | |
| 73 | try: |
| 74 | print(f"Original content:\n{Path(temp_path).read_text()}\n") |
| 75 | |
| 76 | tool = EditTool() |
| 77 | result = await tool.execute( |
| 78 | path=temp_path, old_str="Python", new_str="Agent" |
| 79 | ) |
| 80 | |
| 81 | if result.success: |
| 82 | print(f"✅ File edited successfully") |
| 83 | print(f"New content:\n{Path(temp_path).read_text()}") |
| 84 | else: |
| 85 | print(f"❌ Failed: {result.error}") |
| 86 | finally: |
| 87 | Path(temp_path).unlink() |
| 88 | |
| 89 | |
| 90 | async def demo_bash_tool(): |