Appearance
Quickstart
Build your first Elsai agent in under 5 minutes.
Step 1 — Install
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ elsai-agents==0.1.0 elsai-agents-toolsStep 2 — Create your first agent
python
from elsai import Agent
from elsai_tools import calculator
agent = Agent(tools=[calculator])
result = agent("What is the square root of 1764?")
print(result)The agent will:
- Receive your question
- Decide to call the
calculatortool - Execute the tool and get the answer
- Return a natural-language response
Step 3 — Build a custom tool
Add your own Python function as a tool using the @tool decorator:
python
from elsai import Agent, tool
@tool
def get_weather(city: str) -> str:
"""Get current weather for a city.
Args:
city: The name of the city to get weather for.
Returns:
A description of current weather conditions.
"""
# In a real app, call a weather API here
return f"It's sunny and 72°F in {city}."
agent = Agent(tools=[get_weather])
result = agent("What's the weather like in Tokyo?")
print(result)Step 4 — Add a system prompt
Guide the agent's behavior with a system prompt:
python
from elsai import Agent
agent = Agent(
system_prompt="You are a helpful Python coding assistant. "
"Always provide complete, runnable code examples."
)
result = agent("Write a function that reverses a string")
print(result)Step 5 — Choose a model provider
Configure a model provider using the standalone elsai-model package (e.g., Anthropic Claude on AWS Bedrock):
python
import os
from elsai import Agent
from elsai_model.bedrock import BedrockConnector
model = BedrockConnector(
aws_access_key=os.environ.get("AWS_ACCESS_KEY_ID"),
aws_secret_key=os.environ.get("AWS_SECRET_ACCESS_KEY"),
aws_region="us-east-1",
model_id="anthropic.claude-3-5-sonnet-20241022-v2:0"
)
agent = Agent(model=model, system_prompt="You are a concise assistant.")
result = agent("Explain machine learning in one sentence")
print(result)Step 6 — Stream responses
Get tokens as they're generated:
python
import asyncio
from elsai import Agent
agent = Agent()
async def stream():
async for event in agent.stream_async("Tell me a short story"):
if "data" in event:
print(event["data"], end="", flush=True)
asyncio.run(stream())Step 7 — Multi-turn conversation
Agents maintain conversation history automatically:
python
from elsai import Agent
agent = Agent()
agent("My name is Alice and I'm a software engineer.")
agent("What do you know about me?")
# → "Your name is Alice and you're a software engineer."What's next?
- Core Concepts — understand how agents work
- Tools — build powerful tools
- Model Providers — configure your preferred LLM
- Multi-Agent — orchestrate multiple agents