Long-running agent on ECS Fargate that orchestrates Lambda tools using ReAct pattern with streaming responses.
- ReAct (Reasoning + Acting) agent pattern implementation
- ECS Fargate for long-running containerized workloads
- Lambda function orchestration from ECS
- Server-Sent Events (SSE) for streaming responses
- Multi-step reasoning and tool usage loops
- AWS ECS cluster or Docker for local development
- Deployed Lambda AI tool from Example 03
- Anthropic API key
- AWS credentials with Lambda invoke permissions
npm install
docker build -t ecs-agent . && docker run -p 3000:3000 ecs-agent
curl -X POST http://localhost:3000/agent/process -d '{"task":"Analyze customer feedback and suggest improvements"}'The agent follows a ReAct loop for complex reasoning and action:
- Reasoning: Agent analyzes the current state and decides next action
- Acting: Calls appropriate Lambda tools (summarize, classify, extract)
- Observing: Processes tool results and updates internal state
- Repeating: Continues until task completion or iteration limit
User Request -> ReAct Loop -> Stream Progress -> Final Result
| | | |
v v v v
Parse Task -> Reason/Act -> Lambda Tools -> Synthesize
The agent streams its reasoning process and intermediate results via Server-Sent Events, allowing real-time visibility into multi-step workflows.
While this approach handles complex workflows Lambda cannot:
- Container overhead increases costs vs serverless
- Always-running resources vs event-driven Lambda
- Complex scaling decisions vs automatic Lambda scaling
- Infrastructure management vs managed Lambda runtime
See Example 05 (streaming-chat) for user-facing chat interfaces, or Example 06 (cost-tracking) for monitoring multi-step agent costs.