forked from strands-agents/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (56 loc) · 1.75 KB
/
main.py
File metadata and controls
61 lines (56 loc) · 1.75 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
import os
from strands import Agent
from strands.models import BedrockModel
from utils.tools import (
code_generator,
code_reviewer,
code_writer_agent,
code_execute,
project_reader,
)
from utils.prompts import CODE_ASSISTANT_PROMPT
# Show rich UI for tools in CLI
os.environ["STRANDS_TOOL_CONSOLE_MODE"] = "enabled"
# Claude model instance
claude_sonnet_4 = BedrockModel(
model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
)
# Code Assistant Agent
code_assistant = Agent(
system_prompt=CODE_ASSISTANT_PROMPT,
model=claude_sonnet_4,
tools=[
project_reader,
code_generator,
code_reviewer,
code_writer_agent,
code_execute,
],
)
# Example usage
if __name__ == "__main__":
print("\n💻 Code Assistant Agent 💻\n")
print("This agent helps with programming tasks")
print("Type your code question or task below or 'exit' to quit.\n")
print("Example commands:")
print(" - Run: print('Hello, World!')")
print(
" - Explain: def fibonacci(n): a,b=0,1; for _ in range(n): a,b=b,a+b; return a"
)
print(" - Create a Python script that sorts a list")
print(" - Read sample_ts_app directory and convert into python")
# Interactive loop
while True:
try:
user_input = input("\n> ")
if user_input.lower() == "exit":
print("\nGoodbye! 👋")
break
# Process the input as a coding question/task
code_assistant(user_input)
except KeyboardInterrupt:
print("\n\nExecution interrupted. Exiting...")
break
except Exception as e:
print(f"\nAn error occurred: {str(e)}")
print("Please try asking a different question.")