Skip to content

Commit fa864a5

Browse files
authored
[FEAT-TOOLS][Added proper computer-use tools, fully working and tested] (#1692)
* Added computer-use tools * Add PyTorch model creation and debugging example This script provides an example of using an agent to create and debug a PyTorch model. It outlines the workflow for developing the model, including planning, creating, testing, fixing, and reporting. * Add create_computer_use_tools to __all__ exports * Refactor file handling functions to include workspace_root * Update print statement from 'Hello' to 'Goodbye'
1 parent 0d1ab2e commit fa864a5

3 files changed

Lines changed: 1204 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
Agent Computer Use Example: Create and Debug a PyTorch Model
3+
4+
This example demonstrates an agent using the computer_use toolkit to:
5+
1. Create a PyTorch model file
6+
2. Run tests to verify it works
7+
3. Debug and fix any issues over multiple loops
8+
9+
The agent has access to all computer_use tools:
10+
- read_file, list_directory, grep_files (read-only)
11+
- write_file, edit_file, patch_file, delete_file (write)
12+
- run_command (shell)
13+
"""
14+
15+
import os
16+
from swarms import Agent
17+
from swarms.tools.computer_use import create_computer_use_tools
18+
19+
tools = create_computer_use_tools()
20+
21+
22+
agent = Agent(
23+
agent_name="PyTorch-Debugger",
24+
system_prompt="""
25+
You are an expert Python/PyTorch developer agent. Your task is to create and debug
26+
a PyTorch model file called `/$HOME/pytorch_model.py`.
27+
28+
Follow this workflow in each loop:
29+
30+
1. PLAN: Decide what needs to be done based on current state
31+
2. CREATE/MODIFY: Use write_file/edit_file to create or fix code
32+
3. TEST: Use run_command to run `python -c "from examples.models.pytorch_model import *; print('Import OK')"`
33+
4. FIX: If there are errors, use edit_file to fix them
34+
5. REPORT: Summarize what was done
35+
36+
The model should:
37+
- Define a NeuralNetwork class with at least 3 layers
38+
- Include forward() method
39+
- Include a training step function
40+
- Include an evaluation function
41+
- Be well-documented with docstrings
42+
- Handle both CPU and GPU (cuda) devices
43+
- Have proper error handling
44+
45+
When you see import errors or runtime errors:
46+
- Read the model file to understand the code
47+
- Identify the bug
48+
- Fix it with edit_file
49+
- Re-run the test
50+
51+
Continue until the model imports and runs without errors.
52+
When fully working, create a simple test that demonstrates the model training.
53+
54+
Return a final report with:
55+
- The final working code
56+
- Test results showing successful training
57+
- Any bugs that were fixed
58+
""",
59+
model_name="gpt-4o",
60+
max_loops=10,
61+
tools=list(tools.values()),
62+
)
63+
64+
result = agent.run("""
65+
Create and debug a PyTorch model at `/$HOME/pytorch_model.py`.
66+
67+
Start by creating the initial model file, then test it.
68+
If there are errors, fix them. Keep iterating until the model works correctly.
69+
70+
The model should demonstrate:
71+
1. A feedforward neural network
72+
2. Forward pass
73+
3. Training loop with loss computation
74+
4. Evaluation mode
75+
5. GPU/CPU device handling
76+
""")
77+
78+
print(result)

swarms/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
multi_base_model_to_openai_function,
3232
)
3333
from swarms.tools.tool_registry import ToolStorage, tool_registry
34+
from swarms.tools.computer_use import create_computer_use_tools
3435
from swarms.tools.tool_utils import (
3536
scrape_tool_func_docs,
3637
tool_find_by_name,
3738
)
3839

3940
__all__ = [
41+
"create_computer_use_tools",
4042
"scrape_tool_func_docs",
4143
"tool_find_by_name",
4244
"_remove_a_key",

0 commit comments

Comments
 (0)