Open Reader

Stanford CS146S: How always-on agents work

completed 45:17 Oct 11, 2026 Watch on YouTube

Current Status

completed

Video ID

L1OBRtfPS34

RAG / Chat

Enabled
Stanford CS146S: How always-on agents work
Description

Learn more about the product, infrastructure, and harness details used to build Grok Bot, a new type of always-on and proactive agent.

Summary

Generated by gpt-5.6-terra

At-a-Glance

  • Verdict: Watch fully
  • Core thesis: Always-on agents are not simply chatbots with more tools: they require a durable server-side harness that manages persistence, event triggers, isolated computers, hierarchical memory, subagents, cost-aware context handling, and explicit safety controls.
  • Why it matters: This is a concrete architecture and operating model for moving from interactive, terminal-bound agents to long-running digital colleagues that can execute work across applications while remaining recoverable, affordable, and governable.
  • Best use: Use it as a systems-design reference for an OpenClaw-style agent control plane, especially for workflow durability, VM isolation, memory/context design, tool routing, notification policy, and evaluation/security requirements.

Executive Summary

Lee frames the shift in agents as four product eras: copy-pasting from chat; terminal coding agents that can edit files and run commands; dedicated coding-agent applications with human command approval; and now persistent agents that run on servers, retain state, act on external triggers, and behave more like colleagues than reactive assistants. The central product change is moving the user from approving every command to steering a capable system that works in the background and reports only when useful.

The proposed architecture separates a thin client from a thick server. The durable agent loop, state, orchestration, and integrations live on the server, while an on-demand Firecracker VM provides an isolated Linux desktop, browser, files, and shell environment. The VM can be snapshotted, stopped, rebuilt, and patched independently of the agent, while durable workflows preserve progress through failures rather than replaying an entire task.

Much of the lecture is a practical guide to context engineering. Keep the main orchestrator's context sparse; store durable knowledge in files; use subagents for tool-heavy or long-running work; dynamically discover tool schemas instead of loading every connector into every prompt; compact conversations before cache expiration; and preserve stable prompt/tool ordering to maximize prompt-cache hits. These choices improve quality, latency, and unit economics simultaneously.

The speaker is clear that autonomy does not remove the need for controls. External content such as emails and webhooks must be treated as untrusted rather than as instructions; irreversible actions need user approval; credentials should stay outside model context; and command review can be automated with a separate reviewing model. The unresolved frontier is evaluating agents whose tasks span weeks or months while the underlying models change on shorter release cycles.

Key Takeaways

  • Claim: An always-on agent needs a server-resident, persistent architecture rather than a terminal loop running on the user's machine. | Evidence: The agent's conversations, memories, routines, and workflow state are persisted to storage; the server and its computer can sleep when idle and be awakened by a direct message, Slack activity, email, meeting, routine, or other event. | Implication: Build the agent as a durable service with explicit wake-up, state-rehydration, queueing, and sleep policies—not as a continuously running chat session or local process. | Caveat: Persistence alone does not make an agent useful; the product also needs routing and notification heuristics so the agent does not interrupt users for every intermediate update.
  • Claim: Use durable workflows rather than ordinary job queues for multi-step agent work that can fail mid-execution. | Evidence: The speaker contrasts a queue that must replay steps one through three after a crash with a durable workflow that resumes at step three; the implementation cited uses Temporal as an open-source workflow engine. | Implication: Model every substantial agent turn and subagent task as resumable workflow state, enabling safe retries, crash recovery, and long-running operations without duplicating prior work. | Caveat: Durable workflows solve retry/resumption mechanics, but task-level idempotency and protection around irreversible external actions are still required.
  • Claim: The primary agent should orchestrate sparse summaries while delegating expensive, tool-heavy work to subagents with fresh context. | Evidence: Subagents can handle shell commands, browser work, video tasks, and other long operations, then return a result to the main agent; each helper is itself described as a durable workflow. | Implication: Separate coordination from execution: maintain a lightweight lead agent with a to-do list and use specialized workers to contain context growth, isolate failures, and optimize long-running tasks independently. | Caveat: “Infinite context” is only an effective illusion: every model still has a finite context window, and summary quality determines whether important facts survive delegation and compaction.
  • Claim: Context engineering is a core economic and reliability discipline, not a prompt-writing detail. | Evidence: The lecture recommends keeping system prompts and tool definitions static for prompt caching, dynamically loading tool details rather than all MCP schemas, offloading long outputs to files, and compacting long conversations while the provider cache is still warm; the example context window is 200,000 tokens. | Implication: Treat cache-hit rate, context size, compaction fidelity, and tool-schema footprint as first-class production metrics; a cache miss is characterized as a system bug for an always-on agent. | Caveat: Compaction is inherently lossy, so the system needs a deliberate memory hierarchy rather than indiscriminately summarizing everything.
  • Claim: Files are a practical substrate for memory, skills, and retrieval because models can search and manipulate them reliably with standard computer tools. | Evidence: The proposed memory stack includes always-loaded user facts, dated work logs, ephemeral scratch-pad notes, and files for everything else; skills are encoded as markdown procedures, while routines are scheduled prompts analogous to cron jobs. | Implication: Start with inspectable, versionable filesystem artifacts for agent memory and reusable procedures before adding more complex graph or vector-memory abstractions. | Caveat: File-based memory requires curation and garbage collection so stale or low-value facts do not dominate the agent's active context.
  • Claim: Agent tool use should follow an escalating reliability/cost ladder, and computer use is a fallback that extends agents to services without APIs. | Evidence: The recommended order is existing conversation knowledge, then plugins/MCP/API access, then web search, browser use, full desktop/scripting, and finally asking the user. For browser control, the system prefers accessibility trees or HTML over screenshots, with pixel clicking as a later fallback. | Implication: Implement explicit tool-routing policy that prefers structured, lower-cost interfaces and reserves VM/browser interaction for cases where APIs or direct retrieval cannot complete the work. | Caveat: Browser and desktop automation increases exposure to authentication challenges, captchas, brittle interfaces, and malicious page content.
  • Claim: Security and evaluation must be embedded in the harness because persistent agents receive untrusted inputs and act over long time horizons. | Evidence: The speaker calls for automated review of shell commands, treating email and webhooks as possible prompt-injection vectors, requiring approval for irreversible actions such as sending email or Slack messages, and keeping passwords outside model conversations. They also identify a future evaluation mismatch: agents may run for a month while new models ship monthly. | Implication: Adopt defense in depth: isolate execution, classify input trust, gate side effects, separate credential systems from model context, log decisions, and create accelerated or proxy evaluations for long-horizon behavior before model upgrades. | Caveat: The lecture presents automated model review as often outperforming fatigued humans reviewing hundreds of commands, but it does not establish that such review is sufficient for high-impact actions or adversarial settings.

Detailed Brief

Control plane, client interaction, and interruption management

  • Claims: The client/server boundary can remain simple even when the product surface expands: the described harness has one client-facing communication tool, "send to user," while server-side tools perform execution.; A single server-side interaction primitive lets the same agent operate through mobile, desktop, email, Slack, or other clients, with each client rendering the response appropriately.; Incoming work should be prioritized: direct user corrections can interrupt the current agent loop, while group-chat messages, Slack-thread activity, and background routines can queue behind them. Rapid consecutive messages can be batched into one turn.; A proactive agent needs an explicit decision policy for silence versus escalation; useful autonomous behavior is partly a notification-design problem.
  • Evidence: The client may render a sign-in interaction through 1Password, a payment interaction through services such as Stripe Link or X Money, an editable approval draft for non-reversible actions, or a lightweight emoji reaction.; The meeting example is agents joining meetings for employees who cannot attend, taking notes, and reporting back.; The speaker compares excessive progress pings to an annoying coworker and suggests that status cadence depends on the task rather than every intermediate action.
  • Caveats: The correct proactivity threshold is explicitly presented as unsolved: a contextual suggestion can be helpful or intrusive.; UI and interaction design should remain adaptable because model capability jumps may render current approval and steering patterns obsolete.
  • Implications: Separate the canonical agent state and action protocol from channel-specific presentation layers.; Define interruption rights and message priority by actor and risk level, rather than processing all events as equal prompts.; Instrument notification usefulness, suppression, and user overrides as product-quality signals.

Model-product flywheel and strategic design posture

  • Claims: Harness quality improves through an inner loop that turns production failures into evaluations and fixes, plus an outer loop in which later model versions learn from accumulated failures.; Main interactive agents and background workers should use different latency/cost profiles: low latency matters for the conversational coordinator, while a 10-minute versus 12-minute worker difference may not matter.; The speaker's design principle is to "delete the product": assume models are currently the worst they will ever be, keep interfaces minimal, and expect to rebuild major product assumptions as capability improves.; The emerging stack consists of durable workflows, sandboxes, cloud computers, memory, skills, integrations, identity, payments, observability, and evaluations; these are treated as durable primitives rather than a transient chat-app pattern.
  • Evidence: For a failure such as a wrong tool call, the proposed loop is: create an eval, identify whether the cause is harness/prompt/inference, fix it, verify the eval, and ship.; The training framing is pretraining for general knowledge, supervised fine-tuning for harness/tool behavior, and reinforcement learning for instruction following, skill selection, and browser interaction.; The speaker notes that group-chat bot behavior lacks extensive historical training data and cites the Moldbook and Huggy Face incidents as examples of how multi-agent social behavior can go wrong.
  • Caveats: Forecasts that agents will soon work for weeks or months, better learn skills on the job, and receive all the tools of a human employee are predictions rather than demonstrated outcomes in the lecture.; Rapid model releases create a validation problem for long-horizon agents that the speaker identifies but does not resolve.
  • Implications: Build an eval and observability pipeline alongside the first production harness, rather than treating it as later-stage quality work.; Avoid overinvesting in rigid UI workflows or model-specific interaction patterns that prevent rapid replacement.; View agent infrastructure categories as interdependent control-plane components, not isolated point solutions.

Notable Concepts & Terms

  • Always-on agent: A persistent, server-hosted digital colleague that can be triggered by events, retain state, execute background work, and decide when to report back.
  • Harness / context engineering: The system around the model—tools, prompts, memory, routing, compaction, safety, and execution environment—that determines whether a capable model can operate reliably in production.
  • Durable workflow: A failure-resilient execution model that persists progress and resumes from the point of failure rather than replaying a multi-step task; Temporal is the cited implementation.
  • Firecracker VM: The cited lightweight virtual-machine approach for giving an agent an isolated Linux computer that can be snapshotted, stopped, restarted, and patched independently.
  • Dynamic tool discovery / tool search: A context-saving pattern in which the model sees available tool names initially and reads full schemas or instructions only when it elects to use a tool.
  • Prompt caching: Reusing stable prompt prefixes—system instructions, tool definitions, and conversation history—to reduce token cost and latency; static ordering is essential to avoid cache misses.
  • Compaction: Lossy summarization of a long conversation into a smaller working context, ideally performed while the provider's cache remains warm and supported by layered memory artifacts.
  • Auto review: A separate AI review layer that checks proposed commands or actions, positioned as a scalable alternative to human approval fatigue but not a substitute for side-effect controls.

Operator Notes / Why Ken Should Care

  • Draft a reference control-plane design with durable workflow IDs, resumable task state, event routing, actor-based priority, and an explicit interrupt/cancel protocol for direct user messages.
  • Define a memory contract with four stores: immutable core preferences, dated durable logs, expiring scratch state, and searchable file artifacts; assign retention and garbage-collection rules to each.
  • Set production telemetry targets for cache-hit rate, context growth, compaction frequency and retrieval success, subagent completion/retry rate, notification suppression/override rate, and irreversible-action approval rate.
  • Require a trust-boundary review before connecting inboxes, Slack, webhooks, or browser tools: label external content as untrusted, restrict instruction promotion, isolate credentials, and gate external side effects.
  • Use a tool-selection ladder in the agent policy: native knowledge/context, structured integrations, search, browser automation, desktop execution, then human escalation.
  • Create a regression-eval pipeline from real failures, including wrong-tool calls, prompt-injection attempts, duplicate-action retries, stale-memory retrieval, interruption handling, and multi-agent/group-chat behavior.
  • Avoid locking product UX to today's capabilities; keep client rendering decoupled from the server protocol so approval, voice, and autonomous-work interfaces can be replaced without rewriting the agent core.

Source/Metadata

  • Title: Stanford CS146S: How always-on agents work
  • Transcript words: 16242
  • Duration seconds: 2717
  • Timestamp note: No timestamps or chapter markers were present in the supplied transcript. The transcript also contains a substantial repeated passage beginning around the agent architecture discussion.

Transcript

8545 words en Processed in 266.5s

So as mentioned, I'm Lee. We're going to talk a little bit today about how this new category of always-on, proactive, persistent agents work and give you some of the understandings of the building blocks for how these are made. Just as a fun statement up here, some of the things we'll talk about are in progress, we're working on at SpaceX. And in week one, you all built this very simple harness that helps you understand the core idea, which is that you have a model, it can call tools in a loop, and that's actually very powerful. It unlocks a lot of new capabilities for the models, but it does come with some drawbacks. Notably, you close your laptop and the process stops. It's no longer running. And I want to talk about how you can take this simple idea, it's very powerful for how to get more out of models, and extend it to this new type of agent, which is an always-on agent. So rather than just running in your terminal, this can run on a server. It can run in the cloud. You can close your computer. It can restart. It can survive crashes, for example. This agent has its own computer. So not just your laptop, but a Linux machine in the cloud, where it has its own desktop files, browser, and more, maybe some 3D apps. It can save files on the machine. It can understand more about your progress over time and build up a memory of how you work with it. Unlike a harness in the terminal that is responding to every message that you send, this type of always-on agent is more like a colleague, where it doesn't always immediately send you a message. It knows when to be quiet. Sometimes it might just want to work in the background a little bit and only come back to you when there's an important update. And it can be triggered more than just you typing. So it's not just you prompting it in the terminal. Maybe there was a Slack message or an email or some other type of event that wakes up this agent to go do work. And ideally, the hope with these type of always-on agents is that they can do work over very long periods of time. Not just hours or days, but maybe even weeks or months. And that just requires a little bit of a different architecture, which we'll get into. So we're going to go decently in-depth on how we built this architecture, how we built the harness, what's got us here today and where we're going in the future. And we'll get into some of the specifics of how we've engineered this system to be proactive, to be persistent, and to follow instructions very well. And, of course, time at the end for questions if you all want to ask anything about this or anything outside of what we've covered today. So first, how we got here. There's been four eras of developers working with AI so far, I would say. The first one was copy-pasting code out of ChatGPT and putting it into your editor of choice, which feels like decades ago at this point, but it was really only a few years ago. And then, once the model started to get better at having that simplified harness we talked about in the last lecture, they were able to edit files, run shell commands, have this very simple interface for how you work with them in the terminal. And this really took off because all of a sudden, the model had this new capability where it could go do more proactive work for you and be more productive. Then, this third era was taking the coding agents and giving them these dedicated apps. And at this point, people were starting to run many agents in parallel. Maybe they're running them in the cloud, not just on their machine. But still, at this point, you were the bottleneck in that you were reviewing every command that they were running. You wanted to make sure every shell command was just right. You're watching them and being in the loop on everything. And now, with improvements in models, in harnesses, in products, we're in this new era where you're starting to have these always-on agents. And they can run ambiently in the background where they have their own computer, they have their own memory, they learn new skills on the job, and they keep working after you go to bed or do other work. A good example of this is we've moved away from this world of prompting an agent every single day, although we still do that sometimes. But you can set up agents where it will run in the background. So maybe in the before times, it was you would prompt an agent, you would wait, prompt an agent, you would wait. And if it asked you to run a shell command, you would have to approve or disallow that command. And now, instead of queuing commands, you can steer the agent. And you might say, hey, go check this thread, and then immediately after, oh, by the way, actually go do that on Thursday. And prior generations of models would get confused when you would immediately interrupt it and give it some other command. But now they understand just like how you might ramble on talking to a friend and they can parse that these two things are related. The models and the harnesses can now handle that. And if you say, hey, go send this email, go send this Slack message, there are additional safety checks in place, which a lot of companies are calling auto review, which is essentially a separate AI model that's checking all of the commands that get run. So that's actually more secure than the fatigue of having to watch hundreds of shell commands and approve each one. We've reached the point where if you did a blind test with what the AI model is checking on the commands and what a human is checking on the commands, most of the time the model is actually doing a better job. As the models have gotten better, the interface has gotten quite a bit more simple, actually. And this type of always-on agent we're calling a bot. But as you'll notice, there's actually quite a few of these new types of products popping up right now and gaining a lot of traction. And I think the main reason is because we all know how to text. Everyone knows how to text. Everyone is pretty proficient with using their phones. And we've distilled down this way of working with AI that feels like you're texting a friend, but it can actually go and do real work for you. It's not just answering questions in a Q&A style setting anymore. It's actually going and doing longer tasks like you would hand off to a coworker, for example. So there's been a few changes specifically in the models that have enabled this to happen. I'll go over six, but there's quite a bit more. The first one is that the models over the past year or two have really gotten better at being able to follow instructions over a longer period of time where they don't get confused or make mistakes. And now models can pretty confidently run for hours or days with the right compression and compaction, which we'll talk about. Two, models now can essentially hand off to helpers. And those helpers are called subagents. And the reason why a subagent is helpful is the model has its working memory of the process that it's on, and that's going to fill up eventually. So it's nice if it can hand off to these helpers that have a fresh set of working memory. And that effectively can give it unlimited context, basically, where it can go and do work that might be expensive in terms of the tokens it's using or the tools it's calling, and then come back to the main agent and report its updates. Models now not only are better at calling tools. A few years ago, they basically couldn't call tools very well, and they would hallucinate all the time. You don't really hear people talk about hallucinations anymore because it's a solved problem, mostly. But not only can they call tools, but you can give them very powerful tools the same way as if you onboarded somebody onto your team. So obviously running shell commands and files, but also you give them a full computer, a full Linux computer. You allow them to make demo videos and such. They can click around on a screen just like a human would, and they're getting increasingly better at doing that, otherwise known as computer use, which basically means that any SaaS product or any website that didn't expose an API or an MCP server can be used headlessly, autonomously through computer use by these models and these bots. You can store all of the information in files, and the reason you can do that is because it's very easy for the models to recall and search this information, which we'll talk about. And then finally you can just show the bot how to do some work, and it will turn that into skills or memories or routines or things that it can reuse later. So obviously running shell commands and files, but also you give them a full computer, a full Linux computer. You allow them to make demo videos and such. They can click around on a screen just like a human would, and they're getting increasingly better at doing that, otherwise known as computer use, which means that any SaaS product or any website that didn't expose an API or an MCP server can be used headlessly, autonomously through computer use by these models and these bots. You can store all of the information in files, and the reason you can do that is because it's actually very easy for the models to recall and search this information, which we'll talk about. And then finally you can show the bot how to do some work, and it will turn that into skills or memories or routines or things that it can reuse later. So on the file thing, for example, this is a simplified example, but you might remember or imagine that when you're working with a bot, under the hood it might look something like this. You build up this profile or understanding of the user, and that's going to be included in every single prompt. Maybe you prefer lowercase text-like messaging, and every single message should have that. Also, as you're working with these bots over time, you're building up a working log, just like if you were working with a colleague and they were writing down notes every day of the work that they've done. That's all being put into files that the model can then decide to search or use later. If you say, hey, what did I do last week? It just can go and look that up. And the models are very good at using Linux commands, running shell commands to grep and search and look through these files. Similarly, with skills, you are essentially taking your knowledge of how to do a specific task and encoding it into a markdown file, the very specific process you need to do, the things that you believe make that successful or unsuccessful. And that's not just your skills. There's a whole ecosystem now of companies and developers writing these skills for how to send a great email or how to build a great API or many different things. And in GrokBot, there is a whole system of plug-ins. So basically, any tool that you want to use, there's a plug-in you can install which uses skills or servers. And then also routines, which, if you're familiar with CronJobs, you're running some prompt on some kind of schedule, which is pretty useful as well. So basically, everything is computer. Part three. So let's go a little bit further into the mind of this always-on agent or going behind the scenes. What does it mean for the agent to be always-on? You can read this chart from left to right, but it starts out with the server being asleep and also this computer that the agent can use being asleep. And so whether you send it a message or some kind of trigger decides to make the agent start up, which we'll talk about in a second, that's basically loading up and booting up all of the state for this agent, and it's running on a server. If it decides that it needs to use a computer, maybe it wants to go use the computer's browser or go click around on the computer, it can start up the computer as well. And then once you're done using it, it also has the ability to put those to sleep. Why is this important? It would be expensive and also there's not enough computers in the world to just have those computers running all of the time for everyone as well as a lot of server usage too. And so this state can then be persisted to a database, the conversation logs, the memories, the routines, all of that. How does the agent get woken up then? Well, obviously you can prompt it directly, but what's increasingly interesting is having other things running in the background that can then decide when you want to reach out to your bots. Maybe that is somebody pinging you on Slack and your bots can live in Slack. Maybe that's a phone call or a meeting that you put your bot in. It's increasingly common now at SpaceX where we see bots joining meetings for employees where they couldn't make it to the meeting, but they want their bot to go and take notes and come back to them, which is funny. Maybe you had some routine or some background work that was taking hours or days to do and then you want to come back and give you a summary. That all happens. Then we have a router that dedupes that and figures out how to put it into the conversation. And then it has this heuristic of do I need to bug the user about this or not? Because not everything is actually important. Just like if you have a coworker working on something, it would be annoying if every single time they made progress on something, they came and bugged you like, hey, check it out, I made progress on this thing. You really only need a status update, I don't know, every day depending on the task. So I talked about how the agent has this computer, this Linux box. This is running a Firecracker virtual machine. And the reason this is really helpful is because it's very easy then to essentially snapshot the state of the machine and shut it down and start it back up. And on this machine, you, of course, have files, but you can connect into the machine and have a live view of the machine and actually control it yourself if you want. The machine can, of course, run commands, which is great if you're going to run some shell commands. Maybe you don't want it on your personal laptop. You want it in this other environment that is secured and locked down. And then another interesting thing is, of course, it has Chrome and it can use a browser, but you can also make it essentially have virtual desktops. So if you're running five bots, ten bots, and each one of them needs their own browser, you can essentially let them have different screens. And all of this is shared infrastructure between these bots where they can go call on these computers. So we talked about the triggers that will wake up the agent. That's on the left, so different apps or Slack messages or emails. Then you have this middle piece, which is the server. And then on the right is the computer that we just talked about where you can run files and commands and other things. So let's talk a little bit more about the server. I already mentioned that commands will come in. They get put into this queue. And then it calls the purple box, which is the agent loop. And this is what we covered last week. This is a model calling tools in a loop. And then when you shut it down, you can save the state to the database or storage. So it's interesting to look at this and realize there's this one small piece that can then have all of these abstractions built on top to create a very powerful product when you give it all of these helpful tools and you connect it to all of these different services. The reason the agent runs on the server is a pretty common practice in computing where you want a thin client and a thick server. And computing has oscillated between these things over the years. But there are a few good reasons for this. Let's say you need to push an update to the agent code. It would suck if you had to push an app store update just to get that code out there versus just pushing a bunch of server updates very quickly. Also, sometimes you need to do heavy computation work, transcription or image generation or something. And that's probably going to be faster on a server than on device depending on what the devices are. And there are very established ways that we know how to scale servers, especially with variable traffic and variable growth. But the most critical thing here is that if you put the agent loop on the virtual machine, then you can't shut down the virtual machine independently from the agent server. So you want to save everything on the server so you can always rebuild that virtual machine. For example, if you need to do some critical zero-day Linux update on the VM, it would be great to be able to rebuild that and not blow away the entire agent loop and have downtime in the application. When you hit send, this is maybe a little in the weeds, so I'll just gloss through it. But basically, if you want to dig more into learning about distributed systems and thinking about strong versus eventual consistency, which are fun topics to get into, you send a message. And you want the client to immediately identify that and acknowledge it. Then when you go into the turn, you're obviously putting these tools in a loop with the model, saving that to the database. And then the clients are essentially putting subscriptions with all of the servers so they know if something changed and they're listening for these signals. And if they get a signal, then they can go and essentially fetch the latest information from the server. Well, it would be great to be able to rebuild that and not blow away the entire agent loop and have downtime in the application. When you hit send, this is maybe a little in the weeds, so I'll just gloss through it. But if you want to dig more into learning more about distributed systems and thinking about strong versus eventual consistency, which are fun topics to get into, you send a message. And you want the client to immediately identify that and acknowledge it. Then when you go into the turn, you're putting these tools in a loop with the model, saving that to the database. And then the clients are essentially putting subscriptions with all of the servers so they know if something changed and they're listening for these signals. And if they get a signal, then they can go and essentially fetch the latest information from the server. And there's some fancy deduping you can do to make sure if there were some kind of retries that you would not show multiple messages in the list. And so the underlying infrastructure primitives to think about here is a workflow versus a job queue. And the main difference here is with a job queue, you're going along on steps. You ask your agent to go and do some kind of complicated task. And it's making its way from step one to step two to step three. But then for some reason there was an infrastructure issue, there was some problem. With a normal queue, if that crashes and you go to restart it, well, now you have to replay steps one, two, and three, which could be pretty problematic. So what you really want here is a durable workflow, which means that it's safe for you to actually retry that. And when you retry after a failure, it picks right up on step three. And this is a solved problem in some ways in distributed systems and in infrastructure. So we use an open source tool called Temporal, which is interesting to look into if you're curious, so that we don't have to rebuild a lot of this very complicated stuff from scratch. Of course, you start to run the infrastructure for it, but some of the pieces to put together there. So let's say a new message comes in. There's different priorities based on whether I'm messaging my agents or messaging my bots versus if it's in a group chat or a Slack thread or some background routine, for example. So if I say, oh, actually, change the date for this event, we actually want that agent loop to stop. And my message is going to have priority over everything else that's happening, which makes sense. For everybody else, you're putting things into the queue in the back of the line. And if the agent gets three or four messages very quickly, it's able to batch those together. So it's just one turn. You can figure out whatever heuristic you want there. And then it goes through and does each turn at a time. Okay. So let's talk about the harness itself. And this is going to take the basic harness that we talked about last week and add some new tools, some new concepts to it. The biggest difference with the GrokBot harness and probably some of the other tools like this on the market is the way we've done the thin client fixed server architecture is there's only one tool that communicates between the client and the server. And it's just send to user. And the great thing about this is that it's architecturally simple where the client is just texting the server in some ways. And you're putting a lot of these heavier tools on the server. And there's many of those tools. There's running shell commands, reading files, but also calling on a cloud agent or recording your screen or doing demos, for example. And this has worked pretty well because now, regardless of where you spin up a new client, whether it's a mobile app, a server, a desktop app, email, Slack, it all just has this one single tool that communicates back and forth with the server. On the client, though, even though it just has this one tool, when it receives the tool, it can decide how it wants to display that in a rich and interactive way that makes the most sense for the user. So if it gets information back from the server that the user is trying to log into something, it can show these unique sign-in forms and connect to tools like 1Password. It can call on services like Stripe Link or use X Money or other services to allow people to pay for their services. If you're trying to do something that you can't reverse it, sending an email or a Slack message, it might come back and ask you to edit and approve a draft before you send it. And then sometimes you can just leave an emoji reaction if you don't actually need to send a message. So going back to what I was saying with dynamic tool discovery, for any model, there's a context window, which is its working memory. And that's some limit in tokens. And if you just jam every single tool possible into that context window, you're not going to have a lot of space. And the way the tools work is you have the name of the tool, you have the schema, you have all these different details. And if you start installing your Google Drive connector, your Gmail connector, your YouTube connector, like all these different services that use MCP servers, which all have tools, you're going to start looking at something like the top, where a lot of the blocks are already filled. And the problem with that is it doesn't give the model as much space to actually do the work of the conversation. So one kind of context engineering or harness trick that a lot of the popular harnesses now use is it's called dynamic context, or some other folks call it the tool search tool, which is a fun name. But basically, you're only putting the names of the tools into every message that gets sent to the model. And then the model can decide, okay, I actually want to go use this tool, I can go read the information from a file. It's files and a file system all the way down for all of these things. And that just helps you save on your context usage, which then also helps save on costs, save on usage, which is better for everybody. In general, the principle here really is to try the cheapest option or the most reliable option first and work your way up the ladder. So the easiest one is just what the agent or what the bot already knows based on the conversation history. If it's not in the immediate context, maybe there's a plugin, an MCP server, some kind of API that it can go and pull your banking information from Plaid, for example. Maybe that doesn't work and it needs to go do some kind of web search to see what the score of the Cubs game was last night. Maybe if it doesn't have that, it actually needs to go to the computer and open up the browser and do some searches on there. And finally, maybe it needs to go and actually use the entire desktop, so run scripts or run commands or build things on that Linux computer. And only if all of those fail, then go bug the user and ask them to give input or approve something. And this really helps it feel like what it would be like to work with a colleague. They're not going to bug you for all these different things. Ideally, they're going to try a lot of these options first. On that computer, so the Linux machine that the agent is able to use, there's three different ways that it can retrieve information from it. Of course, it can just take a screenshot of the screen, but there's more efficient ways of doing this. It could also look at the HTML of the page, but you can also look at the accessibility tree, which is a nice way of cutting down a lot of the token usage. And basically to help you find the buttons or links or other elements that you want the browser to click on. Of course, if none of that works, you can just click on pixels. So some websites, for example, have modals or dialogues that pop up that you need to click. And so your model, your agent needs to have that functionality as well. Or, worst case on that ladder is you go back to the user and there's a two-factor auth code or some kind of captcha or something like that. So the idea is that putting the pieces together, you have this main agent. And it's your orchestrator. And the main agent, you want to keep the conversation as sparse as possible because it now has the ability to go call on all of these different helpers. And the helpers are just sub-agents. And so this is helpful because if you hand it off to a helper to go run a bunch of shell commands or do a lot of expensive tool calls, all of that work that ultimately is ending up in some answer to a question or a task, none of that is bloating the conversation in the context of the main agent. It's only coming back with the result. And this is how you get to a product that feels like it has infinite context. So the idea is putting the pieces together, you have this main agent. It's like your orchestrator. And the main agent, you want to keep the conversation as sparse as possible because it now has the ability to go call on all of these different helpers. And the helpers are just sub-agents. And so this is helpful because if you hand it off to a helper to go run a bunch of shell commands or do a lot of expensive tool calls, all of that work that ultimately is ending up in some answer to a question or a task, none of that is bloating the conversation in the context of the main agent. It's only coming back with the result. And this is how you get to a product that feels like it has infinite context. Obviously, infinite context is not a real thing. Every model has a context limit. But there are these tricks and workarounds such that, especially when you train models to get better at this, that it doesn't feel like you're running up against the limits of the context window. And you don't feel a degradation of the model's quality as you get further along that as well. So we have these different helpers, each with different skills. Each one of these is its own durable workflow. So going back to the cues versus workflows thing, that means if it fails, the video helper crashes, something uses up too much memory or something, that can restart and keep going without losing progress along the way. And then the main agent, it is a co-worker where it's managing a to-do list. You have a few things you can do. You can go check on it. You can send it a message. You can stop the helpers, for example. And so a lot of this is modeled after the ideal way you would scale a team of engineers working on a very complicated problem. So just a few little interesting tidbits from building this out on the team. I think we'll talk a little bit more about prompt caching here, but ideally you don't add or remove new tools during turns. And just like I mentioned with the slide with all of the boxes, if you have extremely long tool descriptions or schemas, that's going to take up a lot of space in the context window, which is bad for pricing. It's bad for usage. Ideally, you want to minimize that. So there's plenty of optimizations you can make here on the engineering side to just trim that down. Another interesting one is if you hear people talk about how we can have a harness that just has one tool. And that one tool is running shell commands. And this is true, and you can model a lot of things this way. But if you see the model doing 90% of its time doing shell commands for this one thing, it actually can be more efficient to make a dedicated tool for some of that stuff. And it's a bit more legible for people actually reviewing how the product is working. And the last one's funny too. Obviously, if you're writing errors for humans, it's helpful to make it very descriptive. Like, okay, this thing failed. Here's what you need to do next. Turns out that's also very helpful for agents. So there is some DX in designing good error messages for agents too. And when you're trusting your bots to go and do work over a long period of time, it is very important that you trust them to be secure with your information, to be secure with how it operates. So even working on its own separate machine, not polluting anything on your machine, still you would like it if a model reviews every shell command before it goes. So auto review. It would be great if, when these untrusted inputs, like an email in your inbox, could be a phishing email or some web hook, you don't want to send that to the model and act like it was a user instruction. And there's plenty of work to do here in the industry on just making sure that that is properly protected from prompt injections. For these non-reversible things like sending emails, right, you want to really ask the user first. And then also you can build in some workflows into the product to keep passwords and other things outside of the model conversations. Context engineering is also known as harness engineering. It's the same thing. They've evolved over time. But basically what are some tips and tricks we can do to minimize the amount of context that's being used in these harnesses, which is good for efficiency, for reducing costs and other reasons. I talked about prompt caching. This is a good example of why it's really important. So if you think about when you're working with a coding agent or any agent, most of the tokens used are actually ideally cached tokens because you're sending in a conversation and then you're doing a change, you're adding one more message, and then you're basically resending the entire conversation over again. So if you look at the pricing for models, there's huge discounts on cached tokens. And you want to keep them in the cached window as long as possible. And so a way to do this is you try to keep the tool definitions, the system prompts, all this information as static as possible between different calls so that you don't break the cache and then have to pay for the uncached tokens every single time. So if you have that fixed part at the top, then when you get down to the bottom and you only have the newest message that comes in, that's the only delta that you're paying the uncached tokens for. And there's a whole art and science to this as well. Basically because that main agent, in the most ideal sense, this is the one you're having this very, very, very long conversation with that's compacting or compressing, so summarizing the context, many, many times over without you even noticing sometimes, which we'll show an example of. So you really want to keep that context small. Some ways of doing that is anytime there's a very long output, rather than stuffing that in the context, you can just put it in a file. And the agents are very good at reading files, so this actually works pretty well, which is just like reading a skill or reading a memory, for example. If you give the model a screenshot or some other very expensive work, you just delegate that out to a helper. Again, so it goes to the subagent, and it doesn't affect the main agent's context. And then also, in an ideal world, you want to be always gardening and trimming and removing unnecessary stuff from this conversation, from this context window, as you're going, both for cost but for also recall and just making sure the model's performing well. So if there's a cache miss, it's a bug in the system, really. And if you go all the way back to January of this year, when OpenAI was really getting popular and people were using it inside of subscription plans for model providers, this was a very new usage pattern that model providers hadn't really seen. And the harness hadn't really yet been optimized for this type of workflow. So there was a lot of cache misses. And when you're doing something like this, where agents are running all the time, that's obviously problematic. So lots of fixes had to go in to make that robust to keeping the prompt cached as much as possible. So a fun trick here is just trying to keep everything in the prompt in order such that even if you deploy a new change where you want to test out some new change to the system prompt or add a new tool, you can almost hash each section and always keep a fixed order. Let's say you're doing an A-B test and you want to put a new piece of the prompt in there. You really don't want that to screw up the prompt order for everybody else. Otherwise, you just busted the cache. And then that's problematic. Another fun one is when you open the chat and you start typing, the server can actually go and prepare the prompt early to basically warm the cache. Almost like if you're on a website and you go to hover on a link, it can go and prefetch the next page. So there's tons and tons of little engineering optimizations that compound how far these models can go in terms of token usage and how smart they can be when you use them for very long periods of time. And the key thing is that when you're working over a very long period of time, you essentially have to get very good at compaction or summarization because let's say the model has a 200,000 token context window. You're going and going and going. Eventually, it's going to hit a point where it needs to summarize. And all compression is lossy. So you have to figure out the best algorithm to do the compression and not lose important details. And there's, I'm sure, entire PhDs just for this problem. It's very, very tough to do, right? But just to show an example, let's say you're going back and forth with your bot. You have over 100,000 tokens and then you go and do something else. Well, there is this time period where the model providers have a cache window when the cache is still warm. Maybe it's 10 minutes, maybe it's 60 minutes. One trick that we do, which I think is really helpful, You essentially have to get very good at compaction or summarization because let's say the model has a 200,000 token context window. You're going and going and going. Eventually, it's going to hit a point where it needs to summarize. And all compression is lossy. So you have to figure out the best algorithm to do the compression and not lose important details. And there's, I'm sure, entire PhDs just for this problem. It's very, very tough to do, right? But just to show an example, let's say you're going back and forth with your bot. You have over 100,000 tokens and then you go and do something else. Well, there is this time period where the model providers have a cache window when the cache is still warm. Maybe it's 10 minutes, maybe it's 60 minutes. One trick that we do, which I think is really helpful, is while you're still within the warm cache period, you should probably do the compaction right now because you have this long conversation. It's going to be much cheaper. So just go ahead, do the compaction. And now when the user comes back in 30 minutes or whatever, they're starting from this summary. And the summary now is going to be much cheaper for them to continue adding messages on. So lots of work to do there to make the algorithm very high quality for how you do the summarization. When you talk about compaction and what information you choose to include in the agent's memory, I kind of think about it in a few different layers. The first one is facts about the user that are very important to be included every single time. Going back to earlier when I said the user always wants to have lowercase text. That probably needs to be in every single message. Otherwise, it would be really weird if one message now has uppercase letters. If you're going full Sam Altman style. Then you probably also have some prompts or some facts that you want to include in there. And there's many different ways you can make this algorithm to determine what are the most important facts to keep. So ideally, there's this kind of garbage collection of this fact. And if you think about it, this is kind of how our brains work. This fact right now is important to keep. It's relevant for this conversation today. You're probably not thinking about a soccer match right now. And your brain is very good at keeping those ones in context right now and kind of remembering them for later. We tried to model some of that here where the harness has, of course, these core facts. It also has these dated logs of your past conversation history, essentially. And then also these kind of scratch pad notes. So it's little things that you've been working on right now that are designed to be ephemeral and they will go away, but they might be relevant just for the next 30 minutes or an hour. And everything else can be found through files. This is the magic of files of the models being good at running commands. It's like they can always just go look stuff up. And they're actually very good at doing that. So where is this going? There is this flywheel of training the model to get better at the product. And this is a high-level refresher on the stages of training a large language model. First, you have pre-training where the model learns a general understanding of the world from large amounts of Internet text or other private data. Then you have supervised fine-tuning where you're teaching the model how to behave in a certain way, maybe as a chat assistant or as an agent. And then finally you have reinforcement learning where it's kind of like teaching the model how to play games and get better at those games. In the context of these always-on agents, it's very helpful, for example, to train the model to see examples of the harness and to know how to work inside of the harness in SFT so it can understand the tools that you have available. It's helpful to train the model to be better at instruction following during reinforcement learning, how to understand the right skill to call when there's hundreds of skills, for example, how to click on the right spots when you're given a browser and it needs to click around. And not only the training itself but also how you serve the model, the inference that you do. The main agent you're talking with, you ideally want it to have very low latency. You want it to come back to you right away, give you really fast replies, and you can tune the harness and the inference to do that. But then when you hand it off to a helper and you're asking it to go do some work for a very, very long period of time, the difference between 10 minutes and 12 minutes is negligible at that point. So that allows you to control how you optimize things. The way this flywheel works is that let's say your agent gets something wrong. Ideally then that gets turned into some kind of evaluation. The model accidentally called this tool and it wasn't supposed to. Then on the back end you can go and fix the harness, you can fix the bug, you can fix the prompt, maybe it's an inference issue. You can check and make sure it's actually fixed in the evals and then ship the change. And the teams and the products, the teams working on these products, they're doing this every single day. They're finding bugs, they're fixing it, they're measuring it with evals. That's this inner loop that you're always getting better at. But then there's this outer loop, which is every few months or every month or however long you're training new models. And ideally the new models are learning from all of these bugs and these failures and they're climbing on the evals to get better at the things that you care about. And you can drop the new versions into the product and make sure that they're improving at all these different things. And the fun thing about this is then when the new models come out, they have new capability jumps. It allows you to use the product in new ways. So there hasn't really been a lot of training data, for example, on using bots in a group chat. This is an emergent thing that's being figured out and it's important to get it right. Obviously, if you've seen things like Moldbook or the Huggy Face incident, there are ways that that goes poorly. So it's important to be able to train the models how to behave well in a multi-agent system where different bots are talking to each other, for example. And so ideally you're always running these inner loops and outer loops as a product team building these type of harnesses at a company working on AI together. One of the principles that we had at Cursor and now at SpaceX is to delete the product. And what we mean by this is you have to internalize and assume that the models today are the worst they'll ever be, which means that in six months you might need to completely rebuild the UI. Most of the stuff that I've talked about today is a pretty big update from if I would have given this talk six months ago or definitely a year ago because we've learned a lot of new practical ways of building harnesses and doing context engineering. So a good strategy here is you really want to try to build for the next generation of the model. How do you build as little as possible and get by while making just a really, really simple interface to work with these models and allow them to think and act for you. So some things that I think will happen in the next six to 12 months, we'll see. I think these are decently safe bets. But right now let's say you have your agents or your bots working for maybe a few hours, maybe a day, depending on how tough it is. I think it's very possible that pretty soon your agents will be working for weeks or months. And it does bring up some interesting questions in terms of how we train and evaluate those models. I think the models are going to get better and better about how they recall on past information in conversations. Plenty of different approaches in research here for the type of algorithms used or the representation of the data under the hood. Maybe it's a graph, maybe it's files, maybe something else. I think ideally if you have this digital colleague, you give it literally all the tools that you have if you were onboarding a real human. And so I think organizations are still warming up to that idea, of course. So there's more to do there. I think the interfaces will maybe get even easier. I think some people will prefer to just talk to their bots or agents in a speech-to-speech way. Maybe they'll have their Johnny Ive device that is hopefully really cool and they can talk to that all day. I think the models and the products will get really good at learning skills on the job and then encoding that into files and instructions, skills, and taking that raw intelligence and actually making it useful for whatever task you're asking it to do. And people and companies are going to get much better, I think, about writing down how all of these bespoke processes work so that they're legible for agents to use. So some interesting problems, I think, You give it literally all the tools that you have if you were onboarding a real human. And so I think organizations are still warming up to that idea, of course. So there's more to do there. I think the interfaces will get even easier. I think some people will prefer to just talk to their bots or agents in a speech-to-speech way. Maybe they'll have their Johnny Ive device that is hopefully really cool and they can talk to that all day. I think the models and the products will get really good at learning skills on the job and then encoding that into files and instructions, skills, and taking that raw intelligence and actually making it useful for whatever task you're asking it to do. And people and companies are going to get much better about writing down how all of these bespoke processes work so that they're legible for agents to use. So some interesting problems that could spark ideas for you all to research or to look into. The first one is going back to this idea of agents that run for a month. What do you do when you need to evaluate an agent that runs for a month, but the models ship every month? It's like you can't fully evaluate that the model is sufficiently behaving as expected, so you either have to figure out how to do a better eval or not ship models as fast. And I think that's going to be a problem that the industry has to figure out in the next six months. Memory, obviously, we talked about the different algorithms. I think there's so much to do on the security side for how to make a secure harness, how to make the infrastructure around these agents very secure, and so they can't be taken over by bad actors. I think we didn't really talk about it too much, but the heuristics around when the agent is silent or when it bugs you—I don't think that we have it perfect yet. And I think trying to thread the needle between being proactive and suggesting, like, oh, hey, I saw that you missed class yesterday. I had a recording there, and I took the notes, and here's the thing. Maybe that's helpful, or maybe that's annoying, and trying to figure out the right balance there. I also think that it's a pretty safe bet to assume that at this time next year, there will be significantly, significantly more tokens flowing in the world, which means that optimizing the inference, optimizing the models, optimizing the harnesses, trying to drive down the token usage to be more efficient will also be very important. So there's these new building blocks to think about. I believe it was Alex from Open Router that I saw on X. He had a really good take on this. There were people saying, every app today looks the same. You've got the sidebar, you've got the agent, you've got the chat box. Everybody's building the same thing. And he was like, yeah, that's like in 2005. Everybody's building the same thing. They've got a server. They've got a database. They've got a CRUD interface to update and delete things. And the reality is, this is just the new normal now where every new product is going to have to have some kind of agentic side to it, either integrating or it will become a headless piece of data for another agent to use. And so we've talked about a lot of these products today: durable workflows, sandboxes, computers in the cloud, memory, skills, connecting to other services, doing voice, payments, identity, evals, observability. Each one of those boxes is multiple billions of dollars of VC capital, probably trillions. There's 20 startups for each one of those. And there's so many different things to explore in all of those because they are the new primitives for the next generation of companies, the next generation of products. And they all have to integrate and be part of harnesses. So there's definitely a lot to do there. A few things to take away, and then we'll have time for questions. Obviously, you all are engineers. You're thinking about how to write software. It's more important than ever to think about the broader system design and the architecture of the code that you're working on because the decisions you make there will really compound. So I'm still pro looking at code. I still look at the code that I'm writing. Some people are not looking at the code. I still think it's helpful, especially to understand the architecture that you're shipping. It's crazy how much that's changed in just a couple years. Secondly, it sounds like you all were messing around with building your own versions or understanding of how the harness worked last week. I encourage you to think about some of the things that I did today and try to apply that and think about how you might build a version for yourself. I'm pretty sure there's open Grokbot on GitHub somewhere where somebody's forked code and made a version. And you could probably set up the GUI for that with a sandbox somewhere and a VM and all sorts of different things. So that could be interesting if you want to learn more about how these pieces work. And then, finally, I would not shy away from just learning more about how LLMs work. We gave a little bit of the TLDR here of how they're trained. But there's so much more you can go into without necessarily going deep in ML or deep into the science part of it. But I think it's helpful to understand—just like when you're building a web app, it's helpful to know how databases work because increasingly, there are so many decisions you make at the product and the harness level that are influenced by the models themselves. And having an intuition of how that works I think will make you very well positioned for whatever role you're operating in. And that's all I have today. Thank you. the very specific process you need to do, the things that you believe make that successful or unsuccessful. And that's not just your skills. There's a whole ecosystem now of companies and developers writing these skills for how to send a great email or how to build a great API or many different things. And, for example, in GrokBot, there is a whole system of plug-ins. So basically, any tool that you want to use, there's a plug-in you can install which uses skills or servers. And then also routines, which, if you're familiar with CronJobs, you're running some prompt, basically, on some kind of schedule, which is pretty useful as well. So basically, everything is computer. Part three. So let's go a little bit further into the mind of this always-on agent or going behind the scenes. What does it mean for the agent to be always-on? You can kind of read this chart from left to right, but it starts out with the server being asleep and also this computer that the agent can use being asleep. And so whether you send it a message or some kind of trigger decides to make the agent start up, which we'll talk about in a second, that's basically loading up and booting up all of the state for this agent, and it's running on a server. If it decides that it needs to use a computer, maybe it wants to go use the computer's browser or go click around on the computer, it can start up the computer as well. And then once you're done using it, it also has the ability then to basically put those to sleep. Why is this important? It would be expensive and also there's not enough computers in the world to just have those computers running all of the time for everyone as well as a lot of server usage too. And so this state can then be persisted to a database, the conversation logs, the memories, the routines, all of that. How does the agent get woken up then? Well, obviously you can prompt it directly, but I think what's increasingly interesting is having other things running in the background that can then decide when you want to go reach out to your bots. Maybe that is somebody pinging you on Slack and your bots can live in Slack. Maybe that's a phone call or a meeting that you put your bot in. It's increasingly common now at SpaceX where we see bots joining meetings for employees where they couldn't make it to the meeting, but they want their bot to go and just take notes and come back to them, which is kind of funny. Maybe you had some routine or some background work that was taking hours or days to do and then you want to come back and give you a summary. That all happens. Then we have basically a router that dedupes that and figures out how to put it into the conversation. And then it has this heuristic of do I need to bug the user about this or not? Because not everything is actually important. Just like if you have a coworker working on something, it would be pretty annoying if every single time they made progress on something, they came and bugged and were like, hey, check it out. I made progress on this thing. You really only need a status update maybe, I don't know, every day depending on the task. So I talked about how the agent has this computer, this Linux box. This is running a firecracker virtual machine. And the reason this is really helpful is because it's very easy then to essentially snapshot the state of the machine and shut it down and start it back up. And on this machine, you, of course, have files, but you can kind of connect into the machine and have a live view of the machine and actually control it yourself if you want. The machine can, of course, run commands, which is great if you're going to run some shell commands. Maybe you don't want it on your personal laptop. You want it in this other environment that is, you know, secured and locked down. And then another interesting thing is, of course, it has Chrome and it can use a browser, but you can also make it essentially have, like, virtual desktops. So if you're running five bots, ten bots, and each one of them needs their own browser, you can essentially let them have different screens. And all of this, again, is kind of shared infrastructure between these bots where they can go call on these computers. So we talked about kind of the triggers that will wake up the agent. That's kind of on the left, so different apps or Slack messages or emails. Then you have this middle piece, which is the server. And then on the right is the computer that we just talked about where you can run files and commands and other things. So let's talk a little bit more about the server. I already mentioned, you know, commands will come in. They get put into this queue. And then it calls the purple box, which is the agent loop. And this is what we covered last week. Like, this is a model calling tools in a loop. And then when you shut it down, you can kind of save the state to the database or storage. So it's interesting, I think, to look at this and realize there's this one kind of small piece that can then have all of these abstractions built on top to create a very powerful product when you give it all of these helpful tools and you connect it to all of these different services. The reason the agent runs on the server is a pretty common practice in computing where you want to have kind of a thin client and a thick server. And computing has kind of oscillated between these things over the years. But, for example, a few good reasons for this is let's say you need to push an update to the, you know, the agent code. It would, you know, kind of suck if you had to push an app store update just to get that code out there versus just pushing a bunch of server updates very quickly. Also, sometimes you need to do heavy computation work, you know, like transcription or image generation or something. And that's probably going to be faster on a server than on device depending on what the devices are. And, you know, there's very established ways that we know how to scale servers, especially with variable traffic and variable growth. But the most critical thing here is that if you put the agent loop on the virtual machine, then you can't shut down the virtual machine independently from the agent server. So, yeah, you want to save everything on the server so you can always kind of rebuild that virtual machine. For example, let's say you need to do some critical zero-day Linux update on the VM. Well, it would be great to be able to rebuild that and not, you know, blow away the entire agent loop and have downtime in the application. When you hit send, this is maybe a little in the weeds, so I'll just kind of gloss through it. But basically, if you want to dig more into learning more about distributed systems and thinking about, you know, strong versus eventual consistency, which are just fun topics to get into, you know, you send a message. And you kind of want the client to immediately identify that and acknowledge it. Then when you go into the turn, you're obviously putting these tools in a loop with the model, saving that to the database. And then the clients are essentially putting subscriptions with all of the servers so they know if something changed and they're listening for these signals. And if they get a signal, then they can go and essentially fetch the latest information from the server. And there's some fancy deduping you can do to make sure if, you know, if there were some kind of retries that you would not show, you know, multiple messages in the list. And so the, like, underlying infrastructure primitives to think about here is a workflow versus a job queue. And the main difference here is with a job queue, let's say you're kind of going along on steps. You ask your agent to go and do some kind of complicated task. And it's making its way from step one to step two to step three. But then for some reason there was an infrastructure issue. There was some problem. With a normal queue, if that crashes and you go to restart it, well, now you have to replay steps one, two, and three, which is obviously that could be pretty problematic. So what you really want here is you want a durable workflow, which means that it's safe for you to actually retry that. And when you retry after a failure, it picks right up on step three. And this is, like, kind of a solved problem in some ways in distributed systems and in infrastructure. So we use an open source tool called Temporal, which is interesting to look into if you're curious, so that we don't have to rebuild a lot of this very complicated stuff from scratch. Of course, you start to run the infrastructure for it, but some of the pieces to put together there. So let's say a new message comes in. There's different priorities based on whether I'm messaging my agents or messaging my bots versus if it's in a group chat or a Slack thread or some background routine, for example. So if I say, oh, actually, you know, change the date for this event, we actually want that agent loop to stop. And my message is going to have priority over everything else that's happening, which kind of makes sense. For everybody else, you're kind of putting things into the queue in the back of the line. And if the agent gets, you know, three or four messages very quickly, it's able to kind of batch those together. So it's just one turn. You can kind of figure out whatever heuristic you want there. And then it kind of goes through and does each turn at a time. Okay. So let's talk about the harness itself. And this is going to kind of take the basic harness that we talked about last week and add some new tools, some new concepts to it. The biggest difference with the GrokBot harness and probably some of the other tools like this on the market is the way we've done the thin client fixed server architecture is there's only one tool that communicates between the client and the server. And it's just send to user. And the great thing about this is that it's actually very architecturally simple where the client is just texting the server in some ways. And you're putting a lot of these heavier tools on the server. And there's many of those tools. There's running shell commands, reading files, but also calling on a cloud agent or recording your screen or doing demos, for example. And this, I think, has worked pretty well because now, regardless of where you spin up a new client, whether it's a mobile app, a server, a desktop app, email Slack, it all just has this one single tool that communicates back and forth with the server. On the client, though, even though it just has this one tool, when it receives the tool, it can decide how it wants to display that in a rich and interactive way that makes the most sense for the user. So if it gets information back from the server that the user is trying to log into something, it can kind of show these unique sign-in forms and connect to tools like 1Password. It can go and call on services like Stripe Link or use X Money or other services to go and allow people to pay for their services. If you're trying to do something that is non- you can't reverse it, sending an email or a Slack message, it might come back and ask you to edit and approve a draft before you send it. And then sometimes you can just leave an emoji reaction if you don't actually need to send a message. So going back to what I was saying with dynamic tool discovery, so for any model, there's a context window, which is kind of its working memory. And that's some limit in tokens. And if you just jam every single tool possible into that context window, you're not going to have a lot of space. And the way the tools work is you have kind of the name of the tool, you have the schema, you have all these different details. And if you start installing your Google Drive connector, your Gmail connector, your YouTube connector, like all these different services that use MCP servers, which all have tools, you're going to start looking at something like the top, where a lot of the blocks are already filled. And the problem with that is it doesn't give the model as much space to actually do the work of the conversation. So one kind of context engineering or harness trick that a lot of the popular harnesses now use is it's called dynamic context, or I think some other folks call it the tool search tool, which is a fun name. But basically, you're only putting the names of the tools into every message that gets sent to the model. And then the model can decide, okay, I actually want to go use this tool, I can go read the information from a file. It's kind of files and a file system all the way down for all of these things. And that just helps you save on your context usage, which then also helps save on costs, save on usage, which is better for everybody. In general, the principle here really is to try the cheapest option or the most reliable option first and kind of work your way up the ladder here. So the easiest one is just what the agent or what the bot already knows based on the conversation history. If it doesn't, if it's not in the immediate context, maybe there's a plugin, an MCP server, some kind of API that it can go and pull your banking information from Plaid, for example. Maybe that doesn't work and it needs to go do some kind of web search to see what was the score of the Cubs game last night. Maybe if it doesn't have that, it actually needs to go to the computer and open up the browser and do some searches on there. And finally, maybe it needs to go and actually use the entire desktop, so run scripts or run commands or build things on that Linux computer. And only if all of those fail. Then go bug the user and ask them to go give input or approve something. And this really helps it feel like what it would be like to work with a colleague. It's like they're not going to bug you for all these different things. Ideally, they're going to try a lot of these options first. On that computer, so the Linux machine that the agent is able to use, there's kind of three different ways that it can retrieve information from it. Of course, it can just take a screenshot of the screen, but there's more efficient ways of doing this. It could also look at the HTML of the page, but you can also look at the accessibility tree, which is a nice way of cutting down a lot of the token usage. And basically to help you find the buttons or links or other elements that you want the browser to click on. Of course, if none of that works, you can just click on pixels. So some websites, for example, have modals or dialogues that pop up that you need to click. And so your model, your agent needs to have that functionality as well. Or, again, kind of worst case on that ladder is you go back to the user and like, oh, there's like a two-factor auth code or some kind of captcha or something like that. So the idea is that kind of putting the pieces together, you have this main agent. And it's kind of like your orchestrator. And the main agent, you want to keep the conversation as sparse as possible because it now has the ability to go call on all of these different helpers. And the helpers are just sub-agents. And so this is helpful because if you hand it off to a helper to go run a bunch of shell commands or do a lot of expensive tool calls, all of that work that ultimately is ending up in some answer to a question or a task, none of that is bloating the conversation in the context of the main agent. It's only coming back with the result. And this is how you get to a product that feels like it has infinite context. Obviously, infinite context is not a real thing. Every model has a context limit. But there are these tricks and workarounds such that, especially when you train models to get better at this, that it doesn't feel like you're running up against the limits of the context window. And you don't feel a degradation of the model's quality as you get further along that as well. So we have these different helpers, each with different skills. Each one of these is its own durable workflow. So going back to the cues versus workflows thing, that means if it fails, the video helper crashes, something uses up too much memory or something, that can restart and keep going without losing progress along the way. And then the main agent, it is kind of like a co-worker where it's managing a to-do list. You have a few things you can do. You can go check on it. You can send it a message. You can stop the helpers, for example. And so a lot of this is modeled after the ideal way you would scale a team of engineers working on a very complicated problem. So just a few little interesting tidbits from building this out on the team. I think we'll talk a little bit more about prompt caching here, but ideally you don't add or remove new tools during turns. And just like I mentioned with the slide with all of the boxes, if you have extremely long tool descriptions or schemas, that's going to take up a lot of space in the context window, which is bad for pricing. It's bad for usage. Ideally, you want to minimize that. So there's plenty of optimizations you can make here on the engineering side to just trim that down. Another interesting one is like you might hear people talk about how, oh, like we can have a harness that just has one tool. And that one tool is like running shell commands. And this is true, and you can model a lot of things this way. But if you see the model doing, you know, 90% of its time doing shell commands for this one thing, it actually can be more efficient to make a dedicated tool for some of that stuff. And it's a bit more legible for people actually reviewing how the product is working. And the last one's kind of funny too. Obviously, if you're writing errors for humans, it's helpful to make it very descriptive. Like, okay, this thing failed. Like, click on this link or here's what you need to do next. Turns out that's also very helpful for agents. So there is some DX in designing good error messages for agents too. And when you're trusting your bots to go and do work over a long period of time, it is very important that you trust them to be secure with your information, to be secure with how it operates. So even working on its own separate machine, not polluting anything on your machine, still you would like it if, you know, a model reviews every shell command before it goes. So auto review. It would be great if, you know, when these untrusted inputs, like an email in your inbox, could be a phishing email or some web hook, you don't want to send that to the model and act like it was a user instruction. And there's plenty of work to do here in the industry on just making sure that that is properly protected from prompt injections. For these kind of non-reversible things like sending emails, right, you want to really ask the user first. And then also you can build in some workflows into the product to keep passwords and other things outside of the model conversations. Okay. Context engineering is also known as harness engineering. Like I feel like it's kind of the same thing. They've evolved over time. But basically what are some tips and tricks we can do to minimize the amount of context that's being used in these harnesses, which is good for efficiency, for reducing costs and other reasons. I talked about prompt caching. This is a good example of why it's really important. So if you think about when you're working with a coding agent or any agent, most of the tokens used are actually ideally cached tokens because you're sending in a conversation and then you're doing a change, you're adding one more message, and then you're basically resending the entire conversation over again. So if you look at the pricing for models, there's huge discounts, of course, on if a token is cached. And you want to keep them in the cached window as long as possible. And so a way to do this is you try to keep the tool definitions, the system prompts, all this information as static as possible between different calls so that you don't break the cache and then have to pay for the uncached tokens every single time. So if you have that fixed part at the top, then when you get down to the bottom and you only have the newest message that comes in, that's the only delta that you're paying the uncached tokens for. And there's a whole art and science to this as well. Basically because that main agent, in the most ideal sense, this is the one you're having this very, very, very long conversation with that's compacting or compressing, so summarizing the context, many, many times over without you even noticing sometimes, which we'll show an example of. So you really want to keep that context small. Some ways of doing that is anytime there's a very long output, rather than stuffing that in the context, you can just put it in a file. And the agents are very good at reading files, so this actually works pretty well, which is just like reading a skill or reading a memory, for example. If you give the model a screenshot or some other very expensive work, you just delegate that out to a helper. Again, so it goes to the subagent, and it doesn't affect the main agent's context. And then also, in an ideal world, you want to kind of be always gardening and trimming and removing unnecessary stuff from this conversation, from this context window, as you're going, both for cost but for also recall and just making sure the model's performing well. So if there's a cache miss, it's kind of like a bug in the system, really. And if you go all the way back to January of this year, when OpenClaw was really getting popular and people were using it inside of subscription plans for model providers, this was a very new usage pattern that model providers hadn't really seen. And the harness hadn't really yet been optimized for this type of workflow. So there was a lot of cache misses. And when you're doing something like this, where agents are running all the time, that's obviously problematic. So lots of fixes had to go in to make that robust to keeping the prompt cached as much as possible. So like a fun trick here is just trying to keep everything in the prompt in order such that even if you deploy a new change where you want to test out some new change to the system prompt or add a new tool, you can almost hash each section and always keep a fixed order. Like let's say you're doing an A-B test and you want to put a new piece of the prompt in there. You really don't want that to screw up the prompt order for everybody else. Otherwise, you just busted the cache. And then that's problematic. Another fun one is when you open the chat and you start typing, the server can actually go and prepare the prompt early to basically warm the cache. Almost like if you're on a website and you go to hover on a link, it can go and prefetch the next page. So there's like tons and tons of little engineering optimizations that compound how far these models can go in terms of token usage and how smart they can be when you use them for very long periods of time. And the key thing is that when you're working over a very long period of time, you essentially have to get very good at compaction or summarization because let's say the model has a 200,000 token context window. You're going and going and going. Eventually, it's going to hit a point where it needs to summarize. And all compression is lossy. So you have to figure out the best algorithm to do the compression and not lose important details. And there's, I'm sure, entire PhDs just for this problem. Like it's very, very tough to do, right? But just to show an example, like let's say you're going back and forth with your bot. You have over 100,000 tokens and then you go and do something else. Well, there is this time period where the model providers have like a cache window when the cache is still warm. Maybe it's 10 minutes, maybe it's 60 minutes. One trick that we do, which I think is really helpful, is while you're still within the warm cache period, you should probably do the compaction right now because you have this long conversation. It's going to be much cheaper. So just go ahead, do the compaction. And now when the user comes back in 30 minutes or whatever, they're starting from this summary. And the summary now is going to be much cheaper for them to continue adding messages on. So lots of work to do there to make the algorithm very high quality for how you do the summarization. When you talk about compaction and what information you choose to include in the agent's memory, I kind of think about it in a few different layers. The first one is like facts about the user that are very important to be included every single time. Going back to earlier when I said, oh, like the user always wants to have lowercase text. That probably needs to be in every single message. Otherwise, it would be really weird if one message now has uppercase letters. If you're going like full Sam Altman style. Then you probably also have some prompts that you want, or some facts that you want to include in there. And there's many different ways you can make this algorithm to determine what are the most important facts to keep. So ideally, there's this kind of garbage collection of this fact. And like, if you think about it, this is kind of how our brains work. It's like this fact right now is important to keep. It's relevant for this conversation today. You're probably not thinking about, you know, a soccer match right now. And your brain is very good at keeping those ones in context right now and kind of remembering them for later. We tried to model some of that here where the harness has, of course, these core facts. It also has these dated logs of kind of your past conversation history, essentially. And then also these kind of scratch pad notes. So it's like little things that you've been working on right now that are designed to be ephemeral and they will go away, but they might be relevant just for the next 30 minutes or an hour. And everything else can be found through files. This is the magic of files of the models being good at running commands. It's like they can always just go look stuff up. And they're actually very good at doing that. So where is this going? There is this flywheel of training the model to get better at the product. And this is a high-level refresher on kind of the stages of training a large language model. First, you have pre-training where the model learns a general understanding of the world from large amounts of Internet text or other private data. Then you have supervised fine-tuning where you're teaching the model how to behave in a certain way, maybe as a chat assistant or as an agent. And then finally you have reinforcement learning where it's kind of like teaching the model how to play games and get better at those games. And in the context of these always-on agents, it's very helpful, for example, to train the model to see examples of the harness and to know how to work inside of the harness in SFT so it can understand the tools that you have available. It's helpful to train the model to be better at instruction following during reinforcement learning, how to understand the right skill to call when there's hundreds of skills, for example, how to click on the right spots when you're given in a browser and it needs to kind of click around. And not only the training itself but also how you serve the model, the inference that you do. The main agent you're talking with, you know, ideally you want it to have very low latency. You want it to come back to you right away, give you really fast replies, and you can tune the harness and the inference to do that. But then when you go hand it off to a helper and you're asking it to go do some work for a very, very long period of time, the difference between 10 minutes and 12 minutes is kind of negligible at that point. So that allows you to kind of control how you optimize things. The way that this kind of flywheel works is that let's say your agent gets something wrong. Ideally then that gets turned into some kind of evaluation. So the model, you know, accidentally called this tool and it wasn't supposed to. Then on the back end you can go and fix the harness, you can fix the bug, you can fix the prompt, maybe it's an inference issue. You can check and make sure it's actually fixed in the evals and then shift the change. And, you know, the teams and the products, the teams working on these products, they're kind of doing this every single day. They're finding bugs, they're fixing it, they're measuring it with evals. That's kind of this inner loop that you're always getting better at. But then there's this outer loop, which is like every few months or every month or however long you're training new models. And ideally the new models are learning from all of these bugs and these failures and they're kind of climbing on the evals to get better at the things that you care about. And you can drop the new versions into the product and make sure that they're improving at all these different things. And the fun thing about this is then when the new models come out, they have new capability jumps. It allows you to use the product in new ways. So there hasn't really been a lot of training data, for example, on using bots in a group chat. This is kind of an emergent thing that's being figured out and it's important to get it right. Obviously, if you've seen things like Moldbook or the Huggy Face incident, like there are ways that that goes poorly. So it's important to be able to train the models how to behave well in a multi-agent system where different bots are talking to each other, for example. And so ideally you're always kind of running these inner loops and outer loops as a product team building these type of harnesses at a company working on AI together. One of the principles that we had at Cursor and now at SpaceX is to delete the product. And what we mean by this is you kind of have to internalize and assume that the models today are the worst they'll ever be, which means that in six months you might need to completely rebuild the UI. Like most of the stuff that I've talked about today, it's a pretty big update from if I would have given this talk six months ago or definitely a year ago because we've learned a lot of new practical ways of building harnesses and doing context engineering. So a good strategy here is you really want to try to build for the next generation of the model. Like how do you build as little as possible and get by while making just a really, really simple interface to work with these models and allow them to think and act for you. So some things that I think will happen in the next six to 12 months, we'll see. I think these are decently safe bets. But right now let's say you have your agents or your bots working for maybe a few hours, maybe a day, depending on how tough it is. I think it's very possible that pretty soon your agents will be working for weeks or months. And it does bring up some kind of interesting questions in terms of how we train and evaluate those models. I think the models are going to get better and better about how they recall on past information in conversations. Plenty of different approaches in research here for the type of algorithms used or the representation of the data under the hood. Maybe it's a graph, maybe it's files, maybe something else. I think ideally if you have this digital colleague, you give it literally all the tools that you have if you were onboarding a real human. And so I think organizations are still warming up to that idea, of course. So there's more to do there. I think the interfaces will maybe get even easier. I think some people will prefer to just talk to their kind of bots or agents in a speech-to-speech way. Maybe they'll have their Johnny Ive device that is hopefully really cool and they can talk to that all day. I think the models and the products will get really good at learning skills on the job and then encoding that into files and instructions, skills, and taking that raw intelligence and actually making it useful for whatever task you're asking it to do. And people and companies are going to get much better, I think, about writing down how all of these kind of bespoke processes work so that they're legible for agents to use. So some interesting problems, I think, that could just spark ideas for you all to research or to look into. The first one is going back to this idea of agents that run for a month. What do you do when you need to evaluate an agent that runs for a month, but the models ship every month? You know, it's like you can't fully evaluate that the model is sufficiently behaving as expected, so you either have to figure out how to do a better eval or, you know, not ship models as fast. And I think that's going to be a problem that the industry has to figure out in the next six months. Memory, obviously, we talked about the different algorithms. I think there's so much to do on the security side for how to make a secure harness, how to make the infrastructure around these agents very secure, and so they can't be taken over by bad actors. I think we didn't really talk about it too much, but the heuristics around when the agent is silent or when it kind of bugs you, I don't think that we have it perfect yet. And I think trying to thread the needle between being proactive and suggesting, like, oh, hey, I saw that you missed class yesterday. Like, I had a recording there, and I took the notes, and, like, here's the thing. Like, maybe that's helpful, or maybe that's kind of annoying, you know, and, like, trying to figure out the right balance there. I also think that it's a pretty safe bet to assume that at this time next year, there will be significantly, significantly more tokens flowing in the world, which means that optimizing the inference, optimizing the models, optimizing the harnesses, trying to drive down the tokens to be more efficient will also, the token usage to be more efficient, I think will also be very important. So there's kind of these new building blocks to think about. I believe it was Alex from Open Router that I saw on X. He had a really good take on this. There was people saying, like, oh, every app today looks the same. You've got the sidebar, you know, you've got the agent, you've got the chat box. Like, everybody's building the same thing. And he was like, yeah, that's like in 2005. He said, everybody's building the same thing. They've got a server. They've got a database. They've got some, like, CRUD interface to, like, update and delete things. And the reality is, this is just kind of the new normal now where every new product is going to have to have some kind of agentic side to it, either integrating or it will become a, you know, a headless piece of data for another agent to use. And so we've talked about a lot of these products today, durable workflows, sandboxes, computers in the cloud, memory skills, connecting to other services, doing voice payments, identity, evals, observability. Each one of those boxes is, like, multiple billions of dollars of VC capital, probably trillions. There's 20 startups for each one of those. And there's so many different things to explore in all of those because they kind of are the new primitives for the next generation of companies, the next generation of products. And they all have to integrate and be part of harnesses. So there's definitely a lot to do there. A few things to take away, and then we'll have time for questions. Obviously, you all are engineers. You're thinking about how to write software. It's more important than ever to think about the broader system design and the architecture of the code that you're working on because that, the decisions you make there will really compound. So I'm still pro looking at code. You know, I still look at the code that I'm writing. Some people are not looking at the code. I still think it's helpful, especially to understand the architecture that you're shipping. It's crazy how much that's changed in just a couple years. Secondly, you know, it sounds like you all were kind of messing around with building own versions or understanding of how the harness worked in last week. I encourage you to think about some of the things that I did today and try to apply that and think about how you might build a version for yourself. I'm pretty sure there's, like, open Grokbot on GitHub somewhere where somebody's, like, you know, slot forked R code and made a version. And you could probably set up, like, the GUI for that with, you know, a sandbox somewhere and, you know, a VM and, like, all sorts of different things. So that could be interesting if you want to learn a little bit more about how these pieces work. And then, finally, I would not shy away from just learning a little bit more about how LLMs work. You know, we gave a little bit of the TLDR here of how they're trained. But there's so much more you can go into here without necessarily going deep in ML or deep into the science part of it. But I think it's helpful to understand, just like when you're building a web app, it's helpful to know how databases work because, increasingly, there are so many decisions you make at the product and the harness level that are influenced by the models themselves. And having an intuition of how that works I think will make you very well positioned for whatever role you're operating in. And that's all I have today. Thank you.