Skip to content

HITL Tutorial: Demonstrate HITL with a Strands Agent #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"agentName": "HRAssistant",
"agentAliasName": "HRAssistantAlias",
"agentModelId": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"agentDescription": "An HR assistant that helps employees manage their time off requests",
"agentInstruction": "You are an HR assistant that helps employees check their available time off and submit time off requests. You should be friendly, helpful, and professional. When a user asks about their time off balance, use the getTimeOff function. When a user wants to request time off, use the requestTimeOff function with the start date and number of days they want to take off.",

"getTimeOffActionGroupName": "GetTimeOffActionGroup",
"getTimeOffActionGroup": "Action group for retrieving employee time off information",

"requestTimeOffActionGroupName": "RequestTimeOffActionGroup",
"requestTimeOffActionGroup": "Action group for submitting time off requests",

"func_gettime_name": "getTimeOff",
"func_gettime_description": "Get the current time off balance for the employee",

"func_createtimeoff_name": "requestTimeOff",
"func_createtimeoff_description": "Submit a time off request for the employee",
"func_createtimeoff_start_date": "startDate",
"func_createtimeoff_number_of_days": "numberOfDays"
}
91 changes: 91 additions & 0 deletions 01-tutorials/01-fundamentals/09-human-in-the-loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Strands HR Assistant

A virtual HR assistant built with the Strands SDK that helps employees manage their time off requests.

## Features

- Check time off balance
- Submit time off requests
- Natural language interaction

## Prerequisites

- Python 3.10 or higher
- AWS account with access to Amazon Bedrock
- AWS CLI configured with appropriate credentials

## Installation

1. Clone the repository:
```
git clone https://github.com/strands-agents/samples.git
cd strands-samples/01-tutorials/01-fundamentals/09-human-in-the-loop
```

2. Create and activate a virtual environment:
```
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

3. Install the required packages:
```
pip install -r requirements.txt
```

4. Configure AWS credentials:
- Make sure you have the AWS CLI installed and configured with your credentials
- Update the `aws_config.py` file with your AWS region and profile name

## Configuration

The HR assistant is configured using the `BedrockAgentStack/config.json` file. You can modify the following settings:

- `agentName`: The name of the HR assistant
- `agentDescription`: A description of the HR assistant
- `agentInstruction`: Instructions for the HR assistant
- Function names and descriptions

## Usage

1. Run the HR assistant:
```
python hr_assistant.py
```

2. Interact with the assistant using natural language:
- "What is my time off balance?"
- "I want to request time off from 2025-07-01 for 5 days"
- "Show me my pending time off requests"

3. Type 'exit' to quit the assistant.

## How It Works

The HR assistant uses the Strands SDK to create an agent with two main functions:

1. `get_time_off()`: Retrieves the employee's time off balance
2. `request_time_off(start_date, number_of_days)`: Submits a time off request

The agent uses Amazon Bedrock's Claude model to understand natural language requests and determine when to call these functions.

## Customization

You can extend the HR assistant by adding more functions to handle additional HR-related tasks, such as:

- Checking pay information
- Updating personal details
- Submitting expense reports
- Accessing company policies

To add a new function, define it using the `@tool` decorator and add it to the agent's tools list in the `create_hr_assistant()` function.

## Troubleshooting

- **AWS Credentials Error**: Make sure your AWS credentials are properly configured and you have access to Amazon Bedrock.
- **Model Not Found**: Verify that the model ID in the code matches an available model in your AWS region.
- **Function Not Called**: Ensure that your natural language request clearly indicates which function should be called.

## License

This project is licensed under the MIT License - see the LICENSE file for details.
23 changes: 23 additions & 0 deletions 01-tutorials/01-fundamentals/09-human-in-the-loop/aws_config.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pick up the region dynamically

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

picking it from the environment, and allowing user to change to a different region if required.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
AWS configuration for the HR assistant agent.
This file contains the AWS configuration for the Bedrock model.
"""

import os
import boto3
from botocore.config import Config

# AWS configuration
AWS_REGION = os.environ.get('AWS_REGION') # Replace with your AWS region if using a region different from the one set in ~/.aws/config
AWS_PROFILE = "default" # Replace with your AWS profile name

def get_bedrock_session():
"""Get a Bedrock client with the configured AWS credentials.

Returns:
A Bedrock client.
"""
# Configure AWS session
session = boto3.Session(profile_name=AWS_PROFILE, region_name=AWS_REGION)

return session
Loading