diff --git a/04-UX-demos/05-strands-playground/README.md b/04-UX-demos/05-strands-playground/README.md index d93c9b11..3c838906 100644 --- a/04-UX-demos/05-strands-playground/README.md +++ b/04-UX-demos/05-strands-playground/README.md @@ -87,7 +87,7 @@ This project provides a playground environment for developers to experiment with 1. Clone the repository and navigate to the project directory: ```bash git clone https://github.com/strands-agents/samples.git - cd 04-UX-demos/05-strands-playground/ + cd samples/04-UX-demos/05-strands-playground/ ``` 2. Install Python dependencies: @@ -125,7 +125,7 @@ This project provides a playground environment for developers to experiment with 3. Open your browser and navigate to `http://localhost:8003` -### Option 3: Full CDK Deployment to AWS +### Option 2: Full CDK Deployment to AWS Deploy a complete production-ready environment to AWS using CDK: @@ -171,8 +171,6 @@ The Strands Playground follows a modern web application architecture: - **AI Integration**: Direct integration with Amazon Bedrock through the Strands SDK - **Deployment**: Containerized application deployable locally or on AWS infrastructure - - ## Usage Examples ### Basic Experimentation @@ -260,10 +258,26 @@ When deploying this application, consider the following security best practices: 3. **Environment Variables**: Never hardcode sensitive information; use environment variables or AWS Secrets Manager 4. **CORS Settings**: Restrict CORS settings to specific origins in production 5. **Network Security**: Deploy within a VPC with appropriate security groups and network ACLs +6. **Tools permissions**: By default, certain tools that perform potentially senstive operations (like file modifications, shell commands or code execution) will prompt for user confirmation before executing. This safety feature ensures users maintain control over actions that could modify their system.). To bypass these confirmation prompts, you can set the `BYPASS_TOOL_CONSENT` environment variable: + + ```bash + # Set this environment variable to bypass tool confirmation prompts + export BYPASS_TOOL_CONSENT=true + ``` + + or you can edit `main.py`: + + ```bash + import os + + os.environ["BYPASS_TOOL_CONSENT"] = "true" + ``` + ## Version History - **1.0.0** - Initial release with core playground functionality +- **1.0.1** - Update tools list, dependencies and README ## License diff --git a/04-UX-demos/05-strands-playground/app/main.py b/04-UX-demos/05-strands-playground/app/main.py index fa420a63..713c495c 100644 --- a/04-UX-demos/05-strands-playground/app/main.py +++ b/04-UX-demos/05-strands-playground/app/main.py @@ -2,16 +2,19 @@ import os import logging import boto3 +import base64 + from botocore.exceptions import ClientError from typing import Optional - from strands import Agent, tool from strands.models import BedrockModel from strands_tools import ( - agent_graph, calculator, cron, current_time, editor, environment, - file_read, file_write, generate_image, http_request, image_reader, journal, - load_tool, mem0_memory, memory, nova_reels, python_repl, retrieve, shell, - slack, speak, stop, swarm, think, use_aws, use_llm, workflow + a2a_client, agent_core_memory, agent_graph, batch, browser, calculator, + code_interpreter, cron, current_time, diagram, editor, environment, + file_read, file_write, generate_image, generate_image_stability, handoff_to_user, + http_request, image_reader, journal, load_tool, mem0_memory, memory, + nova_reels, python_repl, retrieve, rss, shell, slack, sleep, speak, + stop, swarm, think, use_agent, use_aws, use_llm, workflow ) from fastapi import FastAPI, HTTPException @@ -50,15 +53,23 @@ def weather_forecast(city: str, days: int = 3) -> str: # Define all available tools available_tools = { + 'a2a_client': a2a_client, + 'agent_core_memory': agent_core_memory, 'agent_graph': agent_graph, + 'batch': batch, + 'browser': browser, 'calculator': calculator, + 'code_interpreter': code_interpreter, 'cron': cron, 'current_time': current_time, + 'diagram': diagram, 'editor': editor, 'environment': environment, 'file_read': file_read, 'file_write': file_write, 'generate_image': generate_image, + 'generate_image_stability': generate_image_stability, + 'handoff_to_user': handoff_to_user, 'http_request': http_request, 'image_reader': image_reader, 'journal': journal, @@ -68,12 +79,15 @@ def weather_forecast(city: str, days: int = 3) -> str: 'nova_reels': nova_reels, 'python_repl': python_repl, 'retrieve': retrieve, + 'rss': rss, 'shell': shell, 'slack': slack, + 'sleep': sleep, 'speak': speak, 'stop': stop, 'swarm': swarm, 'think': think, + 'use_agent': use_agent, 'use_aws': use_aws, 'use_llm': use_llm, 'workflow': workflow, @@ -82,15 +96,23 @@ def weather_forecast(city: str, days: int = 3) -> str: # Tool descriptions for better user understanding tool_descriptions = { + 'a2a_client': 'Enable agent-to-agent communication', + 'agent_core_memory': 'Integration with Amazon Bedrock Agent Core Memory', 'agent_graph': 'Create and manage graphs of agents with different topologies and communication patterns', + 'batch': 'Call multiple tools from a single model request', + 'browser': 'Automate web browser interactions', 'calculator': 'Perform mathematical calculations with support for advanced operations', + 'code_interpreter': 'Execute code in isolated sandboxes', 'cron': 'Manage crontab entries for scheduling tasks, with special support for Strands agent jobs', 'current_time': 'Get the current time in various timezones', + 'diagram': 'Create cloud architecture and UML diagrams', 'editor': 'Editor tool designed to do changes iteratively on multiple files', 'environment': 'Manage environment variables at runtime', 'file_read': 'File reading tool with search capabilities, various reading modes, and document mode support', 'file_write': 'Write content to a file with proper formatting and validation based on file type', - 'generate_image': 'Create images using Stable Diffusion models', + 'generate_image': 'Create AI generated images with Amazon Bedrock', + 'generate_image_stability': 'Create images with Stability AI', + 'handoff_to_user': 'Enable human-in-the-loop workflows by pausing agent execution for user input or transferring control entirely to the user', 'http_request': 'Make HTTP requests to external APIs with authentication support', 'image_reader': 'Read and process image files for AI analysis', 'journal': 'Create and manage daily journal entries with tasks and notes', @@ -100,12 +122,15 @@ def weather_forecast(city: str, days: int = 3) -> str: 'nova_reels': 'Create high-quality videos using Amazon Nova Reel', 'python_repl': 'Execute Python code in a REPL environment with PTY support and state persistence', 'retrieve': 'Retrieves knowledge based on the provided text from Amazon Bedrock Knowledge Bases', + 'rss': 'Manage and process RSS feeds', 'shell': 'Interactive shell with PTY support for real-time command execution and interaction', 'slack': 'Comprehensive Slack integration for messaging, events, and interactions', - 'speak': 'Generate speech from text using say command or Amazon Polly.', + 'sleep': 'Pause execution with interrupt support', + 'speak': 'Generate speech from text using say command or Amazon Polly', 'stop': 'Stops the current event loop cycle by setting stop_event_loop flag', 'swarm': 'Create and coordinate a swarm of AI agents for parallel processing and collective intelligence', 'think': 'Process thoughts through multiple recursive cycles', + 'use_agent': 'Run a new AI event loop with custom prompts and different model providers', 'use_aws': 'Execute AWS service operations using boto3', 'use_llm': 'Create isolated agent instances for specific tasks', 'workflow': 'Advanced workflow orchestration system for parallel AI task execution', @@ -168,6 +193,7 @@ def restore_agent_state(self, user_id): # Save agent state def save_agent_state(self, user_id): + logger.debug(self.messages) if not table_name and not table_region: try: logger.debug("TABLE_NAME and TABLE_REGION environment variable not set, fallback to local file session management, saving conversation to file") @@ -263,7 +289,6 @@ def get_agent_response(request: PromptRequest): result = agent(request.prompt) logger.debug(f"Model response: {result.message}") agent.save_agent_state(request.userId) - logger.info(f"Agent state saved for user: {request.userId}") return { "messages": result.message, "latencyMs": result.metrics.accumulated_metrics["latencyMs"], diff --git a/04-UX-demos/05-strands-playground/app/requirements.txt b/04-UX-demos/05-strands-playground/app/requirements.txt index 3f926a29..e1e59ce0 100644 --- a/04-UX-demos/05-strands-playground/app/requirements.txt +++ b/04-UX-demos/05-strands-playground/app/requirements.txt @@ -4,4 +4,10 @@ pydantic==2.11.4 strands-agents strands-agents-tools strands-agents-tools[mem0_memory] +strands-agents-tools[local_chromium_browser] +strands-agents-tools[agent_core_browser] +strands-agents-tools[agent_core_code_interpreter] +strands-agents-tools[a2a_client] +strands-agents-tools[diagram] +strands-agents-tools[rss] uv \ No newline at end of file