Skip to content

Commit 0ea457a

Browse files
committed
add claude agent examples
1 parent a0229a6 commit 0ea457a

File tree

3 files changed

+450
-0
lines changed

3 files changed

+450
-0
lines changed

claude_agent/.mcp.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"mcpServers": {
3+
"aws-api": {
4+
"command": "uvx",
5+
"args": [
6+
"awslabs.aws-api-mcp-server@latest"
7+
],
8+
"env": {
9+
"AWS_REGION": "us-west-2"
10+
}
11+
},
12+
"aws-knowledge": {
13+
"command": "uvx",
14+
"args": [
15+
"fastmcp",
16+
"run",
17+
"https://knowledge-mcp.global.api.aws"
18+
]
19+
},
20+
"bedrock-agentcore": {
21+
"command": "uvx",
22+
"args": [
23+
"awslabs.amazon-bedrock-agentcore-mcp-server@latest"
24+
],
25+
"env": {
26+
"FASTMCP_LOG_LEVEL": "ERROR"
27+
}
28+
},
29+
"strands-agents": {
30+
"command": "uvx",
31+
"args": [
32+
"strands-agents-mcp-server"
33+
],
34+
"env": {
35+
"FASTMCP_LOG_LEVEL": "INFO"
36+
},
37+
"autoApprove": [
38+
"search_docs",
39+
"fetch_doc"
40+
]
41+
},
42+
"aws-diagram": {
43+
"command": "uvx",
44+
"args": [
45+
"--with",
46+
"sarif-om,jschema_to_python",
47+
"awslabs.aws-diagram-mcp-server@latest"
48+
]
49+
}
50+
}
51+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#!/usr/bin/env python3
2+
"""
3+
AWS Solutions Architect Agent - A Claude Agent SDK implementation for AWS infrastructure.
4+
5+
This agent helps with building and deploying AWS infrastructure, with specialized knowledge
6+
of AWS Strands agents and AgentCore framework for deploying production agents.
7+
"""
8+
9+
import asyncio
10+
11+
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
12+
13+
14+
async def architect_solution(user_request: str, mcp_config_path: str = ".mcp.json"):
15+
"""
16+
Processes user requests for AWS solutions architecture and deployment.
17+
18+
Args:
19+
user_request: User's description of what they want to build or deploy
20+
mcp_config_path: Path to the MCP configuration file
21+
22+
Returns:
23+
None: Outputs progress to console
24+
"""
25+
# System prompt defining the agent's role and behavior
26+
system_prompt = """You are an AWS Certified Solutions Architect - Professional with comprehensive expertise across the entire AWS ecosystem.
27+
28+
**Your Expertise:**
29+
You have mastery of 200+ AWS services spanning compute, storage, databases, networking, security, analytics, machine learning, IoT, and more. Rather than being limited to specific services, you leverage the full breadth of AWS capabilities to design optimal solutions.
30+
31+
**Core Competencies:**
32+
33+
1. **Solutions Architecture**
34+
- Design scalable, resilient, cost-effective architectures for any workload
35+
- Apply AWS Well-Architected Framework (Operational Excellence, Security, Reliability, Performance Efficiency, Cost Optimization, Sustainability)
36+
- Create multi-region, disaster recovery, and high-availability solutions
37+
- Architect hybrid cloud and multi-cloud environments
38+
39+
2. **AWS Strands Agents Framework**
40+
- Lightweight, model-driven Python SDK for building AI agents
41+
- Model-agnostic: supports Bedrock, Anthropic, OpenAI, Gemini, Ollama, LiteLLM, and more
42+
- Multi-agent systems with flexible orchestration patterns
43+
- Dynamic tool integration using Python decorators
44+
- Native MCP (Model Context Protocol) support
45+
- Hot-reloadable tools for rapid development
46+
- Scalable from simple conversational assistants to complex autonomous workflows
47+
48+
3. **Amazon Bedrock AgentCore**
49+
- Managed infrastructure for deploying highly capable AI agents at scale
50+
- Framework and model agnostic - works with any AI framework
51+
- Enterprise features: session isolation, persistent memory, secure browser runtime, code interpreter
52+
- Long-running workloads (up to 8 hours per session)
53+
- Native identity provider integration with IAM
54+
- CloudWatch and OpenTelemetry monitoring
55+
- Serverless, auto-scaling infrastructure
56+
57+
**Available MCP Servers:**
58+
- **aws-api**: Deploy and manage any AWS service
59+
- **aws-knowledge**: Query comprehensive AWS documentation, blog posts, whitepapers, and best practices
60+
- **bedrock-agentcore**: Deploy and operate production agents on Bedrock AgentCore
61+
- **strands-agents**: Access Strands SDK docs and build multi-agent systems
62+
- **aws-diagram**: Generate professional architecture diagrams
63+
- **aws-pricing**: Calculate costs and optimize spending across all AWS services
64+
- **aws-cdk**: Generate and manage AWS CDK infrastructure as code
65+
- **aws-cloudformation**: Create and manage CloudFormation templates and stacks
66+
67+
**Your Approach:**
68+
69+
1. **Discovery & Analysis**
70+
- Deeply understand user requirements and constraints
71+
- Query aws-knowledge for latest service features, best practices, and patterns
72+
- Consider technical, business, and operational requirements
73+
74+
2. **Architecture Design**
75+
- Leverage the full AWS portfolio - don't artificially limit yourself
76+
- Generate architecture diagrams using aws-diagram server
77+
- Calculate costs using aws-pricing server
78+
- Provide multiple options when trade-offs exist
79+
80+
3. **Agent-Specific Guidance**
81+
- For AI agent projects, evaluate Strands vs other frameworks based on requirements
82+
- Recommend Bedrock AgentCore for production agent deployments requiring scale, security, and monitoring
83+
- Design agent orchestration patterns for multi-agent systems
84+
- Integrate agents with AWS services (Lambda, Step Functions, EventBridge, etc.)
85+
86+
4. **Implementation**
87+
- Provide infrastructure as code (CDK, CloudFormation, Terraform)
88+
- Deploy resources using aws-api server when requested
89+
- Follow security best practices (IAM least privilege, encryption, VPC isolation)
90+
- Implement observability (CloudWatch, X-Ray, OpenTelemetry)
91+
92+
5. **Optimization**
93+
- Right-size resources for cost efficiency
94+
- Implement auto-scaling and elasticity
95+
- Optimize for performance and latency
96+
- Consider sustainability and environmental impact
97+
98+
**Guidelines:**
99+
- Always query aws-knowledge for up-to-date service information
100+
- Generate diagrams to visualize architectures
101+
- Calculate costs before deployment
102+
- Track progress with todos for complex projects
103+
- Explain architectural decisions and trade-offs
104+
- Verify AWS credentials before API operations
105+
- Follow Well-Architected Framework principles
106+
107+
You are a trusted advisor who designs world-class AWS solutions.
108+
"""
109+
110+
# Create the prompt for the architecture task
111+
prompt = f"""Help me with this AWS architecture request: {user_request}
112+
113+
Please:
114+
1. Analyze the requirements
115+
2. Check AWS knowledge base for relevant best practices
116+
3. Design an appropriate solution
117+
4. Provide implementation steps
118+
5. Deploy or configure resources if requested
119+
120+
Start by understanding the requirements and checking AWS documentation.
121+
"""
122+
123+
# Configure agent options
124+
options = ClaudeAgentOptions(
125+
system_prompt=system_prompt,
126+
mcp_servers=mcp_config_path,
127+
permission_mode="bypassPermissions", # Auto-approve MCP tool usage
128+
allowed_tools=[
129+
"Read",
130+
"Write",
131+
"Edit",
132+
"Bash",
133+
"Glob",
134+
"Grep",
135+
"TodoWrite",
136+
"ListMcpResources",
137+
"ReadMcpResource",
138+
# AWS API MCP tools (will be discovered at runtime)
139+
# AWS Knowledge MCP tools (will be discovered at runtime)
140+
],
141+
)
142+
143+
# Use ClaudeSDKClient for stateful conversation with loop
144+
async with ClaudeSDKClient(options=options) as client:
145+
# Send initial query
146+
await client.query(prompt)
147+
148+
# Stream and handle responses in a loop
149+
async for message in client.receive_response():
150+
# Handle different message types
151+
if hasattr(message, "type"):
152+
msg_type = message.type
153+
else:
154+
msg_type = getattr(message, "__class__", type(message)).__name__
155+
156+
# Print text content from assistant messages
157+
if msg_type == "text" or "Text" in msg_type:
158+
if hasattr(message, "text"):
159+
print(message.text, end="", flush=True)
160+
elif "Assistant" in msg_type or "Message" in msg_type:
161+
# Try to extract text from message content
162+
if hasattr(message, "content"):
163+
for block in message.content:
164+
if hasattr(block, "text"):
165+
print(block.text, end="", flush=True)
166+
167+
168+
async def main():
169+
"""
170+
Main entry point for the AWS Solutions Architect agent.
171+
"""
172+
print("AWS Solutions Architect Agent")
173+
print("=" * 50)
174+
print("\nI'm your AWS Solutions Architect specializing in:")
175+
print(" • AWS infrastructure and services")
176+
print(" • AWS Strands agents framework")
177+
print(" • AWS AgentCore deployment")
178+
print("\nWhat would you like to build or deploy?")
179+
print("\nExamples:")
180+
print(" - 'Create a 3-tier architecture diagram'")
181+
print(" - 'Deploy a Strands agent to AgentCore'")
182+
print(" - 'Explain how to build a scalable microservices architecture'")
183+
184+
user_request = input("\nYour request: ").strip()
185+
186+
if not user_request:
187+
print("Please provide a request description.")
188+
return
189+
190+
print("\nAnalyzing your request...\n")
191+
print("=" * 50)
192+
print()
193+
194+
try:
195+
await architect_solution(user_request)
196+
except Exception as e:
197+
print(f"\nError during architecture process: {e}")
198+
print("\nMake sure:")
199+
print("1. AWS credentials are configured (aws configure)")
200+
print("2. AWS MCP servers are installed:")
201+
print(" - uvx awslabs.aws-api-mcp-server@latest")
202+
print(" - uvx fastmcp run https://knowledge-mcp.global.api.aws")
203+
print("3. claude-agent-sdk is installed: pip install claude-agent-sdk")
204+
print("4. .mcp.json is properly configured")
205+
206+
207+
if __name__ == "__main__":
208+
asyncio.run(main())
209+

0 commit comments

Comments
 (0)