-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_task_direct.py
More file actions
102 lines (86 loc) · 3.62 KB
/
test_task_direct.py
File metadata and controls
102 lines (86 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
Direct task execution test - bypassing conversation loop
"""
import asyncio
import sys
import os
from pathlib import Path
# Add current directory to path
sys.path.insert(0, str(Path(__file__).parent))
from python_agent.agent import create_agent_from_config_file
async def test_direct_task():
"""Test the tutorialspoint screenshot task directly"""
print("=== Direct Task Execution Test ===")
# Create agent
agent = create_agent_from_config_file('python_agent/mcp_config.yaml')
try:
# Start agent
await agent.start()
print("✅ Agent started successfully")
# Get status
status = await agent.get_status()
print(f"✅ MCP tools loaded: {status['tools']['mcp']}")
print(f"✅ Connected servers: {status['mcp_servers']['connected']}")
# Create directory
os.makedirs('temp_images', exist_ok=True)
# Step 1: Navigate to the URL
print("\n📍 Step 1: Navigating to tutorialspoint...")
nav_tool = agent.tools.get('mcp_browser_navigate')
if nav_tool:
result = await nav_tool.execute({
'url': 'https://www.tutorialspoint.com/parallel_algorithm/graph_algorithm.htm'
})
print(f"Navigation result: success={result.success}")
if not result.success:
print(f"❌ Navigation error: {result.error}")
return False
else:
print("✅ Successfully navigated to the page!")
else:
print("❌ Navigation tool not found")
return False
# Wait for page to load
print("⏳ Waiting for page to load...")
await asyncio.sleep(3)
# Step 2: Take screenshot
print("\n📸 Step 2: Taking screenshot...")
screenshot_tool = agent.tools.get('mcp_browser_take_screenshot')
if screenshot_tool:
result = await screenshot_tool.execute({
'filename': 'temp_images/graph_algorithm.png'
})
print(f"Screenshot result: success={result.success}")
if result.success:
print("✅ Screenshot taken successfully!")
print(f"Output: {result.output[:200]}..." if len(result.output) > 200 else result.output)
# Check if file exists in current directory
screenshot_files = []
for root, dirs, files in os.walk('.'):
for file in files:
if 'graph_algorithm' in file and file.endswith(('.png', '.jpg', '.jpeg')):
screenshot_files.append(os.path.join(root, file))
if screenshot_files:
print(f"✅ Found screenshot files: {screenshot_files}")
for file_path in screenshot_files:
size = os.path.getsize(file_path)
print(f" - {file_path}: {size} bytes")
else:
print("⚠️ No screenshot file found in expected location")
return True
else:
print(f"❌ Screenshot error: {result.error}")
return False
else:
print("❌ Screenshot tool not found")
return False
finally:
# Stop agent
await agent.stop()
print("🔚 Agent stopped")
if __name__ == "__main__":
success = asyncio.run(test_direct_task())
if success:
print("\n🎉 Task completed successfully!")
else:
print("\n❌ Task failed!")