AI Agents Are Just Distributed Systems Now — Salman Munaf, TikTok

AI Engineer · 19 min · 133 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:01[music]
  2. 00:12Hello everyone.
  3. 00:13Good good afternoon.
  4. 00:14Uh today uh I will be talking about AI agents are also distributed systems.
  5. 00:20So as uh the models have started to become more complex.
  6. 00:25Initially the uh LLM models were just text in text out without performing any actions and uh the effect that they can produce was just a wrong model output.
  7. 00:39However, with now the capability of agent the agent the rise in agent capabilities where the systems can now talk to external systems uh it has turned into a distributed systems and it is important
  8. 00:56to incorporate distributed systems thinking and concepts when building AI agents.
  9. 01:02So I will be going over uh that uh in this talk.
  10. 01:07So you guys might have uh heard about incidents being caused by a AI agents.
  11. 01:14Uh for instance, the replicate AI agent deleting a production incident production database or Air Canada chatbot basically making an uh an incorrect refund.
  12. 01:28And both of these uh incidents or a lot of these incidents could have been prevented uh by good systems thinking when building these uh AI agents.
  13. 01:41So for instance for the replet a uh uh uh incident we could have good uh uh we could have robust backups.
  14. 01:53We could have scoped authority.
  15. 01:54we should we shouldn't ideally have uh allow AI agents to delete production databases.
  16. 02:00Uh moreover for Air Canada chatbot it would have been uh a good idea to have uh authoritative source of truth retrieval so that it's not making uh uh decisions based on stale or incorrect policies.
  17. 02:19So let's uh go over the transition from chatbot to production system.
  18. 02:23Uh so uh initially when we were in the uh in the uh age where LLMs were just chat bots uh we had prompt in and we were outputting text
  19. 02:38there were no side effects the agent was not interacting with any other system.
  20. 02:44However, uh due to agentic uh in the agentic era in the agentic revolution, now those agents uh by ingesting prompt can uh run an agent loop, call external services, call tools and also perform state changes.
  21. 03:01The architectural boundary now has moved uh way beyond an LLM model.
  22. 03:08And the difference is that it can now cause side effects in the outside world.
  23. 03:13So when basic when building AI agents, it is important to recognize the external systems that it is talking to, [clears throat] the states that uh it is interacting with
  24. 03:25and what credentials does it have and the actions that it can perform.
  25. 03:32uh I ideally like to think about it as uh uh AI agents as basically having a probabilistic coordinator.
  26. 03:42In distributed systems as well, we used to have services which were coordinating uh multi-step workflows.
  27. 03:48However, they were deterministic in nature.
  28. 03:51But in the case of AI agent, the AI acts as a probabilistic coordinator.
  29. 03:56The amount of action, the kind of actions that it can take can vary quite a lot.
  30. 04:01It is not just a decision tree that uh we typically in traditional systems would have mapped out and those uh actions can have severe consequences uh ba uh if they are not confined
  31. 04:18by our determinist by having deterministic controls in place.
  32. 04:23So it is important to ensure uh that we have deterministic controls in place to ensure that agent or the AI agent is not performing any uh any actions that might be
  33. 04:39uh uh problematic.
  34. 04:42So uh let's uh discuss the how a typical agent loop might look like.
  35. 04:51So at first it might uh do some planning.
  36. 04:56Then based on that plan it will it will perform an action and it will then observe the results of those actions and uh it might persist that into some d some data store and then decide what to do next.
  37. 05:12Each step in this loop is basically crossing a a boundary.
  38. 05:16During planning, it can interact with data sources to retrieve some data.
  39. 05:22Uh during action, it can call external APIs, tools, uh databases and perform any actions.
  40. 05:30During observation phase, it can perform it can get partial results and basically plan or make subsequent actions based on those partial results.
  41. 05:42It can persist incorrect data or uh and uh when deciding it might also decide to uh perform an incorrect action or uh worse it can also do a retry
  42. 05:59storm.
  43. 06:01So it is very important when building an agent loop to persist every step of the process.
  44. 06:07Whatever actions the agent is doing, whatever context it is retrieving, it is important to uh persist that so that if anything fails, the agent is able to recognize where it failed and it can perform
  45. 06:20uh a reversible action.
  46. 06:23Uh it can perform undo operations.
  47. 06:25Similarly, there should be explicit transactions uh identified for each step.
  48. 06:31So for instance, if an agent is making a call, if it fails, what it should do?
  49. 06:36What should be the transaction to compensate for a uh for a irreversible or unsafe operation?
  50. 06:43For instance, if an agent makes sends an email to a a wrong email to a customer, what should it do to compensate for that?
  51. 06:53So, uh tool calls are just wrappers around uh external external APIs, databases, cues, uh and so on.
  52. 07:06And uh with uh when calling the when making these remote calls, there are some failures that you incorporate uh such as network delays, timeouts, uh you can make duplicate requests
  53. 07:21or worse the server side request uh might succeed.
  54. 07:26However, the client however the client might be reported an error.
  55. 07:30We have we have seen uh instances where uh a data by base might have written the data.
  56. 07:38However, due to some other errors, the server might have reported uh uh to us the error and uh with humans in the loop we can make we can basically
  57. 07:52perform correct corrective actions based on uh by seeing uh the database and actual source of truth.
  58. 07:58But in agent's case, we need to ensure that we have uh we have proper guardrails in place.
  59. 08:04So for instance, an agent calls refund customer uh tool call which basically performs a refund to the customer.
  60. 08:12The request times out uh that did the refund happen or not?
  61. 08:18What will the agent uh infer from that?
  62. 08:22Would it retry uh refunding to the customer?
  63. 08:25you basically the the timeout does not actually mean that there a failure had occurred.
  64. 08:30It means unknown.
  65. 08:32And it is important to have uh when designing these tools, it is important to have request ids, item potency keys so that when making duplicate requests, they are not causing duplicate side effects.
  66. 08:47uh and the system can always do a status lookup like what the previous request was and what was the status of that so that it is not making side effect
  67. 08:59it is not making side effects with duplicate a with duplicate requests.
  68. 09:05So [clears throat] AI agents when they whenever they uh uh whenever they uh they face failures they retry the their first uh action is to perform retries.
  69. 09:20So it is really important to have item potency baked in.
  70. 09:25uh it if a same request is coming in to an external API or the tool it should recognize that this is a duplicate request and ensure that no side effects are being take are taking place.
  71. 09:38Moreover, uh we should also prevent uh AI agents to perform retry storms to external APIs because this can cause cascading failures.
  72. 09:48uh we we should have max turns budget spend and max parallel calls to prevent uh to uh to ensure that the fan out is not that large.
  73. 10:00Moreover, we should have exponential back back off in place to ensure that uh the downstream dependencies are not being uh burdened and we should also have compensation uh operations in place for
  74. 10:17uh operations that uh that that can have side effects.
  75. 10:25Uh so uh a lot of uh teams when building AI agents think of AI agent context as just a AI cont the context that uh the AI agent has as
  76. 10:43uh as just a context.
  77. 10:45However, when that context can influence an action, it's a state and that state can become stale that can conflict with the authoritative data or corrupt future actions that the agent might perform.
  78. 10:59I like to classify it into two different types of uh memory that the agent has.
  79. 11:05First is the short-term memory which is the jet thread uh that the agent has uh the which is tied to a single execution thread and the second is the long-term memory.
  80. 11:16It can be project files uh system prompts uh databases that it interacts with the cache layer and so on.
  81. 11:25It is important to uh to to decide what will be the source of truth when these uh different data sources have conflicting information and we should ideally treat memory as a cache
  82. 11:42which uh can be invalidated which can have provenence attached to it.
  83. 11:48So for instance whenever a data store or a database is updated or the source of truth is updated we in we invalidate the context or the memory that the agent has to ensure that it is not making actions based on the
  84. 12:03uh incorrect or stale data.
  85. 12:08So usually these agents perform multi-step actions and uh the agent can succeed on uh on uh on the first couple of steps and then it fail.
  86. 12:22Uh it is important to reverse the entire transaction that was performed and these can uh then can cross system boundaries.
  87. 12:31So for instance, an agent can update an internal ticket uh send an email to a customer and fail to update the CRM.
  88. 12:41We need to figure out what is the uh correct compensation operation when it when it hits that failure.
  89. 12:51So for instance uh as I mentioned earlier that uh it improperly uh it improperly sends an incorrect email to the customer.
  90. 13:02It is important that the compensation operation is defined for the AI agent to ensure that it is sending an uh uh an apology email to the customer or any or or any email or an email that is correcting that mistake.
  91. 13:19So uh a the AI agent basically runs in a loop and uh whenever uh like it can it can do multiple calls.
  92. 13:31It can it can have a retry uh retry loop that it can run based uh whenever it fails.
  93. 13:39So it is important to have uh circuit breakers whenever it is making making external calls uh to ensure that the uh that the that it is not uh burdening the downstream
  94. 13:53system.
  95. 13:54Uh for instance if a downstream is unhealthy there should be system break uh circuit breakers in place that prevents AI agents to call call that dependency.
  96. 14:03Moreover, it also prevents cascading failures when for instance the downstream dependency is uh unhealthy or uh is saturated.
  97. 14:14It is also important to assign rate limits and budgets.
  98. 14:17Uh an agent can uh go over uh can run your cost uh if it's not assigned proper budgets and rate limits.
  99. 14:27it will uh keep retrying and try try to uh try to solve the problem that if it if it's facing.
  100. 14:35So it is important that it is uh that we have uh set up max turns, max parallelism, max spend uh to ensure that the model is not uh uh not
  101. 14:46uh crossing the uh the budget boundary that we have set.
  102. 14:52Moreover, uh ideally uh usually whenever we are building AI agents, uh we usually try to give all the permissions that it can have to ensure that it has all that it can perform perform the task that we have.
  103. 15:09That's the that's the uh first uh uh thing that we have that that's the first step that we take usually that to give the AI agents all the uh cred all the uh privileges
  104. 15:24to perform any actions like for instance if it's interacting with the database we just give it all uh the readr access to the entire table.
  105. 15:32However, uh it is important to give scoped credentials to it.
  106. 15:38There should be separate read and write permissions and there should be allow list for the tools that it can call.
  107. 15:45A harmless model can become dangerous when it can perform unsafe operations.
  108. 15:51Moreover, uh a human approval shouldn't be tied uh to a blanket approval.
  109. 15:57It should be tied to uh action, timestamp, actor and expiration.
  110. 16:04So for instance, if a user has given uh an approval to approve a $30 refund, it shouldn't turn into a subsequent approval for $300 refund.
  111. 16:17It is important that whenever an approval is given, it should be tied to the particular parameters that it was uh asked for.
  112. 16:31So, uh observability is an important requirement when building AI agents because uh and logs are not enough.
  113. 16:42Teams need to reconstruct when an agent failed, what happened, what information was was it reacting to and why it failed.
  114. 16:51And logs alone are not enough to uh for an agent to uh for teams to determine that.
  115. 16:59It is important to trace the model that was called, the prompt that was uh that was uh given to it and uh also the tool calls that were made
  116. 17:09uh the request uh that was made, the response from the tool, the errors that it got, the retrieved context, what the agent was uh was the the retrieved information that the agent was reacting to, the rights that it made, and the approvals that it got and so on.
  117. 17:31So uh I would like to uh end with uh the idea that yes model capability matters.
  118. 17:40Having good models uh improves the uh likelihood of it making uh correct operations.
  119. 17:48Smarter models reduce mistakes.
  120. 17:50It uh it uh improves the capability that the model has.
  121. 17:55However, it cannot eliminate network failures, stale data or adversarial input.
  122. 18:02It is important when building this architecture, we also reason about can we bound, observe and recover from actions performed by the AI agent.
  123. 18:14It is important to have tool contracts in place to ensure that uh it is only allowed to make uh operations that it is uh given that it is provided the contract and the contracts are clearly establishing the request and response
  124. 18:29uh response uh response types uh the schema and all these tools have item potency baked into it.
  125. 18:38so that uh when repeated requests are sent in uh it is not causing unsafe operations to be retried.
  126. 18:46Moreover, there should be source of truth decisions made uh when there are conflict conflicting uh memory states.
  127. 18:53It is important uh for the agent to realize this is the source of data that it should rely on and we should have re retry policies uh like rate limits set in to ensure that the agent is not uh retrying
  128. 19:08uh ext uh aggressively.
  129. 19:11Moreover, uh permissions should be set up.
  130. 19:15There should be traces and recovery paths.
  131. 19:18So when building AI agents, we should also ask what the system lets it do when it is wrong.
  132. 19:28Thank you.
  133. 19:46[music]