This demo shows a 3-node LangGraph pattern for handling long-running tasks (simulated Athena queries). Ready for deployment on AWS Bedrock AgentCore Runtime.
- 3-Node Pattern: Submit → Poll → Fetch for async query handling
- AgentCore Ready: Deploy to AWS with one command
- Configurable: Adjust polling intervals, timeouts, and retries
- Production Ready: Includes tests, monitoring, and error handling
# Install dependencies
uv pip install -r requirements.txt
# Run locally
python agent.pySee DEPLOYMENT.md for detailed guide.
The agent splits query execution into three explicit nodes:
- Node A (submit_athena_query): Submits SQL query and stores execution ID
- Node B (poll_athena_status): Polls query status with retry logic
- Node C (fetch_athena_results): Retrieves and processes results when complete
┌─────────────────┐
│ START │
└────────┬────────┘
│
▼
┌────────────────────┐
│ Node A: Submit │
│ Athena Query │
│ │
│ • Build SQL │
│ • Start execution │
│ • Store query_id │
└─────────┬──────────┘
│
▼
┌────────────────────┐
│ Node B: Poll │◄──────────┐
│ Athena Status │ │
│ │ │
│ • Check status │ │
│ • Increment retry │ │
└─────────┬──────────┘ │
│ │
▼ │
┌────────────────────┐ │
│ Conditional Router │ │
└─────────┬──────────┘ │
│ │
┌───────────────┼───────────────┐ │
│ │ │ │
▼ ▼ ▼ │
[SUCCEEDED] [RUNNING] [FAILED] │
│ │ │ │
│ ┌─────┴─────┐ │ │
│ │ retry < │ │ │
│ │max_retry? │ │ │
│ └─────┬─────┘ │ │
│ │ │ │
│ Yes │ No │ │
│ │ │ │
│ └───────────────┼──────┘
│ │
▼ ▼
┌──────────────────┐ ┌────────────────┐
│ Node C: Fetch │ │ END │
│ Athena Results │ │ (Timeout or │
│ │ │ Failed) │
│ • Get results │ └────────────────┘
│ • Format data │
│ • Store state │
└────────┬─────────┘
│
▼
┌──────────────┐
│ END │
│ (Success) │
└──────────────┘
- submit_query → poll_status: Unconditional (always proceeds to polling)
- poll_status → poll_status: When status is RUNNING and retry_count < max_retries (loops back)
- poll_status → fetch_results: When status is SUCCEEDED
- poll_status → END: When status is FAILED or retry_count >= max_retries
Copy the example environment file and customize:
cp .env.example .envEdit .env to configure:
ATHENA_MOCK_DURATION: Query duration in seconds (default: 10)POLL_INTERVAL: Polling interval in seconds (default: 2)MAX_RETRIES: Maximum polling attempts (default: 20)AWS_DEFAULT_REGION: AWS region (default: us-east-1)LOG_LEVEL: Logging level (default: INFO)
- Asynchronous query pattern (submit → poll → fetch)
- Retry logic with configurable max attempts
- Conditional routing based on query status
- Clean state management through LangGraph
- AWS AgentCore Runtime compatible
- Environment-based configuration
- Comprehensive test coverage
.
├── agent.py # Standalone LangGraph agent
├── agentcore_agent.py # AgentCore-compatible wrapper
├── athena_mock.py # Mock Athena client
├── test.py # Tests for standalone agent
├── test_agentcore.py # Tests for AgentCore wrapper
├── invoke_agent_example.py # Example AWS SDK invocation
├── .env # Environment configuration (create from .env.example)
├── .env.example # Environment template
├── .bedrock_agentcore.yaml # AgentCore configuration
├── pyproject.toml # Python dependencies
├── DEPLOYMENT.md # Detailed deployment guide
└── README.md # This file
The agent behavior can be configured via environment variables in .env:
ATHENA_MOCK_DURATION: Mock query duration in seconds (default: 10)POLL_INTERVAL: Polling interval in seconds (default: 2)MAX_RETRIES: Maximum polling attempts (default: 20)AWS_DEFAULT_REGION: AWS region (default: us-east-1)LOG_LEVEL: Logging level - DEBUG, INFO, WARNING, ERROR (default: INFO)
Copy .env.example to .env and customize as needed.
Run all tests:
# Test standalone agent
uv run pytest test.py -v
# Test AgentCore wrapper
uv run pytest test_agentcore.py -v
# Run all tests
uv run pytest -v