forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_openhands.py
More file actions
179 lines (145 loc) Β· 5.1 KB
/
Copy pathtest_openhands.py
File metadata and controls
179 lines (145 loc) Β· 5.1 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
"""
Test script for OpenHands SDK
This tests basic functionality of OpenHands for use with MCPOverflow/Questro integration
"""
import os
import sys
import asyncio
from datetime import datetime
print("=" * 80)
print("OpenHands SDK Test Suite")
print("=" * 80)
print(f"Test started at: {datetime.now()}")
print()
# Test 1: Import OpenHands modules
print("[Test 1] Importing OpenHands modules...")
try:
import openhands
from openhands import __version__
print(f"β OpenHands SDK version: {__version__}")
except ImportError as e:
print(f"β Failed to import OpenHands: {e}")
sys.exit(1)
# Test 2: Check available modules
print("\n[Test 2] Checking available OpenHands components...")
try:
from openhands.core.config import AppConfig
print("β Config module available")
from openhands.controller.agent import Agent
print("β Agent module available")
from openhands.core.logger import openhands_logger as logger
print("β Logger module available")
except ImportError as e:
print(f"β Failed to import components: {e}")
# Test 3: Check LLM configuration
print("\n[Test 3] Checking LLM configuration...")
try:
from openhands.llm.llm import LLM
print("β LLM module available")
# Check for API keys in environment
llm_providers = {
'ANTHROPIC_API_KEY': 'Anthropic (Claude)',
'OPENAI_API_KEY': 'OpenAI (GPT)',
'GOOGLE_API_KEY': 'Google (Gemini)',
}
available_providers = []
for key, name in llm_providers.items():
if os.getenv(key):
available_providers.append(name)
print(f" β {name} API key found")
if not available_providers:
print(" β No LLM API keys found in environment")
print(" Set ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY")
else:
print(f" β Available LLM providers: {', '.join(available_providers)}")
except ImportError as e:
print(f"β Failed to check LLM config: {e}")
# Test 4: Check Runtime support
print("\n[Test 4] Checking runtime support...")
try:
from openhands.runtime.base import Runtime
print("β Runtime module available")
# Check Docker availability
import docker
try:
client = docker.from_env()
client.ping()
print(" β Docker runtime available")
# List images
images = client.images.list()
openhands_images = [img for img in images if any('openhands' in tag for tags in img.tags for tag in tags)]
if openhands_images:
print(f" β Found {len(openhands_images)} OpenHands Docker image(s)")
else:
print(" β No OpenHands Docker images found")
except Exception as e:
print(f" β Docker not available: {e}")
except ImportError as e:
print(f"β Failed to check runtime: {e}")
# Test 5: Check Agent types
print("\n[Test 5] Checking available agent types...")
try:
from openhands.controller.agent_controller import AgentController
print("β AgentController available")
# Try to list available agents
try:
from openhands.controller.agent import Agent
print("β Agent base class available")
except:
pass
except ImportError as e:
print(f"β Failed to check agents: {e}")
# Test 6: Simple Agent creation test (without execution)
print("\n[Test 6] Testing Agent initialization...")
try:
from openhands.core.config import AppConfig, LLMConfig
from openhands.controller.agent import Agent
# Create minimal config
llm_config = LLMConfig(
model="gpt-4", # Default model name
api_key="test_key", # Dummy key for testing
)
app_config = AppConfig(
llm=llm_config,
)
print("β Configuration objects created successfully")
except Exception as e:
print(f"β Failed to create config: {e}")
# Test 7: Check MCP/Tool support
print("\n[Test 7] Checking MCP/Tool support...")
try:
from openhands.core.schema import ActionType
print("β ActionType schema available")
# List available action types
action_types = [attr for attr in dir(ActionType) if not attr.startswith('_')]
print(f" Available action types: {', '.join(action_types[:10])}...")
except ImportError as e:
print(f"β Failed to check MCP support: {e}")
# Test 8: Check Event system
print("\n[Test 8] Checking event system...")
try:
from openhands.core.schema import EventSource
print("β Event system available")
except ImportError as e:
print(f"β Failed to check event system: {e}")
# Summary
print("\n" + "=" * 80)
print("Test Summary")
print("=" * 80)
print("""
OpenHands SDK Status:
β SDK is installed and importable
β Core modules are available
For full functionality, you need:
1. LLM API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY)
2. Docker runtime for sandboxed execution
3. Configuration file at ~/.openhands/config.toml
Next Steps for MCPOverflow Integration:
1. Configure LLM API keys
2. Test with a simple code generation task
3. Create OpenHands adapter for MCPOverflow
4. Integrate with Questro workflow
""")
print(f"Test completed at: {datetime.now()}")
print("=" * 80)