This project implements a FastAPI-based web service that uses an Agent Squad to process and respond to user queries. It supports streaming responses and uses AWS Bedrock for language model interactions.
-
Clone this repository:
git clone https://github.com/awslabs/agent-squad.git cd examples/fast-api-streaming -
Install the required dependencies (must be done with python3.12):
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt
Before running the application, make sure to set up your AWS credentials and region. You can do this by setting environment variables or using AWS CLI's aws configure command.
To start the server, run:
python -m uvicorn main:app --port 8080
This will start the FastAPI server on http://127.0.0.1:8080.
You can interact with the API using curl or any HTTP client. Here's an example using curl:
curl -X "POST" \
"http://127.0.0.1:8080/stream_chat/" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"content\": \"what is aws lambda\", \"user_id\":\"01234\", \"session_id\":\"012345\"}" \
--no-bufferThis will send a streaming request to the /stream_chat/ endpoint with the given query.
- POST
/stream_chat/: Accepts a JSON payload withcontent,user_id, andsession_id. Returns a streaming response with the generated content.
main.py: The main FastAPI application file containing the API routes and Agent Squad setup.requirements.txt: List of Python dependencies for the project.
- This application uses AWS Bedrock for language model interactions. Ensure you have the necessary permissions and credentials set up.
- The Agent Squad is configured with a Tech Agent and a Health Agent.
- Streaming responses are implemented for real-time output.
