-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_agentcore.py
More file actions
173 lines (144 loc) · 5.95 KB
/
debug_agentcore.py
File metadata and controls
173 lines (144 loc) · 5.95 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
#!/usr/bin/env python3
"""
Debug script to identify exactly why AgentCore is failing
"""
import boto3
import sys
import yaml
from botocore.exceptions import ClientError
def test_bedrock_access():
"""Test basic Bedrock access"""
print("🔍 Testing Bedrock Model Access...")
try:
bedrock = boto3.client('bedrock', region_name='us-east-1')
models = bedrock.list_foundation_models()
print("✅ Bedrock model access working")
return True
except Exception as e:
print(f"❌ Bedrock access failed: {e}")
return False
def test_bedrock_agent_list():
"""Test listing AgentCore agents"""
print("\n🔍 Testing AgentCore List Agents...")
try:
bedrock_agent = boto3.client('bedrock-agent', region_name='us-east-1')
response = bedrock_agent.list_agents()
agents = response.get('agentSummaries', [])
print(f"✅ AgentCore list_agents working - found {len(agents)} agents")
if agents:
for agent in agents:
print(f" - {agent.get('agentName')} (ID: {agent.get('agentId')})")
return True
except ClientError as e:
error_code = e.response['Error']['Code']
error_msg = e.response['Error']['Message']
print(f"❌ AgentCore list failed: {error_code}")
print(f" Message: {error_msg}")
return False
except Exception as e:
print(f"❌ AgentCore list failed: {type(e).__name__}: {e}")
return False
def test_bedrock_agent_create():
"""Test creating a minimal AgentCore agent"""
print("\n🔍 Testing AgentCore Create Agent...")
try:
bedrock_agent = boto3.client('bedrock-agent', region_name='us-east-1')
# Try to create a test agent
response = bedrock_agent.create_agent(
agentName='TestAgent-Debug',
foundationModel='amazon.nova-micro-v1:0',
instruction='You are a test agent.',
description='Debug test agent'
)
agent_id = response['agent']['agentId']
print(f"✅ AgentCore create_agent working - created agent ID: {agent_id}")
# Clean up - delete the test agent
print(" Cleaning up test agent...")
bedrock_agent.delete_agent(agentId=agent_id)
print(" ✅ Test agent deleted")
return True
except ClientError as e:
error_code = e.response['Error']['Code']
error_msg = e.response['Error']['Message']
print(f"❌ AgentCore create failed: {error_code}")
print(f" Message: {error_msg}")
# Common issues and solutions
if error_code == 'AccessDeniedException':
print("\n💡 Solution: Add bedrock-agent:CreateAgent permission")
elif error_code == 'ValidationException':
print(f"\n💡 Possible issue: {error_msg}")
return False
except Exception as e:
print(f"❌ AgentCore create failed: {type(e).__name__}: {e}")
return False
def test_bedrock_agent_runtime():
"""Test AgentCore runtime client"""
print("\n🔍 Testing AgentCore Runtime Client...")
try:
bedrock_agent_runtime = boto3.client('bedrock-agent-runtime', region_name='us-east-1')
print("✅ AgentCore runtime client created successfully")
return True
except Exception as e:
print(f"❌ AgentCore runtime client failed: {e}")
return False
def check_config():
"""Check config.yaml settings"""
print("\n🔍 Checking config.yaml...")
try:
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
use_agentcore = config.get('agents', {}).get('use_agentcore', False)
provider = config.get('llm', {}).get('provider', 'unknown')
model = config.get('llm', {}).get('bedrock', {}).get('model', 'unknown')
region = config.get('llm', {}).get('bedrock', {}).get('region', 'unknown')
print(f"✅ Config loaded:")
print(f" - use_agentcore: {use_agentcore}")
print(f" - provider: {provider}")
print(f" - bedrock.model: {model}")
print(f" - bedrock.region: {region}")
if not use_agentcore:
print("\n⚠️ WARNING: use_agentcore is False in config!")
return True
except Exception as e:
print(f"❌ Config check failed: {e}")
return False
def main():
print("="*80)
print("AgentCore Debug Diagnostics")
print("="*80)
results = {}
# Test 1: Check config
results['config'] = check_config()
# Test 2: Basic Bedrock access
results['bedrock'] = test_bedrock_access()
# Test 3: AgentCore list
results['agent_list'] = test_bedrock_agent_list()
# Test 4: AgentCore create (only if list works)
if results['agent_list']:
results['agent_create'] = test_bedrock_agent_create()
else:
print("\n⏭️ Skipping create test (list failed)")
results['agent_create'] = False
# Test 5: Runtime client
results['runtime'] = test_bedrock_agent_runtime()
# Summary
print("\n" + "="*80)
print("DIAGNOSTIC SUMMARY")
print("="*80)
for test_name, passed in results.items():
status = "✅ PASS" if passed else "❌ FAIL"
print(f"{test_name.upper()}: {status}")
if all(results.values()):
print("\n🎉 All diagnostics passed! AgentCore should work.")
print("\nNext step: Run python test_complete_workflow.py")
return 0
else:
print("\n⚠️ Some tests failed. See errors above for details.")
# Provide actionable next steps
if not results['agent_list']:
print("\n📋 Action needed: AgentCore permissions issue")
print(" Even with AmazonBedrockFullAccess, you may need explicit bedrock-agent:* permissions")
print(" Try: ./setup_agentcore_permissions.sh")
return 1
if __name__ == "__main__":
sys.exit(main())