I gave my Amazon Echo Dot an AI agent
I’ve had my Amazon Echo Dot for 3 years now and have never found much use besides asking it for the weather or playing music.
I really wanted to do a project building a personal agent to learn more about these harnesses with tool calling and memory.
I built out a personal agent that runs locally on my MacBook with tools such as Notion, MCP, Gmail, Apple Mail, iMessages, Canvas, and Phone call capabilities. For now, we will call it Jarvis.
Some tasks Jarvis can do include:
- Check my calendar
- Check my to do list on notion
- Summarize recent mail
- Send an email to someone
- Send a text message to someone
- Call someone on my behalf
I decided to connect Jarvis to my Alexa.
Alexa works by having a wake word “Alexa” then whatever comes after is fed into their Custom Skill Interaction Model, which parses the input and classifies which skill to use. Unfortunately the wakeword is a limitation of the hardware and must be there for Alexa to "wake." Skills are similar to how agents have tools. The response from the skill call is fed back into Alexa and outputs a TTS.
Alexa has this thing called custom skills, similar to custom tools for an agent.
Inside a skill, Alexa matches what you said against intents, which are labels for what the user wants to do. Alexa doesn’t send the skill the raw audio, it converts speech to text and sends over the name of the matching intent plus any slots it filled in. I didn’t want Alexa doing the reasoning, so the Jarvis skill only has one catch-all intent, JarvisIntent, with a single query slot that captures everything after “Alexa, ask Jarvis”. The whole sentence gets passed to the agent and the agent decides what to do with it. This gives the Echo LLM reasoning capabilities instead of just mapping intents to skills.
How does the Echo dot communicate with the local agent?
I set up a websocket connection between my local agent’s backend to an AWS API Gateway. This gateway is hosted on the cloud so it talks to the Alexa API. The API gateway takes in traffic from requests and turns it into Lambda service calls. Lambdas push their response over the websocket back into the backend service for the agent to process.
The problem this solves is that Alexa skills live on the internet. When you talk to Alexa, Amazon sends an HTTP request to a public URL, and my Mac doesn’t have one. Instead of opening a port or running a tunnel, the backend dials out to the API Gateway and keeps that connection open. AWS then sends requests back down the same connection.
There are a few pieces on the AWS side, all set up with one CloudFormation template:
- WebSocket API: the endpoint my backend connects to. It only lets the backend in if it presents a shared secret.
- ConnectionsFunction: a Lambda that handles every websocket event. It records the backend’s connection when it connects, and stores Jarvis’s replies when they come back up.
- SkillFunction: the Lambda that is the Alexa skill’s endpoint. It forwards each utterance down the websocket to my Mac and waits for the reply.
- DynamoDB table: shared state between the Lambdas, like which connection is the backend and the replies waiting to be spoken.
So a full request looks like this:
- I say “Alexa, ask Jarvis what’s on my calendar today”
- Alexa calls the SkillFunction Lambda with the query
- The Lambda sends the query down the websocket to my Mac
- The agent runs and sends its answer back up the websocket
- The ConnectionsFunction saves the answer in DynamoDB
- The SkillFunction, which has been polling the table, picks it up and Alexa speaks it
What if the agent takes too long?
Alexa gives a skill 8 seconds to answer. Unfortunately the mic on the Echo dot doesn't stay on for longer than 8 seconds, so after 8 seconds you will have to reprompt it with the wake word. That’s fine for checking the weather, but an agent that reads my inbox and calls a few tools can easily take longer. Alexa also can’t speak unless the user talks to it first, so Jarvis can’t just reply when it’s done.
My workaround is that the Lambda waits about 6.5 seconds for a reply. If it doesn’t get one, Alexa says “I’m still working on that. Say any update in a bit to hear the answer.” and the request is saved as pending in DynamoDB. The agent keeps working in the background, and when I ask “any update”, the Lambda looks up the pending request and speaks the answer if it’s arrived.
Why not host the agent on the cloud?
Lose local access to Mac capabilities like iMessage database.
A lot of what makes Jarvis useful only exists on my Mac. iMessages are read straight from the Messages app’s SQLite database, my MIT email is read through Apple Mail’s on disk, calendar goes through Apple’s EventKit, and contacts come from macOS Contacts. Sending a text goes through the Messages app with AppleScript. None of that works from a server. Keeping the agent local and only putting the thin relay in the cloud means AWS never sees my data except for the messages passing through.
Agent architecture
Once the user prompt is fed into the agent, it runs a think, act, observe loop:
- Build the context: a system prompt plus the conversation so far
- Send it to the model (OpenAI’s Responses API) along with the schemas of every tool
- If the model asks for tool calls, run them and add the results to the conversation
- Repeat until the model answers without any tool calls, or stops at 20 steps
Approvals
Some tools are risky, like sending an email, texting someone, placing a phone call, or running a shell command that isn’t plainly read only. These tools require my approval before they run.
Context and compaction
The system prompt is rebuilt on every step. It includes the current date and time, the facts Jarvis remembers about me, the list of skills it can follow, the channel instructions, and a summary of older parts of the conversation.
When a conversation gets too long (around 400k characters), the oldest messages get summarized by the model and replaced with that summary in the model’s view, keeping the newest quarter word for word. The cut never lands between a tool call and its result, since the model gets confused if it sees one without the other. The original messages are still kept in the session, they just aren’t sent anymore.
Memory
I split long term memory into three types, all stored in one local SQLite file:
- Semantic: short facts about me, like preferences, people and routines. There are few enough that all of them go into every system prompt, so Jarvis always knows them without searching. The model saves them with
remember_factwhen I tell it something lasting. - Episodic: past conversations. After every turn, my message and the final answer are saved as an episode and embedded into a vector.
search_memoryembeds the query and ranks every episode by cosine similarity with numpy. At personal scale this is fast enough that I didn’t need a vector database. - Procedural: skills, which are Markdown how to docs like how I like my weekly review done. Only the names and descriptions go in the system prompt, and the full text is loaded with
read_skillwhen a task needs it. Jarvis can also save new ones when I explain how I like something done.
Tools
- Calendar: list, create, update and delete events through Apple Calendar’s EventKit
- Contacts: look people up by name, and turn phone numbers and emails back into names
- iMessage: list chats, read and search messages, view photo attachments, and send texts
- Email: Gmail goes through IMAP and SMTP. MIT doesn’t let third party apps reach its mailboxes, so that one goes through Apple Mail’s local index and AppleScript.
- Phone calls: the agent places calls through a Smallest AI voice agent using a clone of my voice. It fills in what the call should accomplish, waits for it to end, and gets back a summary and transcript.
- Notion: connected through Notion’s hosted MCP server. OpenAI calls this directly.
- Canvas: an open source canvas-mcp server that Jarvis runs locally as a subprocess and talks to over stdio. I only keep the tools the server marks as read only.
- Files and shell: read files, view images, and run shell commands
- Memory: remember and forget facts, search past conversations, and read and save skills