Creating Your First Agent
Learn how to build a basic agent using CAP and LangGraph from scratch.
What You'll Build
A simple agent that can:
- Process user input
- Generate contextual responses
- Maintain conversation history
- Deploy to AWS Lambda
Prerequisites
- Completed Getting Started
- Basic Python knowledge
- AWS account configured
Step-by-Step Guide
1. Project Setup
mkdir my-first-agent
cd my-first-agent
python -m venv venv
source venv/bin/activate
pip install cap-engine-langgraph-lite
2. Create Agent Class
from cap.core import BaseAgent
from cap.utils import Memory
class MyFirstAgent(BaseAgent):
def __init__(self):
self.memory = Memory()
async def process(self, input_text: str) -> str:
# Add to memory
self.memory.add(input_text)
# Generate response
response = await self.generate_response(
context=self.memory.get_context()
)
return response
3. Configure Deployment
# main.tf
module "my_agent" {
source = "github.com/Agaile-com/cap-cloud-ce//modules/agent"
name = "my-first-agent"
memory_size = 256
timeout = 30
}
4. Deploy
terraform init
terraform apply
Next Steps
- Add custom tools
- Explore advanced patterns
- Check out more examples