An AI agent solution on AWS that hosts a FastAPI endpoint for querying real-time and historical stock prices, powered by LangGraph and Bedrock Claude models with Cognito authentication.
- ReAct Agent: LangGraph-based agent using Claude 3.5 Haiku via AWS Bedrock
- Real-time Stock Prices: Query current stock prices via yfinance
- Historical Data: Retrieve historical stock price trends
- Document RAG: Search Amazon financial documents (Annual Report, Earnings Releases)
- Streaming Responses: Stream agent reasoning and tool calls via Server-Sent Events
- Cognito Authentication: JWT-based authentication via AWS Cognito
- AWS Deployment: Dockerized application deployed via Bedrock Agentcore
- AWS Account with permissions to:
- Access Bedrock models
- Create Cognito user pools
- Push images to ECR
- Create Agentcore runtimes
- Terraform >= 1.0
- Python 3.11+
- Docker
git clone <repository>
cd bedrock-stock-agent
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Copy and configure environment
cp .env.example .env
# Edit .env with your actual valuesexport ENVIRONMENT=dev
export SKIP_AUTH=true
uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000
# Test health
curl http://localhost:8000/ping
# Test invoke (no auth in dev mode)
curl -X POST http://localhost:8000/invocations \
-H "Content-Type: application/json" \
-d '{"input": {"prompt": "What is the stock price for Amazon right now?"}}'Terraform manages the supporting infrastructure: Cognito, S3, and IAM.
cd terraform
terraform init
terraform plan
terraform apply
terraform output -jsonOpen test_agent.ipynb and run the cells. The notebook reads credentials from .env and tests:
- Cognito authentication
- Health check
- Agent invocation with sample queries
| Method | Path | Description |
|---|---|---|
| GET | /ping |
Health check |
| POST | /invocations |
Bedrock Agentcore standard endpoint |
bedrock-stock-agent/
├── src/
│ ├── agent/
│ │ ├── graph.py # LangGraph ReAct agent
│ │ └── tools.py # Stock and retrieval tools
│ ├── api/
│ │ ├── main.py # FastAPI application
│ │ └── auth.py # Cognito authentication
│ └── knowledge/
│ ├── loader.py # Document loading
│ └── retriever.py # FAISS vector store
├── terraform/
│ ├── main.tf # Provider and backend
│ ├── cognito.tf # Cognito resources
│ ├── iam.tf # IAM roles and policies
│ ├── s3.tf # S3 document storage
│ ├── agentcore.tf # ECR image output
│ ├── variables.tf # Input variables
│ └── outputs.tf # Output values
├── data/ # Amazon financial documents
├── image/ # Langfuse test
├── test_agent.ipynb # Test notebook
├── Dockerfile # Container definition
├── requirements.txt # Python dependencies
└── .env.example # Environment variable template
Copy .env.example to .env and fill in values:
# AWS Configuration
AWS_REGION=us-east-1
ENVIRONMENT=dev
# Cognito Authentication
COGNITO_CLIENT_ID=<your-cognito-client-id>
COGNITO_USERNAME=<your-cognito-username>
COGNITO_PASSWORD=<your-cognito-password>
# Bedrock Configuration
USE_BEDROCK_EMBEDDINGS=false
BEDROCK_MODEL_ID=us.anthropic.claude-3-5-haiku-20241022-v1:0
# AgentCore Configuration
AGENTCORE_RUNTIME_ARN=<your-agentcore-runtime-arn>
# Langfuse Observability
LANGFUSE_SECRET_KEY=<your-langfuse-secret-key>
LANGFUSE_PUBLIC_KEY=<your-langfuse-public-key>
LANGFUSE_HOST=https://us.cloud.langfuse.comFor local development, set SKIP_AUTH=true to bypass Cognito authentication.
- Check AWS credentials:
aws sts get-caller-identity - Verify Bedrock access:
aws bedrock list-foundation-models --region us-east-1
- Verify files in
data/directory - Check S3 bucket permissions
- Rebuild vector store:
rm -rf .vector_store
- Verify user exists:
aws cognito-idp admin-get-user --user-pool-id <ID> --username <user> - Check token validity (tokens expire after 1 hour)
- Verify client ID matches
.env
cd terraform
terraform destroy