﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.org</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Putting Claude up against our test suite</title><description>&lt;p&gt;I&amp;rsquo;m convinced that in hell, there is a special place dedicated to making engineers fix flaky tests. &lt;/p&gt;&lt;p&gt;Not broken tests. Not tests covering a real bug. Flaky tests. Tests that pass 999 times out of 1000 and fail on the 1,000th run for no reason you can explain with a clean conscience.&lt;/p&gt;&lt;p&gt;If you&amp;#39;ve ever shipped a reasonably complex distributed system, you know exactly what I&amp;#39;m talking about. RavenDB has, at last count, over 32,000 tests that are run continuously on our CI infrastructure. I just checked, and in the past month, we&amp;rsquo;ve had hundreds of full test runs.&lt;/p&gt;&lt;p&gt;That is actually a problem for our scenario, because with that many tests and that many runs, the law of large numbers starts to apply. Assuming we have tests that have 99.999%&amp;nbsp;reliability, that means that 1 out of every 100,000 test runs may fail. We run tens of millions of those tests in a month.&lt;/p&gt;&lt;p&gt;In a given week, something between ten and twenty of those tests will fail. Given the number of test runs, that is a good number in percentage terms. But each such failure means that we have to investigate it. &lt;/p&gt;&lt;p&gt;Those test failures are &lt;em&gt;expensive. &lt;/em&gt;Every ticket is a developer staring at logs, trying to figure out whether this is a genuine bug in the product, a bug in the test itself, or something broken in the environment. In almost all cases, the problem is with the test itself, but we have to investigate.&lt;/p&gt;&lt;p&gt;A test that consistently fails is easy to fix. A test that occasionally fails is the worst. &lt;/p&gt;&lt;p&gt;With a flaky test, you don&amp;#39;t just fix something and move on. You spend two days isolating it. Reproducing it. Building a mental model of a race condition that only manifests under specific timing, load, and cosmic alignment.&lt;/p&gt;&lt;p&gt;The tests that do this are almost always the integration tests. The ones that test complex distributed behavior across many parts of the system simultaneously. By definition, they are also the hardest to reason about.&lt;/p&gt;&lt;p&gt;The fact that, in most cases, those test failures add nothing to the &lt;em&gt;product&lt;/em&gt;&amp;nbsp;(i.e., they didn&amp;rsquo;t actually discover a real bug) is just crushed glass on top of the sewer smoothie. You spend a lot of time trying to find and fix the issue, and there is no real value except that the test now consistently passes. &lt;/p&gt;&lt;p&gt;We have a script that runs weekly, collects all test failures, and dumps them into our issue tracker. This is routine maintenance hygiene, to make sure we stay in good shape. &lt;/p&gt;&lt;p&gt;I was looking at the issue tracker when the script ran, and the entire screen lit up with new issues. &lt;/p&gt;&lt;p&gt;Just looking at that list of new annoyances was enough to ruin my mood. &lt;/p&gt;&lt;p&gt;And then, without much deliberate planning, I did something dumb and impulsive: I copy-pasted all of those fresh issues into Claude and told it to fix them. Then I went and did other things. I had very low expectations about this, but there was not much to lose.&lt;/p&gt;&lt;p&gt;A few hours later, I got a notification about a pull request. To be honest, I expected Claude to mark the flaky tests as skipped, or remove the assertions to make them pass.&lt;/p&gt;&lt;p&gt;I got an &lt;em&gt;actual&lt;/em&gt;&amp;nbsp;pull request, with real fixes, to my shock. Some of them were fixes applied to test logic. Some were actually fixes in the underlying code. &lt;/p&gt;&lt;p&gt;And then there was this one that stopped me cold. Claude had identified that in one of our test cases, we were waiting on the wrong resource. Not wrong in an obvious way &amp;mdash; wrong in the kind of way that works perfectly 99.9998% of the time and silently fails 0.0002% of the time. &lt;/p&gt;&lt;p&gt;The (test) code &lt;em&gt;looked&lt;/em&gt;&amp;nbsp;right. We were waiting for something to happen; we just happened to wait on the wrong thing, and usually the value we asserted on was already set by the time we were done waiting. &lt;/p&gt;&lt;p&gt;Claude found it. In one pass. For the price of a subscription I was already paying. For reference, that &lt;em&gt;single&lt;/em&gt;&amp;nbsp;&amp;ldquo;let me throw Claude at it&amp;rdquo; decision probably saved enough engineering time to cover the cost of Claude for the entire team for that month.&lt;/p&gt;&lt;p&gt;Let me be precise about what happened and what didn&amp;#39;t. Claude did not fix everything. Some of the &amp;quot;fixes&amp;quot; it produced were pretty bad, surface-level patches that didn&amp;#39;t address the real cause, or things that were legitimately out of scope. &lt;/p&gt;&lt;p&gt;You still need an engineer reviewing the output. And you still need judgment.&lt;/p&gt;&lt;p&gt;But it got things fixed, quickly, without needing two days to context-switch into the problem space. And the things it did fix well, it fixed really well.&lt;/p&gt;&lt;p&gt;The work it compressed would have realistically taken one developer a week or two to grind through &amp;mdash; and that&amp;#39;s assuming you could get a developer to focus on it for that long in the first place. Flaky test investigation is the kind of work that quietly kills team morale. &lt;/p&gt;&lt;p&gt;Engineers start dreading CI. They start treating red builds as background noise. That&amp;#39;s how quality degrades silently. Leaving aside new features or higher velocity, being able to offload the most annoying parts of the job to a machine to do is&amp;hellip; wow. &lt;/p&gt;&lt;p&gt;Based on this, we&amp;#39;re building this into our actual workflow as an integral part of how we handle test maintenance. Failures are collected, routed to Claude, and it takes a first pass at triage and repair. Then we create an issue in the bug tracker with either an &lt;em&gt;actual &lt;/em&gt;fix or a summary of Claude&amp;rsquo;s findings.&lt;/p&gt;&lt;p&gt;By the time a human reviews this, significant progress has already been made.&lt;/p&gt;&lt;p&gt;It doesn&amp;#39;t replace the engineer. But it means the engineer is doing the interesting part of the work: judgment, review, architectural reasoning. Skipping the part that requires staring at race condition logs until your vision blurs.&lt;/p&gt;&lt;p&gt;This isn&amp;rsquo;t the most exciting aspect of using a coding agent, I&amp;rsquo;m aware. But it may be one of the best aspects in terms of quality of life. &lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203973-a/putting-claude-up-against-our-test-suite?Key=51ff4d9c-0a4e-4dd4-bbb4-7b697713fc3c</link><guid>http://ayende.org/203973-a/putting-claude-up-against-our-test-suite?Key=51ff4d9c-0a4e-4dd4-bbb4-7b697713fc3c</guid><pubDate>Wed, 29 Apr 2026 12:00:00 GMT</pubDate></item><item><title>15+ years of working with coding agents</title><description>&lt;p&gt;No, the title is not a mistake, nor did I use my time travel pass to give you insights from the future. Bear with me for a moment while I explain my thinking.&lt;/p&gt;&lt;h3&gt;From individual contributor to oversight role&lt;/h3&gt;&lt;p&gt;I started writing RavenDB in a spare bedroom, which turned into an office. The project grew from a sparkle in my head that wouldn&amp;rsquo;t let me sleep into a major project in very short order. &lt;/p&gt;&lt;p&gt;Today, I want to talk about a pretty important stage that happened during that growth phase. Somewhere between having five and ten full-time developers working on RavenDB, I lost the ability to keep track of every single line of code that was going into the project.&lt;/p&gt;&lt;p&gt;I had been the primary developer for years at this point, I wrote the majority of the code, and I was the person making all the key decisions in the project. And then, gradually, I&amp;hellip; wasn&amp;#39;t that guy anymore. &lt;/p&gt;&lt;p&gt;There were too many moving parts, too many developers, too many decisions happening in parallel for me to have my hands on all of it. That was the whole &lt;em&gt;point&lt;/em&gt;&amp;nbsp;of growing the team, dividing the tasks among the team members, and getting good people to do things so I didn&amp;rsquo;t have to do it all myself.&lt;/p&gt;&lt;p&gt;What I didn&amp;#39;t expect was how much it would &lt;em&gt;bother &lt;/em&gt;me. Moving from being the primary developer to a supervisory role didn&amp;rsquo;t mean that I lost the ability to write code. In fact, in many cases, I could &amp;ldquo;see&amp;rdquo; what the solution for each issue should be.&lt;/p&gt;&lt;p&gt;I just didn&amp;rsquo;t have the &lt;em&gt;time&lt;/em&gt;&amp;nbsp;to do that, nor the capacity to sit with every single developer on every single issue and craft the right way to solve it. I&amp;#39;d hand a feature to a developer &lt;em&gt;know&lt;/em&gt;&lt;em&gt;ing&lt;/em&gt;&amp;nbsp;that the way they were going to handle it would not be&amp;nbsp;mine. &lt;/p&gt;&lt;p&gt;That doesn&amp;rsquo;t mean it would be wrong, but it wouldn&amp;rsquo;t be the same. It might need a review cycle or two to get to the right level for the product, or they wouldn&amp;rsquo;t consider how it fits into the grand scheme of things, etc. &lt;/p&gt;&lt;p&gt;And let&amp;rsquo;s not talk about the time estimates I got. I&amp;rsquo;m willing to assume that my personal timing estimates are highly subjective and influenced by my deep familiarity with the codebase. &lt;/p&gt;&lt;p&gt;But still. Multiple days for something that felt like it &lt;em&gt;should &lt;/em&gt;be a two-hour job was hard to sit with.&lt;/p&gt;&lt;p&gt;I carried around a background level of frustration for quite some time. It killed me that the pace of development wasn&amp;rsquo;t up to what I wanted it to be. &amp;ldquo;If I could just have the time to sit and write this&amp;rdquo;, I kept thinking, &amp;ldquo;we would be done by the end of the week.&amp;rdquo; &lt;/p&gt;&lt;p&gt;There &lt;em&gt;was&lt;/em&gt;&amp;nbsp;progress, to be clear, but nothing was moving fast enough. Everywhere I looked, we had stalled. &lt;/p&gt;&lt;p&gt;And then something happened. It didn&amp;rsquo;t happen all at once, but in the space of a month or two, features started to land. Each team had been heads-down on something for quite a while, and by some coincidence of timing, they all finished around the same time. &lt;/p&gt;&lt;p&gt;Suddenly, we moved from &amp;ldquo;we have nothing to ship&amp;rdquo; to &amp;ldquo;we &lt;em&gt;can&amp;rsquo;t &lt;/em&gt;have so many new features all at once&amp;rdquo;. I realized that I &lt;em&gt;would&lt;/em&gt;&amp;nbsp;be able to ship things faster, for sure. I could do two new features, maybe even three, in that same time frame. That would require head-down coding for the entire duration, of course.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Reading that last paragraph again, I have to admit that I may be letting some hubris color my perception &amp;#129335;&amp;#128527;. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I wouldn&amp;rsquo;t be able to deliver the sheer quantity of features that the team was able to deliver. &lt;/p&gt;&lt;p&gt;What had felt like months of stagnation turned out to be parallelism in action.&lt;/p&gt;&lt;p&gt;Yes, some of the code wasn&amp;#39;t the same code that I would write. And some of the architectural decisions weren&amp;#39;t the ones I&amp;#39;d have made. That didn&amp;rsquo;t make them &lt;em&gt;wrong&lt;/em&gt;, mind. And those developers were working on things &lt;em&gt;I &lt;/em&gt;was not working on. And the sum total of what got built was something I could never have done solo.&lt;/p&gt;&lt;h3&gt;Treating coding agents as junior developers? &lt;/h3&gt;&lt;p&gt;I think about that experience constantly now, because I&amp;#39;m living a version of it again, except the new team member is Claude. Working with AI coding agents today feels remarkably like working with a junior developer who is also a savant. &lt;/p&gt;&lt;p&gt;They&amp;#39;ve read everything. They know an enormous amount. They can produce working code quickly and confidently across a staggering range of domains. And yet they&amp;#39;re also genuinely ignorant in ways that will surprise you: missing context, misreading intent, optimizing for the wrong thing, occasionally producing something that is confidently and completely broken.&lt;/p&gt;&lt;p&gt;This is not a criticism. This is just what it&amp;#39;s like. And I&amp;#39;ve dealt with this before. There are clear parallels between mentoring junior engineers and looking at the output from an AI agent. &lt;/p&gt;&lt;p&gt;There is an assumption that you need to get perfect output from a coding agent. But you are not likely to get perfect output from a human developer. Even experienced developers benefit greatly from reviews, guidance, etc. Junior developers need &lt;em&gt;more &lt;/em&gt;of that, of course, but they can still bring value, even if their output goes through several iterations.&lt;/p&gt;&lt;p&gt;For coding agents to bring real value, you need to consider them in the same light.&lt;/p&gt;&lt;p&gt;The shift that happened with my developer team is the same shift that&amp;#39;s happening now with AI agents.&lt;/p&gt;&lt;p&gt;Instead of writing every line yourself, you start spending time on the bigger picture: here&amp;#39;s the overall direction, here&amp;#39;s the architectural constraint, here&amp;#39;s what done looks like. Then you review the outputs. &lt;/p&gt;&lt;p&gt;Talking to a coding agent is a little different from discussing a feature with a dev and reviewing their code days later, except that the agent delivers the output in the time it takes to get coffee.&lt;/p&gt;&lt;p&gt;The fact that this cycle is done in a short amount of time means that you still have all the knowledge in your head. You can catch drift before it becomes technical debt. &lt;/p&gt;&lt;p&gt;The &lt;em&gt;cost&lt;/em&gt;&amp;nbsp;of going in the wrong direction is greatly reduced, which means that you can be far more radical about how you approach these tasks.&lt;/p&gt;&lt;h3&gt;Unnatural impulses as a developer&lt;/h3&gt;&lt;p&gt;I wonder if a lot of developers are facing challenges in this area specifically because they don&amp;rsquo;t have the managerial experience needed for this new aspect of the work. &lt;/p&gt;&lt;p&gt;I have been writing code with Claude recently. And the short feedback cycle means that I&amp;rsquo;m loving it. I&amp;#39;m not abdicating the technical judgment, mind. I&amp;#39;m applying it differently. &lt;/p&gt;&lt;p&gt;I&amp;#39;m writing the high-level design, not the implementation. I&amp;#39;m doing the review, not the first draft. And I&amp;#39;m being honest with myself that the output, while it isn&amp;rsquo;t always what &lt;em&gt;I &lt;/em&gt;would write, is covering ground I simply would not have covered otherwise.&lt;/p&gt;&lt;p&gt;I have been doing this for a long time and it feels quite natural. I also remember that this was a &lt;em&gt;difficult&lt;/em&gt;&amp;nbsp;transition for me at the time. &lt;/p&gt;&lt;p&gt;For those who want to better understand how they can get the most value from coding agents, you are probably better off looking into project management theory rather than optimizing your &lt;code&gt;agents.md&lt;/code&gt;&amp;nbsp;file.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203972-a/15-years-of-working-with-coding-agents?Key=0c842282-4ab8-41dd-978d-f26f0e80df59</link><guid>http://ayende.org/203972-a/15-years-of-working-with-coding-agents?Key=0c842282-4ab8-41dd-978d-f26f0e80df59</guid><pubDate>Mon, 27 Apr 2026 12:00:00 GMT</pubDate></item><item><title>Expertise in the age of AI, or: Matt's Claude'll handle this</title><description>&lt;p&gt;One of our team leads has been working on a major feature using Claude Code. He&amp;#39;s been at it for a few days and is nearly done. To put that in context: this feature would normally represent about a month of a senior developer&amp;#39;s time.&lt;/p&gt;&lt;p&gt;He did the backend work himself &amp;mdash; working with Claude to build it out, applying his knowledge of how the system should behave, reviewing, adjusting, and iterating. He handled only the backend, and when I asked him about the frontend, he said: &lt;em&gt;&amp;quot;I&amp;#39;m going to let Matt&amp;rsquo;s Claude handle that.&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Context: Matt is the frontend team lead. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Note the interesting phrasing. He didn&amp;#39;t say &amp;quot;I&amp;#39;ll do the UI later&amp;quot; or &amp;quot;Claude&amp;rsquo;ll handle the UI.&amp;quot; He deferred to the frontend lead who has the domain expertise to drive that part.&lt;/p&gt;&lt;p&gt;That&amp;#39;s not a throwaway comment. That&amp;#39;s an &lt;em&gt;important&lt;/em&gt;&amp;nbsp;statement about how work should be divided in the age of AI agents.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s the thing: I&amp;#39;ve told Claude to build a UI for a feature, pointed it at the codebase, and it figured out how the frontend is structured, what patterns we use, and generated something I could work with. It wasn&amp;rsquo;t a sketch or a wireframe diagram, it was actually &lt;em&gt;usable&lt;/em&gt;. &lt;/p&gt;&lt;p&gt;I got a functional UI from Claude in less time than it would take to write up the issue describing what I want.&lt;/p&gt;&lt;p&gt;That UI was enough for me to explore the feature, do a small demo, etc. I&amp;rsquo;m not a frontend guy, and I didn&amp;rsquo;t even look at the code, but I assume that the output probably matched the rest of our frontend code. &lt;/p&gt;&lt;p&gt;We won&amp;rsquo;t be using the UI Claude generated for me, though. The gap in polish between what I got and what a real frontend developer produces is enormous. I got something I could play with, but it was very evident that it wasn&amp;rsquo;t something that had received real attention.&lt;/p&gt;&lt;p&gt;For the time being, it was more than sufficient. The problem is that&amp;nbsp;even leaning heavily on AI, the investment of time for me to do it &lt;em&gt;right&lt;/em&gt;&amp;nbsp;would be significant. I&amp;#39;d need to understand our frontend architecture, our conventions, our component library, how state flows, and what our designers expect. All of that would take real time, even with an AI doing most of the code generation.&lt;/p&gt;&lt;p&gt;That is leaving aside the things that I &lt;em&gt;don&amp;rsquo;t&lt;/em&gt;&amp;nbsp;know about frontend that I wouldn&amp;rsquo;t even realize I need to handle. I wouldn&amp;rsquo;t even know what to ask the AI about, even if it could do the right thing if I sent it the right prompt.&lt;/p&gt;&lt;p&gt;Contrast that with the frontend team. They &lt;em&gt;know&lt;/em&gt;&amp;nbsp;the architecture of the frontend, of course, and they know how things should slot together and what concerns they should address. They know when Claude&amp;#39;s suggestion is on the right track and when it&amp;#39;s going to create a mess three layers down. Effectively, they know the magic incantation that the agent needs in order to do the right thing. &lt;/p&gt;&lt;p&gt;What does this &lt;em&gt;say&lt;/em&gt;&amp;nbsp;about AI usage in general? Given two people with the same access to a smart coding agent like Claude or Codex, both performing the same task, their domain knowledge will lead to &lt;em&gt;very&lt;/em&gt;&amp;nbsp;different results. In other words, it means that Claude and its equivalents are &lt;em&gt;tools&lt;/em&gt;. And the wielder of the tool has a huge impact on the end result.&lt;/p&gt;&lt;p&gt;The role of expertise hasn&amp;#39;t diminished. It&amp;#39;s shifted. The expert is no longer the person who can produce the artifact. They&amp;#39;re the person who can &lt;em&gt;direct the production&lt;/em&gt;&amp;nbsp;of the artifact correctly and efficiently. That&amp;#39;s a different skill profile, but it&amp;#39;s no less valuable and the leverage is higher.&lt;/p&gt;&lt;p&gt;We&amp;#39;re still figuring out what this means structurally. But the instinct to say &amp;quot;that&amp;#39;s not my domain, let the person who knows it handle the AI that does it&amp;quot; is correct. Domain knowledge determines the quality of the output, even when the AI is doing all the typing.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203971-a/expertise-in-the-age-of-ai-or-matts-claudell-handle-this?Key=5cdca447-6773-4a90-8564-4765289ec644</link><guid>http://ayende.org/203971-a/expertise-in-the-age-of-ai-or-matts-claudell-handle-this?Key=5cdca447-6773-4a90-8564-4765289ec644</guid><pubDate>Thu, 23 Apr 2026 12:00:00 GMT</pubDate></item><item><title>Using AI agents in long-lived software projects</title><description>&lt;p&gt;You read the story a hundred times: &amp;ldquo;I told Codex (or Claude, or Antigravity, etc.) to build me a full app to run my business, and 30 minutes later, it&amp;rsquo;s done&amp;rdquo;. These types of stories usually celebrate the new ecosystem and the ability to build complex systems without having to dive into the details.&lt;/p&gt;&lt;p&gt;The benchmarks celebrate &amp;quot;one-shotting&amp;quot; entire applications, as if that&amp;#39;s the relevant metric. I think this is the wrong framing entirely. Mostly because I care very little about disposable software, stuff that you stop using after a few days or a week. I work on projects whose lifetime is measured in decades. &lt;/p&gt;&lt;p&gt;AI agent-driven development isn&amp;#39;t about the ability to use a one-shot prompt to generate a full-blown app that matches &lt;em&gt;exactly&lt;/em&gt;&amp;nbsp;what the user wants. That is a nice trick, but nothing more, because after you generate the application, you need to maintain it, add features (and ensure stability over time), fix bugs, and adjust what you have.&lt;/p&gt;&lt;p&gt;The process of using AI agents to build long-lived applications is distinctly different from what I see people bandying about. I want to dedicate this post to discussing some aspects of using AI agents to accelerate development in long-lived software projects. &lt;/p&gt;&lt;h2&gt;Code quality only matters in the long run&lt;/h2&gt;&lt;p&gt;The key difference between one-off work and long-lived systems is that we don&amp;rsquo;t care about code quality &lt;em&gt;at all&lt;/em&gt;&amp;nbsp;for the one-off stuff. It&amp;#39;s a throwaway artifact. Run it, get your answer, move on. I am usually not even going to &lt;em&gt;look&lt;/em&gt;&amp;nbsp;at the code that was generated; I certainly don&amp;rsquo;t care how it is structured.&lt;/p&gt;&lt;p&gt;If I need to make any changes, or have to come back to it in six months, it is usually easier to just regenerate the whole thing from scratch rather than trying to maintain or evolve it.&lt;/p&gt;&lt;p&gt;When you&amp;#39;re talking about an application that will live for a decade or more - or worse, an &lt;em&gt;existing&lt;/em&gt;&amp;nbsp;application with decades of accumulated effort baked into it - what happens then? The calculus changes completely. How do you even begin to bring AI into that kind of system?&lt;/p&gt;&lt;p&gt;It turns out that proper software architecture becomes &lt;em&gt;more&lt;/em&gt;&amp;nbsp;relevant, not less.&lt;/p&gt;&lt;h2&gt;Software architecture as context management for AI&lt;/h2&gt;&lt;p&gt;Think about what good software architecture actually gives you: components, layers, clear boundaries, and well-defined responsibilities. The traditional justification is that this lets you make small, careful, targeted changes. You know where to go, and you can change one thing. You slowly evolve things over time. Your changes don&amp;#39;t break ten others because not everything is intermingled. &lt;/p&gt;&lt;p&gt;Now think about how an AI operates on a codebase. It works within a context window. That constraint isn&amp;#39;t unique to AI, people do that too. There is only so much you can keep in your head, and proper architecture means that you are separating concerns so you can work with just the relevant details in mind. &lt;/p&gt;&lt;p&gt;When your architecture is clean, the AI can focus on exactly the right piece of the system. When it isn&amp;#39;t, you&amp;#39;re either feeding the AI irrelevant noise or hiding the context it actually needs from it.&lt;/p&gt;&lt;p&gt;Good architecture, it turns out, is also a good AI interface. And the reason this works is the same as for people: it reduces the cognitive load you have to carry while understanding and modifying the system. For AI, we just call it the context window. For people, it is cognitive load. Same term, same concept. &lt;/p&gt;&lt;p&gt;Beyond the mechanical benefits, good architecture gives you two things that I think are underappreciated in this conversation.&lt;/p&gt;&lt;p&gt;The first is &lt;em&gt;structural comprehension&lt;/em&gt;. You don&amp;#39;t need to have every line of a large codebase in your head. But you do need a genuine mental model of how data flows, how components relate, and where things live. That&amp;#39;s only possible if the architecture actually reflects the system&amp;#39;s intent. &lt;/p&gt;&lt;p&gt;When using AI to generate code, you &lt;em&gt;need&lt;/em&gt;&amp;nbsp;to have a proper understanding of the flow of the system. That allows you to look at a pull request and understand the changes, their intent, and how they fit into the greater whole. Without that, you can&amp;#39;t meaningfully review the code. You&amp;#39;re just rubber-stamping diffs you don&amp;#39;t have a hope of understanding.&lt;/p&gt;&lt;p&gt;The second is that &lt;em&gt;the work has shifted&lt;/em&gt;. We&amp;#39;re moving from &amp;quot;how do I write this code?&amp;quot; to &amp;quot;how do I review all of this code?&amp;quot;. Nobody is going to meaningfully maintain 30,000 lines a day of dense AI code. At that point, the codebase has escaped human comprehension, and you&amp;#39;ve &lt;em&gt;lost&lt;/em&gt;the game. This isn&amp;rsquo;t your project anymore, and sooner or later, you&amp;rsquo;ll face the Big Decision.&lt;/p&gt;&lt;h2&gt;Turtles all the way down&lt;/h2&gt;&lt;p&gt;I hear the proposed solution constantly: &amp;quot;I have an agent that writes the code, an agent that tests it, an agent that reviews the reviews, and so on.&amp;quot; This is, I think, genuinely insane for anything that matters.&lt;/p&gt;&lt;p&gt;We already have evidence from the field that this doesn&amp;rsquo;t work. &lt;a href="https://www.digitaltrends.com/computing/ai-code-wreaked-havoc-with-amazon-outage-and-now-the-company-is-making-tight-rules/"&gt;Amazon has had production failures from AI-generated code&lt;/a&gt;&amp;nbsp;produced through exactly these kinds of layered-AI pipelines. Microsoft&amp;#39;s aggressive approach to AI integration has shown what happens when &lt;a href="https://www.digitaltrends.com/computing/from-microsoft-to-microslop-the-ai-backlash-that-forced-a-reset/"&gt;AI-generated code enters production with minimal meaningful human oversight&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In both of those cases, the &amp;ldquo;proper oversight&amp;rdquo; was also provided by AI. And the end result wasn&amp;rsquo;t encouraging for this pattern of behavior. For critical systems that carry &lt;a href="https://dev.to/tyson_cung/amazon-lost-63m-orders-after-ai-coding-tool-went-rogue-now-theyre-hitting-the-brakes-2h7p"&gt;real consequences&lt;/a&gt;, &amp;quot;AI supervising AI&amp;quot; is not a thing.&lt;/p&gt;&lt;p&gt;AI works when you treat it as a tool in your hands, not as an autonomous system you&amp;#39;ve delegated to. An engineer who understands architecture and can look at a diff and say &amp;quot;this is right&amp;quot; or &amp;quot;this is wrong, and here&amp;#39;s why&amp;quot; is &lt;em&gt;much &lt;/em&gt;more capable with AI than without it. &lt;/p&gt;&lt;p&gt;An engineer who has offloaded comprehension to the machine is flying blind; worse, they are flying very fast directly into a cliff wall. &lt;/p&gt;&lt;h2&gt;What should you do about it?&lt;/h2&gt;&lt;p&gt;When we treat AI agents as a tool, it turns out that not all that much &lt;em&gt;needs&lt;/em&gt;&amp;nbsp;to change. The current processes you have in place (CI/CD, testing, review cycles, etc.) are all about being able to &lt;em&gt;generate trust&lt;/em&gt;&amp;nbsp;in the new code being written. Whether a human wrote it or a GPU did is less interesting.&lt;/p&gt;&lt;p&gt;At the same time, we have decades of experience building big systems. We know that a Big Ball of Mud isn&amp;rsquo;t sustainable. We know that proper architecture means breaking the system into digestible chunks. Yes, with AI you can throw everything together, and it will sort of work for a surprisingly long time. Until it doesn&amp;rsquo;t.&lt;/p&gt;&lt;p&gt;With a proper architecture, the scope you need to keep track of is inherently limited. That allows you to evolve over time and make changes that are inherently limited in scope (thus, reviewable, actionable, etc.).&lt;/p&gt;&lt;p&gt;&amp;ldquo;The more things change, the more they stay the same.&amp;rdquo; It is a nice saying, but it also carries a fundamental truth. Using AI doesn&amp;rsquo;t absolve us from the realities on the ground, after all.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203940-c/using-ai-agents-in-long-lived-software-projects?Key=ba47e46e-bfb5-454a-ad3e-178ebc501c01</link><guid>http://ayende.org/203940-c/using-ai-agents-in-long-lived-software-projects?Key=ba47e46e-bfb5-454a-ad3e-178ebc501c01</guid><pubDate>Tue, 21 Apr 2026 12:00:00 GMT</pubDate></item><item><title>Agents, Code Reviews, and the Bottleneck Shift, Oh My!</title><description>&lt;p&gt;Like everything else, we have been using AI in various forms for a while now, from asking ChatGPT to write a function to asking it to explain an error, then graduating to running it on our code in the IDE, and finally to full-blown independent coding assistants. &lt;/p&gt;&lt;p&gt;Recently, we shifted into a much higher gear, rolling it out across most of the teams at RavenDB. I want to talk specifically about what that looks like in practice in real production software.&lt;/p&gt;&lt;p&gt;RavenDB is a mature codebase, with about 18 years of history behind it. The core team is a few dozen developers working on this full-time. We also care &lt;em&gt;very&lt;/em&gt;&amp;nbsp;deeply about correctness, performance, and maintainability. &lt;/p&gt;&lt;p&gt;With all the noise about Claude, Codex, and their ilk recently, we decided to run some experiments to see how we can leverage them to help us build RavenDB.&lt;/p&gt;&lt;h2&gt;The numbers that got my attention&lt;/h2&gt;&lt;p&gt;We started with features that were relatively self-contained &amp;mdash; ambitious enough to be real work, but isolated enough that an AI agent could take them end-to-end without stepping on core aspects of RavenDB. &lt;/p&gt;&lt;p&gt;The first one was estimated at about a month of work for a senior developer. We completed it in two days. To be fair, a significant portion of that time was spent learning how to work effectively with Claude as an agent, learning the ropes and the right discipline and workflows, not just the task itself.&lt;/p&gt;&lt;p&gt;The second was estimated at roughly three months for an initial version. It was delivered in about a week. And we didn&amp;#39;t just hit the target &amp;mdash; we significantly exceeded the planned feature set.&lt;/p&gt;&lt;p&gt;In terms of efficiency, we are talking about a proper &lt;em&gt;leap&lt;/em&gt;&amp;nbsp;from what we previously could expect. &lt;/p&gt;&lt;h2&gt;This isn&amp;#39;t vibe coding&lt;/h2&gt;&lt;p&gt;I want to be direct about something: this is not &amp;quot;prompt it and ship it.&amp;quot; There is a discipline required here. The AI can move very fast, explore a lot of ground, and generate code that looks right, but isn&amp;rsquo;t. Code ownership and engineering responsibility don&amp;#39;t go away; they become much more demanding.&lt;/p&gt;&lt;p&gt;I personally sat and read 30,000 lines of code. I had to understand what was there, push back on decisions, redirect the approach, and enforce the standards that RavenDB has built up over many years. &lt;/p&gt;&lt;p&gt;Those 30,000 lines of code didn&amp;rsquo;t appear out of thin air. They were the final result of a &lt;em&gt;lot&lt;/em&gt;&amp;nbsp;of planning, back and forth with the agent, incremental steps in the right direction (and many wrong ones, etc.).&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;To be fair, 30,000 lines of code sounds like a &lt;em&gt;lot&lt;/em&gt;, right? About 60% of that is actually tests, and about half of the remaining code is boilerplate infrastructure that we need to have, but isn&amp;rsquo;t really interesting. &lt;/p&gt;&lt;p&gt;The juicy parts are only around 5,000 lines or so. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In many respects, this isn&amp;rsquo;t prompt-and-go but feels a lot more like a pair programming session on steroids. &lt;/p&gt;&lt;p&gt;What AI agents give you is the ability to explore the problem space cheaply and quickly. After we had something built, I had a different idea about how to go about implementing it. So I asked it to do that, and it gave me something that I could actually &lt;em&gt;explore&lt;/em&gt;. &lt;/p&gt;&lt;p&gt;Being able to evaluate multiple different approaches to a solution is &lt;em&gt;crazy&lt;/em&gt;&amp;nbsp;valuable.&amp;nbsp;It is transformative for architectural decisions. &lt;/p&gt;&lt;p&gt;Having said that, using a coding agent to take all the boilerplate stuff meant that I was able to focus on the &amp;ldquo;fun parts&amp;rdquo;, the pieces that actually add the most value, not everything else that I need to do to get to that part.&lt;/p&gt;&lt;h2&gt;What this means going forward&lt;/h2&gt;&lt;p&gt;AI agents are going to amplify your existing engineering culture, for better or worse.&lt;/p&gt;&lt;p&gt;A lot of the cost of writing good software is going to move from actually writing code to reviewing it. For many people, the act of writing the code was also the part where they &lt;em&gt;thought&lt;/em&gt;&amp;nbsp;about it most deeply. &lt;/p&gt;&lt;p&gt;Now the thinking part moves either upfront, at the planning phase, or to the end, when you look at the pull request. Reading a pull request, you could reasonably expect to see code that has already been reasoned about and properly tamed. &lt;/p&gt;&lt;p&gt;Now, in some cases, this is the first time that a human is actually going to properly walk through the whole thing. To ensure proper quality, you also need to shift a lot of your focus to that part. &lt;/p&gt;&lt;p&gt;The bottleneck for good software is going to be the review cycle, the architectural approach, and an experienced team that can actually evaluate the output and ensure consistent high quality.&lt;/p&gt;&lt;p&gt;Without that, you can go very fast, but just generating code quickly is a losing proposition. You&amp;rsquo;ll go very fast directly into a painful collision with a wall.&lt;/p&gt;&lt;p&gt;We are still settling down and trying to properly understand the best approach to take, but I have to say that this experiment was a major success.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203939-c/agents-code-reviews-and-the-bottleneck-shift-oh-my?Key=a4aac51e-45ff-426d-8340-9c2056e743f0</link><guid>http://ayende.org/203939-c/agents-code-reviews-and-the-bottleneck-shift-oh-my?Key=a4aac51e-45ff-426d-8340-9c2056e743f0</guid><pubDate>Fri, 17 Apr 2026 12:00:00 GMT</pubDate></item><item><title>Introducing: RavenDB Kubernetes Operator</title><description>&lt;p&gt;RavenDB has recently introduced its dedicated Kubernetes Operator, a big improvement over the Helm charts that teams have been using. This is meant to streamline database orchestration and management, essentially giving you an automated &amp;quot;SRE-in-a-box.&amp;quot;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You can read the &lt;a href="https://github.com/ravendb/ravendb/discussions/22115"&gt;full announcement here&lt;/a&gt;. And the actual operator &lt;a href="https://github.com/ravendb/ravendb-operator?tab=readme-ov-file#ravendb-kubernetes-operator"&gt;is available here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The Operator shifts the management paradigm from manual configuration to a declarative model. Simply applying a &lt;code&gt;RavenDBCluster &lt;/code&gt;custom resource definition (CRD) allows developers to automate the heavy lifting of cluster formation, storage binding, and external networking, removing the operational friction typically associated with running stateful distributed systems on K8s.&lt;/p&gt;&lt;p&gt;Most importantly, it isn&amp;rsquo;t a one-time thing. The RavenDB Kubernetes Operator is all about &amp;quot;Day 2&amp;quot; operational intelligence. It handles complex lifecycle tasks with high precision, such as executing safe rolling upgrades with built-in validation gates to prevent breaking changes.&lt;/p&gt;&lt;p&gt;From dealing with the intricacies of certificate rotation&amp;mdash;supporting both Let&amp;rsquo;s Encrypt and private PKI&amp;mdash;to providing real-time health insights directly via &lt;code&gt;kubectl&lt;/code&gt;, the automation of these critical maintenance tasks lets the Operator ensure that your RavenDB clusters remain resilient, secure, and performant with minimal manual intervention.&lt;/p&gt;&lt;p&gt;For example, you can push an upgrade from RavenDB 7.0 to RavenDB 7.2, and the Operator will automatically handle performing a rolling upgrade for you, ensuring there is no downtime during deployment. There is no need for complex orchestration playbooks, you just push the update, and it happens for you.&lt;/p&gt;&lt;p&gt;This is part of the same DevOps push we are making. &lt;a href="https://ravendb.net/articles/ravendb-ansible-collection-new-features-12-25?utm_source=linkedin&amp;utm_medium=organic&amp;utm_campaign=New_Features"&gt;If you are partial to Ansible, on the other hand, we have recently published great support there as well&lt;/a&gt;.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203715-a/introducing-ravendb-kubernetes-operator?Key=cca815c3-a486-4117-a0dd-0a9047b6095d</link><guid>http://ayende.org/203715-a/introducing-ravendb-kubernetes-operator?Key=cca815c3-a486-4117-a0dd-0a9047b6095d</guid><pubDate>Thu, 15 Jan 2026 12:00:00 GMT</pubDate></item><item><title>Swiping left on writing authentication code yourself</title><description>&lt;p&gt;You may have heard about &lt;a href="https://www.resecurity.com/blog/article/mongobleed-cve-2025-14847-mongodb-memory-leak-flaw"&gt;a recent security vulnerability in MongoDB&lt;/a&gt;&amp;nbsp;(MongoBleed). The gist is that you can (as an unauthenticated user) remotely read the contents of MongoDB&amp;rsquo;s memory (including things like secrets, document data, and PII). You can read the details about the actual technical issue in the link above.&lt;/p&gt;&lt;p&gt;The root cause of the problem is that the authentication process for MongoDB uses MongoDB&amp;rsquo;s own code. That sounds like a very strange statement, no? Consider the layer at which authentication happens. MongoDB handles authentication at the application level.&lt;/p&gt;&lt;p&gt;Let me skip ahead a bit to talk about how RavenDB handles the problem of authentication. We &lt;a href="https://ayende.com/blog/178977/ravendb-4-0-securing-the-keys-to-the-kingdom"&gt;thought long and hard about that problem&lt;/a&gt;&amp;nbsp;when we redesigned RavenDB for the 4.0 release. One of the key design decisions we made was to &lt;em&gt;not&lt;/em&gt;&amp;nbsp;handle authentication ourselves.&lt;/p&gt;&lt;p&gt;Authentication in RavenDB is based on X.509 certificates. That is usually the highest level of security you&amp;rsquo;re asked for by enterprises anyway, so RavenDB&amp;rsquo;s minimum security level is already at the high end. That decision, however, had a lot of other implications. &lt;/p&gt;&lt;p&gt;RavenDB doesn&amp;rsquo;t have any code to actually authenticate a user. Instead, authentication happens at the infrastructure layer, before any application-level code runs. That means that at a very fundamental level, we don&amp;rsquo;t &lt;em&gt;deal&lt;/em&gt;&amp;nbsp;with unauthenticated input. That is rejected &lt;em&gt;very&lt;/em&gt;&amp;nbsp;early in the process.&lt;/p&gt;&lt;p&gt;It isn&amp;rsquo;t a theoretical issue, by the way. A &lt;a href="https://www.ravendb.net/articles/on-cve-2025-55315-security-assessment"&gt;recent CVE was released&lt;/a&gt;&amp;nbsp;for .NET-based applications (of which RavenDB is one) that could lead to exactly this issue, an authentication bypass problem.RavenDB is &lt;em&gt;not&lt;/em&gt;&amp;nbsp;vulnerable as a result of this issue because the authentication mechanism it relies on is much lower in the stack.&lt;/p&gt;&lt;p&gt;By the same token, the code that actually performs the authentication for RavenDB is the same code that validates that your connection to your bank is secure from hackers. On Linux - OpenSSL, on Windows - SChannel. These are already &lt;em&gt;very&lt;/em&gt;&amp;nbsp;carefully scrutinized and security-critical infrastructure for pretty much everyone. &lt;/p&gt;&lt;p&gt;This design decision also leads to an interesting division inside RavenDB. There is a very strict separation between authentication-related code (provided by the platform) and RavenDB&amp;rsquo;s. &lt;/p&gt;&lt;p&gt;The problem for MongoDB is that they reused the same code for reading BSON documents from the network as part of their authentication mechanism. &lt;/p&gt;&lt;p&gt;That means that &lt;em&gt;any&lt;/em&gt;&amp;nbsp;aspect of BSON in MongoDB needs to be analyzed with an eye toward unauthenticated user input, as this CVE shows. &lt;/p&gt;&lt;p&gt;An attempt to add compression support to reduce network traffic resulted in size confusion, which then led to this problem. To be clear, that is a very reasonable set of steps that happened. For RavenDB, something similar is plausible, but not for &lt;em&gt;unauthorized users&lt;/em&gt;.&lt;/p&gt;&lt;h2&gt;What about Heartbleed?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/h2&gt;&lt;p&gt;The name &lt;a href="https://www.resecurity.com/blog/article/mongobleed-cve-2025-14847-mongodb-memory-leak-flaw"&gt;Mongobleed&lt;/a&gt;&amp;nbsp;is an intentional reference to &lt;a href="https://en.wikipedia.org/wiki/Heartbleed"&gt;a very similar bug in OpenSSL&lt;/a&gt;&amp;nbsp;from over a decade ago, with similar disastrous consequences. Wouldn&amp;rsquo;t RavenDB then be vulnerable in the same manner as MongoDB?&lt;/p&gt;&lt;p&gt;That is where the choice to use the platform infrastructure comes to our aid. Yes, in such a scenario, RavenDB would be vulnerable. But so would pretty much everything else. For example, MongoDB itself, even though it isn&amp;rsquo;t using OpenSSL for authentication, would also be vulnerable to such a bug in OpenSSL.&lt;/p&gt;&lt;p&gt;The good thing about OpenSSL&amp;rsquo;s Heartbleed bug is that it shined a huge spotlight on such bugs, and it means that a &lt;em&gt;lot&lt;/em&gt;&amp;nbsp;of time, money, and effort has been dedicated to rooting out similar issues, to the point where trust in OpenSSL has been restored. &lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;One of the key decisions that we made when we built RavenDB was to look at how we could use the underlying (battle-tested) infrastructure to do things for us. &lt;/p&gt;&lt;p&gt;For security purposes, that means we have reduced the risk of vulnerabilities. A bug in RavenDB code isn&amp;rsquo;t a security vulnerability, you have to target the (much more closely scrutinized) infrastructure to actually get to a vulnerable state. That is part of our Zero Trust policy. &lt;/p&gt;&lt;p&gt;RavenDB has a far simpler security footprint, we use the enterprise-level TLS &amp;amp; X.509 for authentication instead of implementing six different protocols (and carrying the liability of each). This both simplifies the process of setting up RavenDB securely and reduces the effort required to achieve proper security compliance.&lt;/p&gt;&lt;p&gt;You cannot underestimate the power of checking the &amp;ldquo;X.509 client authentication&amp;rdquo; box and dropping whole &lt;em&gt;sections&lt;/em&gt;&amp;nbsp;of the security audit when deploying a new system. &lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203651-b/swiping-left-on-writing-authentication-code-yourself?Key=80bc09c8-a4ec-4a64-9479-58e7f514ee6e</link><guid>http://ayende.org/203651-b/swiping-left-on-writing-authentication-code-yourself?Key=80bc09c8-a4ec-4a64-9479-58e7f514ee6e</guid><pubDate>Wed, 07 Jan 2026 12:00:00 GMT</pubDate></item><item><title>PropertySphere bot: understanding images</title><description>&lt;p&gt;In &lt;a href="https://ayende.com/blog/203621-B/propertyspheres-intelligent-telegram-bot?key=1802d1b262ad40169d1fcac2ebf1acff"&gt;the previous post&lt;/a&gt;, I talked about the &lt;a href="https://github.com/ayende/samples.properties"&gt;PropertySphere&lt;/a&gt;&amp;nbsp;Telegram bot (you can also &lt;a href="https://www.youtube.com/watch?v=XOdXDNIGzxE"&gt;watch the full video here&lt;/a&gt;). In this post, I want to show how we can make it even smarter. Take a look at the following chat screenshot:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/FoTncQtYsh8DLJQ3Aj7AfA.png"/&gt;&lt;/p&gt;&lt;p&gt;What is actually going on here? This small interaction showcases a &lt;em&gt;numbe&lt;/em&gt;r of RavenDB features, all at once. Let&amp;rsquo;s first focus on how Telegram hands us images. This is done using Photoor &lt;code&gt;Document &lt;/code&gt;messages (depending on exactly how you send the message to Telegram).&lt;/p&gt;&lt;p&gt;The following code shows how we receive and store a photo from Telegram:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token comment"&gt;// Download the largest version of the photo from Telegram:&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; ms &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;MemoryStream&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; fileId &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;message&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Photo.MaxBy&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;ps &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ps&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;FileSize&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;FileId&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; file &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;botClient&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;GetInfoAndDownloadFile&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;fileId&lt;span class="token punctuation"&gt;,&lt;/span&gt; ms&lt;span class="token punctuation"&gt;,&lt;/span&gt; cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;

&lt;span class="token comment"&gt;// Create a Photo document to store metadata:&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; photo &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;Photo&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    &lt;span class="token class-name"&gt;ConversationId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;GetConversationId&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;chatId&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;Id&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"photos/"&lt;/span&gt;&lt;/span&gt; &lt;span class="token operator"&gt;+&lt;/span&gt; &lt;span class="token class-name"&gt;Guid.NewGuid&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToString&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"N"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;RenterId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;renter&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Id&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;Caption&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;message&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Caption&lt;/span&gt; &lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;message&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Text&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;

&lt;span class="token comment"&gt;// Store the image as an attachment on the document:&lt;/span&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;StoreAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;photo&lt;span class="token punctuation"&gt;,&lt;/span&gt; cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ms&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Position&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token number"&gt;0&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Advanced.Attachments.Store&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;photo&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"image.jpg"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; ms&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;SaveChangesAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;

&lt;span class="token comment"&gt;// Notify the user that we're processing the image:&lt;/span&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;botClient&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;SendMessage&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
chatId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
       &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Looking at the photo you sent..., may take me a moment..."&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
       cancellationToken
&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;A &lt;code&gt;Photo&lt;/code&gt;&amp;nbsp;message in Telegram may contain multiple versions of the image in various resolutions. Here I&amp;rsquo;m simply selecting the best one by file size, downloading the image from Telegram&amp;rsquo;s servers to a memory stream, then I create a &lt;code&gt;Photo&lt;/code&gt;&amp;nbsp;document and add the image stream to it as an attachment.&lt;/p&gt;&lt;p&gt;We also tell the client to wait while we process the image, but there is no further code that &lt;em&gt;does&lt;/em&gt;&amp;nbsp;anything with it. &lt;/p&gt;&lt;h2&gt;Gen AI &amp;amp; Attachment processing&lt;/h2&gt;&lt;p&gt;We use a Gen AI task to actually process the image, handling it in the background since it may take a while and we want to keep the chat with the user open. That said, if you look at the actual screenshots, the entire conversation took under a minute.&lt;/p&gt;&lt;p&gt;Here is the actual Gen AI task definition for processing these photos:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token keyword"&gt;var&lt;/span&gt; genAiTask &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;GenAiConfiguration&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Image Description Generator"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;Identifier&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;TaskIdentifier&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;Collection&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Photos"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;Prompt&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
        You are an AI Assistant looking at photos from renters in 
        rental property management, usually about some issue they have. 
        Your task is to generate a concise and accurate description of what 
        is depicted in the photo provided, so maintenance can help them.
        """&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;


    &lt;span class="token comment"&gt;// Expected structure of the model's response:&lt;/span&gt;
    &lt;span class="token class-name"&gt;SampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
        {
            "Description": "Description of the image"
        }
        """&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;


    &lt;span class="token comment"&gt;// Apply the generated description to the document:&lt;/span&gt;
    &lt;span class="token class-name"&gt;UpdateScript&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"this.Description = &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;output&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt;.Description;"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;


    &lt;span class="token comment"&gt;// Pass the caption and image to the model for processing:&lt;/span&gt;
    &lt;span class="token class-name"&gt;GenAiTransformation&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;GenAiTransformation&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Script&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
            ai.genContext({
                Caption: this.Caption
            }).withJpeg(loadAttachment("image.jpg"));
            """&lt;/span&gt;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;ConnectionStringName&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Property Management AI Model"&lt;/span&gt;&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;What we are doing here is asking RavenDB to send the caption and image contents from each document in the Photos collection to the AI model, along with the given prompt.&amp;nbsp;Then we ask it to explain in detail what is in the picture. &lt;/p&gt;&lt;p&gt;Here is an example of the results of this task after it completed. For reference, here is the full description of the image from the model:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A leaking metal pipe under a sink is dripping water into a bucket. There is water and stains on the wooden surface beneath the pipe, indicating ongoing leakage and potential water damage.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;img src="/blog/Images/ktSm-_2Tpkg8fVCY2YtJUg.png"/&gt;&lt;/p&gt;&lt;h3&gt;What model is required for this?&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;I&amp;rsquo;m using the &lt;code&gt;gpt-4.1-mini&lt;/code&gt;&amp;nbsp;model here; there is no need for anything beyond that. It is a multimodal model capable of handling both text and images, so it works great for our needs.&lt;/p&gt;&lt;p&gt;You can read more about &lt;a href="https://ravendb.net/articles/unlock-ravendb-genai-potential-with-attachments"&gt;processing attachments with RavenDB&amp;rsquo;s Gen AI here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;We still need to close the loop, of course. The Gen AI task that processes the images is actually running in the background. How do we get the output of that from the database and into the chat?&lt;/p&gt;&lt;p&gt;To process that, we create a RavenDB Subscription to the Photos collection, which looks like this:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-json'&gt;&lt;code class='line-numbers language-json'&gt;store.Subscriptions.Create(new SubscriptionCreationOptions
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    Name = SubscriptionName&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    Query = &lt;span class="token string"&gt;""&lt;/span&gt;"
        from &lt;span class="token string"&gt;"Photos"&lt;/span&gt; 
        where Description != &lt;span class="token null keyword"&gt;null&lt;/span&gt;
        &lt;span class="token string"&gt;""&lt;/span&gt;"
&lt;span class="token punctuation"&gt;}&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;This subscription is called by RavenDB whenever a document in the Photos collection is created or updated with the &lt;em&gt;Description&lt;/em&gt;&amp;nbsp;having a value. In other words, this will be triggered when the GenAI task updates the photo after it runs. &lt;/p&gt;&lt;p&gt;The actual handling of the subscription is done using the following code:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;_documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;Subscriptions&lt;span class="token punctuation"&gt;.&lt;/span&gt;GetSubscriptionWorker&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Photo&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"After Photos Analysis"&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Run&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token keyword"&gt;async&lt;/span&gt; &lt;span class="token parameter"&gt;batch&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        using &lt;span class="token keyword"&gt;var&lt;/span&gt; session &lt;span class="token operator"&gt;=&lt;/span&gt; batch&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OpenAsyncSession&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
        &lt;span class="token function"&gt;foreach&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;&lt;span class="token keyword"&gt;var&lt;/span&gt; item &lt;span class="token keyword"&gt;in&lt;/span&gt; batch&lt;span class="token punctuation"&gt;.&lt;/span&gt;Items&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;{&lt;/span&gt;
            &lt;span class="token keyword"&gt;var&lt;/span&gt; renter &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; session&lt;span class="token punctuation"&gt;.&lt;/span&gt;LoadAsync&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Renter&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
item&lt;span class="token punctuation"&gt;.&lt;/span&gt;Result&lt;span class="token punctuation"&gt;.&lt;/span&gt;RenterId&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
            &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token function"&gt;ProcessMessageAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;_botClient&lt;span class="token punctuation"&gt;,&lt;/span&gt; renter&lt;span class="token punctuation"&gt;.&lt;/span&gt;TelegramChatId&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
                $&lt;span class="token string"&gt;"Uploaded an image with caption: {item.Result.Caption}\r\n"&lt;/span&gt; &lt;span class="token operator"&gt;+&lt;/span&gt;
                $&lt;span class="token string"&gt;"Image description: {item.Result.Description}."&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
                cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
        &lt;span class="token punctuation"&gt;}&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;In other words, we run over the items in the subscription batch, and for each one, we emit a &amp;ldquo;fake&amp;rdquo; message as if it were sent by the user to the Telegram bot. Note that we aren&amp;rsquo;t invoking the RavenDB conversation directly, but instead reusing the Telegram message handling logic. This way, the reply from the model will go directly back into the users&amp;#39; chat.&lt;/p&gt;&lt;p&gt;You can see how that works in the screenshot above. It looks like the model looked at the image, and then it acted. In this case, it acted by creating a service request. We previously looked at charging a credit card, and now let&amp;rsquo;s see how we handle creating a service request by the model.&lt;/p&gt;&lt;p&gt;The AI Agent is defined with a &lt;code&gt;CreateServiceRequest&lt;/code&gt;&amp;nbsp;action, which looks like this:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-bash'&gt;&lt;code class='line-numbers language-bash'&gt;Actions &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;
    new AiAgentToolAction
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        Name &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string"&gt;"CreateServiceRequest"&lt;/span&gt;,
        Description &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string"&gt;"Create a new service request for the renter's unit"&lt;/span&gt;,
        ParametersSampleObject &lt;span class="token operator"&gt;=&lt;/span&gt; JsonConvert.SerializeObject&lt;span class="token punctuation"&gt;(&lt;/span&gt;
            new CreateServiceRequestArgs
            &lt;span class="token punctuation"&gt;{&lt;/span&gt;
                    Type &lt;span class="token operator"&gt;=&lt;/span&gt;         &lt;span class="token string"&gt;""&lt;/span&gt;"
Maintenance &lt;span class="token operator"&gt;|&lt;/span&gt; Repair &lt;span class="token operator"&gt;|&lt;/span&gt; Plumbing &lt;span class="token operator"&gt;|&lt;/span&gt; Electrical &lt;span class="token operator"&gt;|&lt;/span&gt; 
HVAC &lt;span class="token operator"&gt;|&lt;/span&gt; Appliance &lt;span class="token operator"&gt;|&lt;/span&gt; Community &lt;span class="token operator"&gt;|&lt;/span&gt; Neighbors &lt;span class="token operator"&gt;|&lt;/span&gt; Other
&lt;span class="token string"&gt;""&lt;/span&gt;",
            Description &lt;span class="token operator"&gt;=&lt;/span&gt;         &lt;span class="token string"&gt;""&lt;/span&gt;"
Detailed description of the issue with all 
relevant context
&lt;span class="token string"&gt;""&lt;/span&gt;"
                &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;,
&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;As a reminder, this is the description of the action that the model can invoke. Its actual handling is done when we create the conversation, like so:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Handle&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;PropertyAgent.CreateServiceRequestArgs&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"CreateServiceRequest"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token keyword"&gt;async&lt;/span&gt; args &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    using &lt;span class="token keyword"&gt;var&lt;/span&gt; session &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OpenAsyncSession&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token keyword"&gt;var&lt;/span&gt; unitId &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;renterUnits&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;FirstOrDefault&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token keyword"&gt;var&lt;/span&gt; propertyId &lt;span class="token operator"&gt;=&lt;/span&gt; unitId&lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Substring&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token number"&gt;0&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;unitId&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;LastIndexOf&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;'/'&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;var&lt;/span&gt; serviceRequest &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;ServiceRequest&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;RenterId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;renter&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Id&lt;/span&gt;&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;UnitId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; unitId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Type&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;args&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Type&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;args&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Description&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Status&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Open"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;OpenedAt&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime.UtcNow&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;PropertyId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; propertyId
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;StoreAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;serviceRequest&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;SaveChangesAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;return&lt;/span&gt; $&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Service request created ID `{serviceRequest.Id}` for your unit."&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;In this case, there isn&amp;rsquo;t really much &lt;em&gt;to&lt;/em&gt;&amp;nbsp;do here, but hopefully this conveys the kind of code this allows you to write.&lt;/p&gt;&lt;h1&gt;Summary&lt;/h1&gt;&lt;p&gt;The &lt;a href="https://github.com/ayende/samples.properties"&gt;PropertySphere&lt;/a&gt;&amp;nbsp;sample application and its Telegram bot are interesting, mostly because of everything that &lt;em&gt;isn&amp;rsquo;t&lt;/em&gt;&amp;nbsp;here. We have a bot that has a pretty complex set of behaviors, but there isn&amp;rsquo;t a lot of complexity for &lt;em&gt;us&lt;/em&gt;&amp;nbsp;to deal with.&lt;/p&gt;&lt;p&gt;This behavior is emergent from the capabilities we entrusted to the model, and the kind of capabilities we give it. At the same time, I&amp;rsquo;m not &lt;em&gt;trusting&lt;/em&gt;&amp;nbsp;the model, but verifying that what it does is always within the scope of the user&amp;rsquo;s capabilities. &lt;/p&gt;&lt;p&gt;Extending what we have here to allow additional capabilities is easy. Consider adding the ability to get invoices directly from the Telegram interface, a great exercise in extending what you can do with the sample app.&lt;/p&gt;&lt;p&gt;There is also &lt;a href="https://www.youtube.com/watch?v=XOdXDNIGzxE"&gt;the full video &lt;/a&gt;where I walk you through all aspects of the sample application, and as always, we&amp;rsquo;d love to talk to you on &lt;a href="http://discord.gg/ravendb"&gt;Discord &lt;/a&gt;or in our &lt;a href="http://github.com/ravendb/ravendb/discussions/"&gt;GitHub discussions&lt;/a&gt;.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203622-b/propertysphere-bot-understanding-images?Key=889433c1-a0cb-4633-b096-390e184c9159</link><guid>http://ayende.org/203622-b/propertysphere-bot-understanding-images?Key=889433c1-a0cb-4633-b096-390e184c9159</guid><pubDate>Fri, 26 Dec 2025 12:00:00 GMT</pubDate></item><item><title>PropertySphere's intelligent Telegram bot</title><description>&lt;p&gt;In &lt;a href="https://ayende.com/blog/203620-B/propertysphere-sample-application?key=2ab9814a35aa48ee86f3f3f9b1accd57"&gt;the previous post&lt;/a&gt;, I introduced the &lt;a href="https://github.com/ayende/samples.properties"&gt;PropertySphere&lt;/a&gt;&amp;nbsp;sample application (you can also &lt;a href="https://www.youtube.com/watch?v=XOdXDNIGzxE"&gt;watch the video introducing it here&lt;/a&gt;). In this post, I want to go over how we build a Telegram bot for this application, so Renters can communicate with the application, check their status, raise issues, and even pay their bills.&lt;/p&gt;&lt;p&gt;I&amp;rsquo;m using Telegram here because the process of creating a new bot is trivial, the API is really fun to work with, and it takes very little effort.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Compare that to something like WhatsApp, where just the &lt;em&gt;process&lt;/em&gt;&amp;nbsp;for creating a bot is a PITA. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Without further ado, let&amp;rsquo;s look at what the Telegram bot looks like:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/ykeP1CWNETKtFlzQteq9ow.png"/&gt;&lt;/p&gt;&lt;p&gt;There are a bunch of interesting things that you can see in the screenshot. We communicate with the bot on the other end using natural text. There aren&amp;#39;t a lot of screens / options that you have to go through, it is just natural mannerism.&lt;/p&gt;&lt;p&gt;The process is pretty streamlined from the perspective of the user. What does that look like from the implementation perspective? A lot of the time, that kind of interface involves&amp;hellip; &lt;em&gt;big &lt;/em&gt;amount of complexity in the backend.&lt;/p&gt;&lt;p&gt;Here is what I usually think when I consider those demos:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/SDGqd664wltq5nf1C8FRqQ.png"/&gt;&lt;/p&gt;&lt;p&gt;In our example, we can implement all of this in about 250 lines of code. The magic behind it is the fact that we can rely on RavenDB&amp;rsquo;s AI Agents feature to do most of the heavy lifting for us.&lt;/p&gt;&lt;p&gt;Inside RavenDB, this is defined as follows:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/ivSxYW8aNkfTU0f4jxAjPA.png"/&gt;&lt;/p&gt;&lt;p&gt;For this post, however, we&amp;rsquo;ll look at how we actually built this AI-powered Telegram bot. The full code is &lt;a href="https://github.com/ayende/samples.properties/blob/master/Services/PropertyAgent.cs"&gt;here&lt;/a&gt;&amp;nbsp;if you want to browse through it. &lt;/p&gt;&lt;h3&gt;What model is used here?&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;It&amp;rsquo;s worth mentioning that I&amp;rsquo;m not using anything fancy, the agent is using baseline &lt;code&gt;gpt-4.1-mini&lt;/code&gt;&amp;nbsp;for the demo. There is no need for training or customization, the way we create the agent already takes care of that.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Here is the overall agent definition: &lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;store&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;AI.CreateAgent&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
    &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentConfiguration&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Property Assistant"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Identifier&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"property-agent"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;ConnectionStringName&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Property Management AI Model"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;SystemPrompt&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
            You are a property management assistant for renters.
            ... redacted ...
            Do NOT discuss non-property topics. 
            """&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Parameters&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;
            &lt;span class="token comment"&gt;// Visible to the model:&lt;/span&gt;
            &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentParameter&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"currentDate"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Current date in yyyy-MM-dd format"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token comment"&gt;// Agent scope only, not visible to the model directly&lt;/span&gt;
            &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentParameter&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"renterId"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Renter ID; answer only for this renter"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; sendToModel&lt;span class="token punctuation"&gt;:&lt;/span&gt; &lt;span class="token boolean"&gt;false&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentParameter&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"renterUnits"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"List of unit IDs occupied by the renter"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; sendToModel&lt;span class="token punctuation"&gt;:&lt;/span&gt; &lt;span class="token boolean"&gt;false&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;SampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;JsonConvert.SerializeObject&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;Reply&lt;/span&gt;
        &lt;span class="token punctuation"&gt;{&lt;/span&gt;
            &lt;span class="token class-name"&gt;Answer&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Detailed answer to query (markdown syntax)"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token class-name"&gt;Followups&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Likely follow-ups"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token comment"&gt;// redacted&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;The code above will create an agent with the given prompt. It turns out that a lot of work actually goes into that prompt to explain to the AI model exactly what its role is, what it is meant to do, etc. &lt;/p&gt;&lt;p&gt;I reproduced the entire prompt below so you can read it more easily, but take into account that you&amp;rsquo;ll likely tweak it a &lt;em&gt;lot&lt;/em&gt;, and that it is usually much longer than what we have here (although what we have below is quite functional, as you can see from the screenshots).&lt;/p&gt;&lt;h3&gt;The agent&amp;rsquo;s prompt&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;You are a property management assistant for renters.&lt;/p&gt;&lt;p&gt;Provide information about rent, utilities, debts, service requests, and property details.&lt;/p&gt;&lt;p&gt;Be professional, helpful, and responsive to renters&amp;rsquo; needs.&lt;/p&gt;&lt;p&gt;You can answer in Markdown format. Make sure to use ticks (`) whenever you discuss identifiers.&lt;/p&gt;&lt;p&gt;Do not suggest actions that are not explicitly allowed by the tools available to you.&lt;/p&gt;&lt;p&gt;Do NOT discuss non-property topics. Answer only for the current renter.&lt;/p&gt;&lt;p&gt;When discussing amounts, always format them as currency with 2 decimal places.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The way RavenDB deals with AI Agents, we define two very important aspects of them. First, we have the parameters, which define the scope of the system. In this case, you can see that we pass the &lt;code&gt;currentDate&lt;/code&gt;, as well as provide the &lt;code&gt;renterId &lt;/code&gt;and &lt;code&gt;renterUnits &lt;/code&gt;that this agent is going to deal with. &lt;/p&gt;&lt;p&gt;We expose the current date to the model, but not the renter ID or the units that define the scope (we&amp;rsquo;ll touch on that in a bit). The model needs the current date so it will understand when it is running and have context for things like &amp;ldquo;last month&amp;rdquo;. But we don&amp;rsquo;t need to give it the IDs, they have no meaning and are instead used to define the scope of a particular conversation with the model. &lt;/p&gt;&lt;p&gt;The sample object we use defines the structure of the reply that we require the model to give us. In this case, we want to get a textual message from the model in Markdown format, as well as a separate array of likely follow-ups that we can provide to the user.&lt;/p&gt;&lt;p&gt;In order to do its job, the agent needs to be able to access the system. RavenDB handles that by letting you define queries that the model can ask the agent to execute when it needs more information. Here are some of them:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;Queries&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;
    &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentToolQuery&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"GetRenterInfo"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Retrieve renter profile details"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Query&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"from Renters where id() = &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;renterId&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;ParametersSampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"{}"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Options&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentToolQueryOptions&lt;/span&gt;
        &lt;span class="token punctuation"&gt;{&lt;/span&gt;
            &lt;span class="token class-name"&gt;AllowModelQueries&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token boolean"&gt;false&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token class-name"&gt;AddToInitialContext&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token boolean"&gt;true&lt;/span&gt;
        &lt;span class="token punctuation"&gt;}&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
     &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentToolQuery&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"GetOutstandingDebts"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Retrieve renter's outstanding debts (unpaid balances)"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Query&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
            from index 'DebtItems/Outstanding'
            where RenterIds in (&lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;renterId&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt;) and AmountOutstanding &gt; 0
            order by DueDate asc
            limit 10
            """&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;ParametersSampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"{}"&lt;/span&gt;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentToolQuery&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"GetUtilityUsage"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
Retrieve utility usage for renter's unit within a date 
range (for calculating bills)
"""&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Query&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
            from 'Units'
            where id() in (&lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;renterUnits&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt;)
            select 
                timeseries(from 'Power' 
between &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;startDate&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt; and &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;endDate&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt; 
group by 1d 
select sum()),
                timeseries(from 'Water' 
between &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;startDate&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt; and &lt;/span&gt;&lt;span class="token interpolation"&gt;&lt;span class="token punctuation"&gt;$&lt;/span&gt;&lt;span class="token expression"&gt;endDate&lt;/span&gt;&lt;/span&gt;&lt;span class="token string"&gt; 
group by 1d 
select sum())
            """&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;ParametersSampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; 
&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
{
"startDate": "yyyy-MM-dd", 
"endDate": "yyyy-MM-dd"
}
"""&lt;/span&gt;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;The first query in the previous snippet, &lt;code&gt;GetRenterInfo, &lt;/code&gt;is interesting. You can see that it is marked as: &lt;code&gt;AllowModelQueries = false, AddToInitialContext = true. W&lt;/code&gt;hat does that mean?&lt;/p&gt;&lt;p&gt;It means that as part of creating a new conversation with the model, we are going to run the query to get all the renter&amp;rsquo;s details and add that to the initial context we send to the model. That allows us to provide the model with the information it will likely need upfront. &lt;/p&gt;&lt;p&gt;Note that we use the &lt;code&gt;$renterId&lt;/code&gt;&amp;nbsp;and &lt;code&gt;$renterUnits&lt;/code&gt;&amp;nbsp;parameters in the queries. While they aren&amp;rsquo;t exposed directly to the model, they affect what information the model can see. This is a good thing, since it means we place guardrails very early on. The model simply cannot see any information that is out of scope for it.&lt;/p&gt;&lt;h2&gt;The model can ask for additional information when it needs to&amp;hellip;&lt;/h2&gt;&lt;p&gt;An important observation about the design of AI agents with RavenDB: note that we provided the model with a bunch of potential queries that it can run. &lt;code&gt;GetRenterInfo &lt;/code&gt;is run at the beginning, since it gives us the initial context, but the rest are left for the judgment of the model.&lt;/p&gt;&lt;p&gt;The model can decide what queries it needs to run in order to answer the user&amp;rsquo;s questions, and it does so of its own accord. This decision means that once you have defined the set of queries and operations that the model can run, you are mostly done. The AI is smart enough to figure out what to do and then act according to your data.&lt;/p&gt;&lt;p&gt;Here is an example of what this looks like from the backend:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/IKdfEV3eVXzR_jl_InBldw.png"/&gt;&lt;/p&gt;&lt;p&gt;Here you can see that the user asked about their utilities, the model then ran the appropriate query and formulated an answer for the user.&lt;/p&gt;&lt;h3&gt;The follow-ups UX pattern&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;You might have noticed that we asked the model for follow-up questions that the user may want to ask. This is a hidden way to guide the &lt;em&gt;user&lt;/em&gt;&amp;nbsp;toward the set of operations that the model supports. &lt;/p&gt;&lt;p&gt;The model will generate the follow-ups based on its own capabilities (queries and actions that it knows it can run), so this is a pretty simple way to &amp;ldquo;tell&amp;rdquo; that to the user without being obnoxious about it.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Let&amp;rsquo;s look at how things work when we actually use this to build the bot, then come back to the rest of the agent&amp;rsquo;s definition. &lt;/p&gt;&lt;h2&gt;Plugging the model into Telegram&lt;/h2&gt;&lt;p&gt;We looked at the agent&amp;rsquo;s definition so far - let&amp;rsquo;s see how we actually use that. The Telegram&amp;rsquo;s API is really nice, basically boiling down to:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;_botClient &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;TelegramBotClient&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;botSecretToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
_botClient&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;StartReceiving&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
    &lt;span class="token class-name"&gt;HandleUpdateAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;HandleErrorAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;ReceiverOptions&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;AllowedUpdates&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;
            &lt;span class="token class-name"&gt;UpdateType.Message&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
            &lt;span class="token class-name"&gt;UpdateType.CallbackQuery&lt;/span&gt; 
            &lt;span class="token punctuation"&gt;]&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    _cts&lt;span class="token punctuation"&gt;.&lt;/span&gt;Token
&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;async&lt;/span&gt; &lt;span class="token class-name"&gt;Task&lt;/span&gt; &lt;span class="token class-name"&gt;HandleUpdateAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token class-name"&gt;ITelegramBotClient&lt;/span&gt; botClient&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token class-name"&gt;Update&lt;/span&gt; update&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token class-name"&gt;CancellationToken&lt;/span&gt; cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    &lt;span class="token keyword"&gt;switch&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;update&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token keyword"&gt;case&lt;/span&gt; &lt;span class="token punctuation"&gt;{&lt;/span&gt; &lt;span class="token class-name"&gt;Message&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt; &lt;span class="token punctuation"&gt;{&lt;/span&gt; &lt;span class="token class-name"&gt;Text&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt; &lt;span class="token punctuation"&gt;{&lt;/span&gt; &lt;span class="token punctuation"&gt;}&lt;/span&gt; messageText &lt;span class="token punctuation"&gt;}&lt;/span&gt; message &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt;
            &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;ProcessMessageAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;botClient&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;message&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Chat.Id.ToString&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
messageText&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
            &lt;span class="token keyword"&gt;break&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;And then the Telegram API will call the &lt;code&gt;HandleUpdateAsync&lt;/code&gt;&amp;nbsp;method when there is a new message to the bot. Note that you may actually get multiple (concurrent messages), maybe from different chats, at the same time.&lt;/p&gt;&lt;p&gt;We&amp;rsquo;ll focus on the process message function, where we start by checking exactly who we are talking to:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;&lt;span class="token keyword"&gt;async&lt;/span&gt; Task &lt;span class="token function"&gt;ProcessMessageAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;ITelegramBotClient botClient&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
string chatId&lt;span class="token punctuation"&gt;,&lt;/span&gt; string messageText&lt;span class="token punctuation"&gt;,&lt;/span&gt; CancellationToken cancellationToken&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    using &lt;span class="token keyword"&gt;var&lt;/span&gt; session &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OpenAsyncSession&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;var&lt;/span&gt; renter &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; session&lt;span class="token punctuation"&gt;.&lt;/span&gt;Query&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Renter&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;FirstOrDefaultAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;r&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; r&lt;span class="token punctuation"&gt;.&lt;/span&gt;TelegramChatId &lt;span class="token operator"&gt;==&lt;/span&gt; chatId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
 cancellationToken&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;if&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;renter &lt;span class="token operator"&gt;==&lt;/span&gt; &lt;span class="token keyword"&gt;null&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token keyword"&gt;await&lt;/span&gt; botClient&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;SendMessage&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;chatId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token string"&gt;"Sorry, your Telegram account is not linked to a renter profile."&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token literal-property property"&gt;cancellationToken&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; cancellationToken
        &lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
        &lt;span class="token keyword"&gt;return&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;
    &lt;span class="token keyword"&gt;var&lt;/span&gt; conversationId &lt;span class="token operator"&gt;=&lt;/span&gt; $&lt;span class="token string"&gt;"chats/{chatId}/{DateTime.Today:yyyy-MM-dd}"&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token comment"&gt;// more code in the next snippet&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;Telegram uses the term chat ID in their API, but it is what I would call the renter&amp;rsquo;s ID. When we register renters, we also record their Telegram chat ID, which means that when we get a message from a user, we can check whether they are a valid renter in our system. If not, we fail early and are done.&lt;/p&gt;&lt;p&gt;If they are, this is where things start to get interesting. Look at the conversation ID that we generated in the last line. RavenDB uses the notion of a conversation with the agent to hold state. The conversation we create here means that the bot will use the same conversation with the user for the same day.&lt;/p&gt;&lt;p&gt;Another way to do that would be to keep the same conversation ID open for the same user. Since RavenDB will automatically handle summarizing and trimming the conversation, either option is fine and mostly depends on your scenario.&lt;/p&gt;&lt;p&gt;The next stage is to create the actual conversation. To do that, we need to provide the model with the right context it is looking for:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-bash'&gt;&lt;code class='line-numbers language-bash'&gt;var renterUnits &lt;span class="token operator"&gt;=&lt;/span&gt; await session.Query&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Lease&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    .Where&lt;span class="token punctuation"&gt;(&lt;/span&gt;l &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; l.RenterIds.Contains&lt;span class="token punctuation"&gt;(&lt;/span&gt;renter.Id&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;))&lt;/span&gt;
    .Select&lt;span class="token punctuation"&gt;(&lt;/span&gt;l &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; l.UnitId&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    .ToListAsync&lt;span class="token punctuation"&gt;(&lt;/span&gt;cts&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


var conversation &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore.AI.Conversation&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"property-agent"&lt;/span&gt;,
    conversationId,
    new AiConversationCreationOptions
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        Parameters &lt;span class="token operator"&gt;=&lt;/span&gt; new Dictionary&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;string, object?&lt;span class="token operator"&gt;&gt;&lt;/span&gt;
        &lt;span class="token punctuation"&gt;{&lt;/span&gt;
            &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string"&gt;"renterId"&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; renter.Id,
            &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string"&gt;"renterUnits"&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; renterUnits,
            &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string"&gt;"currentDate"&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; DateTime.Today.ToString&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"yyyy-MM-dd"&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;}&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;You can see that we pass the renter ID and the relevant units for the renter to the model. Those form the creation parameters for the conversation and cannot be changed. That is one of the reasons why you may want to have a different conversation per day, to get the updated values if they changed.&lt;/p&gt;&lt;p&gt;With that done, we can send the results back to the model and then to the user, like so:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token keyword"&gt;var&lt;/span&gt; result &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;RunAsync&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;PropertyAgent.Reply&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;cts&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;var&lt;/span&gt; replyMarkup &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;ReplyKeyboardMarkup&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;result&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Answer.Followups
    .Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;text &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;KeyboardButton&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;text&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToArray&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;ResizeKeyboard&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token boolean"&gt;true&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;OneTimeKeyboard&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token boolean"&gt;true&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;botClient&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;SendMessage&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
    chatId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;result&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Answer.Answer&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    replyMarkup&lt;span class="token punctuation"&gt;:&lt;/span&gt; replyMarkup&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    cancellationToken&lt;span class="token punctuation"&gt;:&lt;/span&gt; cts&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;The &lt;code&gt;RunAsync()&lt;/code&gt;&amp;nbsp;method handles the entire interaction with the model, and most of the code is just dealing with the reply markup for Telegram.&lt;/p&gt;&lt;p&gt;If you look closely at the chat screenshot above, you can see that we aren&amp;rsquo;t just asking the model questions, we get the bot to perform actions. For example, paying the rent. Here is what this looks like:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/yZoNCftwkqpV06ap7pNWAg.png"/&gt;&lt;/p&gt;&lt;p&gt;How does this work?&lt;/p&gt;&lt;h2&gt;Paying the rent through the bot&lt;/h2&gt;&lt;p&gt;When we looked at the agent, we saw that we exposed some queries that the agent can run. But that isn&amp;rsquo;t the complete picture, we also give the model the ability to run actions. Here is what this looks like from the agent&amp;rsquo;s definition side:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;Actions&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;
    &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;AiAgentToolAction&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Name&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"ChargeCard"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"""
Record a payment for one or more outstanding debts. The 
renter can pay multiple debt items in a single transaction. 
Can pay using any stored card on file.
"""&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;ParametersSampleObject&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;JsonConvert.SerializeObject&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;ChargeCardArgs&lt;/span&gt;
        &lt;span class="token punctuation"&gt;{&lt;/span&gt;
            &lt;span class="token class-name"&gt;DebtItemIds&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"debtitems/1-A"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"debtitems/2-A"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token class-name"&gt;PaymentMethod&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Card"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
            &lt;span class="token class-name"&gt;Card&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Last 4 digits of the card"&lt;/span&gt;&lt;/span&gt;
        &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;
&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;The idea here is that we expose to the model the kinds of actions it can request, and we specify what parameters it should pass to them, etc. What we are &lt;em&gt;not&lt;/em&gt;&amp;nbsp;doing here is giving the model control over actually running any code or modifying any data.&lt;/p&gt;&lt;p&gt;Instead, when the model needs to charge a card, it will have to call &lt;em&gt;your&lt;/em&gt;&amp;nbsp;code and go through validation, business logic, and authorization. Here is what this looks like on the other side. When we create a conversation, we specify handlers for all the actions we need to take, like so:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;Handle&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;PropertyAgent&lt;span class="token punctuation"&gt;.&lt;/span&gt;ChargeCardArgs&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"ChargeCard"&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token keyword"&gt;async&lt;/span&gt; &lt;span class="token parameter"&gt;args&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    using &lt;span class="token keyword"&gt;var&lt;/span&gt; paySession &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OpenAsyncSession&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;var&lt;/span&gt; renterWithCard &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; paySession&lt;span class="token punctuation"&gt;.&lt;/span&gt;LoadAsync&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Renter&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;renter&lt;span class="token punctuation"&gt;.&lt;/span&gt;Id&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; cts&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token keyword"&gt;var&lt;/span&gt; card &lt;span class="token operator"&gt;=&lt;/span&gt; renterWithCard&lt;span class="token operator"&gt;?.&lt;/span&gt;CreditCards
&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;c&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; c&lt;span class="token punctuation"&gt;.&lt;/span&gt;Last4Digits &lt;span class="token operator"&gt;==&lt;/span&gt; args&lt;span class="token punctuation"&gt;.&lt;/span&gt;Card&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;if&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;card &lt;span class="token operator"&gt;==&lt;/span&gt; &lt;span class="token keyword"&gt;null&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token keyword"&gt;throw&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
$&lt;span class="token string"&gt;"Card ending in {args.Card} not found in your profile."&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;


    &lt;span class="token keyword"&gt;var&lt;/span&gt; totalPaid &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; PaymentService&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;CreatePaymentForDebtsWithCardAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
        paySession&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        renter&lt;span class="token punctuation"&gt;.&lt;/span&gt;Id&lt;span class="token operator"&gt;!&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        args&lt;span class="token punctuation"&gt;.&lt;/span&gt;DebtItemIds&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        card&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        args&lt;span class="token punctuation"&gt;.&lt;/span&gt;PaymentMethod&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        cts&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;return&lt;/span&gt; $&lt;span class="token string"&gt;"Charged {totalPaid:C2} to {card.Type}"&lt;/span&gt; &lt;span class="token operator"&gt;+&lt;/span&gt;
    $&lt;span class="token string"&gt;" ending in {card.Last4Digits}."&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;Note that we do some basic validation, then we call the &lt;code&gt;CreatePaymentForDebtsWithCardAsync()&lt;/code&gt;method to perform the actual operation. It is also fun that we can just return a message string to give the model an idea about what the result of the action is. &lt;/p&gt;&lt;p&gt;Inside &lt;code&gt;CreatePaymentForDebtsWithCardAsync(),&lt;/code&gt;we also verify that the debts we are asked to pay are associated with the current renter; we may have to apply additional logic, etc. The concept is that we assume the model is &lt;em&gt;not&lt;/em&gt;&amp;nbsp;to be trusted, so we need to carefully validate the input and use our code to verify that everything is fine.&lt;/p&gt;&lt;h1&gt;Summary&lt;/h1&gt;&lt;p&gt;This post has gone on for quite a while, so I think we&amp;rsquo;ll stop here. As a reminder, the &lt;a href="https://github.com/ayende/samples.properties"&gt;PropertySphere&lt;/a&gt;&amp;nbsp;sample application code is available. And if you are one of those who prefer videos to text, you can &lt;a href="https://www.youtube.com/watch?v=XOdXDNIGzxE"&gt;watch the video here&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In &lt;a href="https://ayende.com/blog/203622-B/propertysphere-bot-understanding-images?key=889433c1a0cb4633b096390e184c9159"&gt;the next post&lt;/a&gt;, I&amp;rsquo;m going to show you how we can make the bot even smarter by adding visual recognition to the mix.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203621-b/propertyspheres-intelligent-telegram-bot?Key=1802d1b2-62ad-4016-9d1f-cac2ebf1acff</link><guid>http://ayende.org/203621-b/propertyspheres-intelligent-telegram-bot?Key=1802d1b2-62ad-4016-9d1f-cac2ebf1acff</guid><pubDate>Mon, 22 Dec 2025 12:00:00 GMT</pubDate></item><item><title>PropertySphere sample application</title><description>&lt;p&gt;This post introduces the &lt;a href="https://github.com/ayende/samples.properties"&gt;PropertySphere&lt;/a&gt;&amp;nbsp;sample application. I&amp;rsquo;m going to talk about some aspects of the sample application in this post, then in the next one, we will introduce AI into the mix.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You can also &lt;a href="https://www.youtube.com/watch?v=XOdXDNIGzxE"&gt;watch me walk through the entire application in this video&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This is based on a real-world scenario from a customer. One of the nicest things about AI being so easy to use is that I can generate throwaway code for a conversation with a customer that is actually a full-blown application.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="https://github.com/ayende/samples.properties"&gt;The full code for the sample application is available on GitHub&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Here is the application dashboard, so you can get some idea about what this is all about:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/vkRtc5XjRQjjIvDAGgqZ-Q.png"/&gt;&lt;/p&gt;&lt;p&gt;The idea is that you have Properties (apartment buildings), which have Units (apartments), which you then Lease to Renters. Note the capitalized words in the last sentence, those are the key domain entities that we work with.&lt;/p&gt;&lt;p&gt;Note that this dashboard shows quite a lot of data from many different places in the system. The map defines which properties we are looking at. It&amp;rsquo;s not just a static map, it is interactive. You can zoom in on a region to apply a spatial filter to the data in the dashboard. &lt;/p&gt;&lt;p&gt;Let&amp;rsquo;s take a closer look at what we are doing here. I&amp;rsquo;m primarily a backend guy, so I&amp;rsquo;m ignoring what the front end is doing to focus on the actual behavior of the system.&lt;/p&gt;&lt;p&gt;Here is what a typical endpoint will return for the dashboard:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token function"&gt;HttpGet&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"status/{status}"&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;
&lt;span class="token keyword"&gt;public&lt;/span&gt; IActionResult &lt;span class="token function"&gt;GetByStatus&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;string status&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;FromQuery&lt;span class="token punctuation"&gt;]&lt;/span&gt; string&lt;span class="token operator"&gt;?&lt;/span&gt; boundsWkt&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    &lt;span class="token keyword"&gt;var&lt;/span&gt; docQuery &lt;span class="token operator"&gt;=&lt;/span&gt; _session
&lt;span class="token punctuation"&gt;.&lt;/span&gt;Query&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;ServiceRequests_ByStatusAndLocation&lt;span class="token punctuation"&gt;.&lt;/span&gt;Result&lt;span class="token punctuation"&gt;,&lt;/span&gt;
 ServiceRequests_ByStatusAndLocation&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Where&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;x&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Status &lt;span class="token operator"&gt;==&lt;/span&gt; status&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OrderByDescending&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;x&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; x&lt;span class="token punctuation"&gt;.&lt;/span&gt;OpenedAt&lt;span class="token punctuation"&gt;)&lt;/span&gt;
        &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Take&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token number"&gt;10&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;if&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token operator"&gt;!&lt;/span&gt;string&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;boundsWkt&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        docQuery &lt;span class="token operator"&gt;=&lt;/span&gt; docQuery&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Spatial&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;
&lt;span class="token parameter"&gt;x&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Location&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token parameter"&gt;spatial&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; spatial&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Within&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;boundsWkt&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;


    &lt;span class="token keyword"&gt;var&lt;/span&gt; results &lt;span class="token operator"&gt;=&lt;/span&gt; docQuery&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;x&lt;/span&gt; &lt;span class="token operator"&gt;=&gt;&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Id&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Status&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;OpenedAt&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;UnitId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;PropertyId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Type&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        x&lt;span class="token punctuation"&gt;.&lt;/span&gt;Description&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        PropertyName &lt;span class="token operator"&gt;=&lt;/span&gt; RavenQuery&lt;span class="token punctuation"&gt;.&lt;/span&gt;Load&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Property&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;x&lt;span class="token punctuation"&gt;.&lt;/span&gt;PropertyId&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;Name&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        UnitNumber &lt;span class="token operator"&gt;=&lt;/span&gt; RavenQuery&lt;span class="token punctuation"&gt;.&lt;/span&gt;Load&lt;span class="token operator"&gt;&amp;lt;&lt;/span&gt;Unit&lt;span class="token operator"&gt;&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;x&lt;span class="token punctuation"&gt;.&lt;/span&gt;UnitId&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;UnitNumber
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToList&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


    &lt;span class="token keyword"&gt;return&lt;/span&gt; &lt;span class="token function"&gt;Ok&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;results&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;We use a static index (we&amp;rsquo;ll see exactly why in a bit) to query for all the service requests by status and location, and then we project data from the document, including &lt;em&gt;related&lt;/em&gt;&amp;nbsp;document properties (the last two lines in the &lt;code&gt;Select&lt;/code&gt;&amp;nbsp;call).&lt;/p&gt;&lt;p&gt;A ServiceRequest doesn&amp;rsquo;t have a location, it gets that from its associated Property, so during indexing, we pull that from the relevant Property, like so:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;Map&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; requests &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt;
    from sr &lt;span class="token keyword"&gt;in&lt;/span&gt; requests
    let property &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;LoadDocument&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;Property&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;PropertyId&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    select &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;Result&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Id&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Id&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Status&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Status&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;OpenedAt&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;OpenedAt&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;UnitId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;UnitId&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;PropertyId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;PropertyId&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Type&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Type&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Description&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;sr&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Description&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Location&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt;  &lt;span class="token class-name"&gt;CreateSpatialField&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;property&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Latitude&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;property&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Longitude&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;You can see how we load the related Property and then index its location for the spatial query (last line).&lt;/p&gt;&lt;p&gt;You can see more interesting features when you drill down to the Unit page, where both its current status and its utility usage are displayed. That is handled using RavenDB&amp;rsquo;s time series feature, and then projected to a nice view on the frontend:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/k21t_u3JYDeXsjc-d33YaQ.png"/&gt;&lt;/p&gt;&lt;p&gt;In the backend, this is handled using the following action call:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token class-name"&gt;HttpGet&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"unit/{*unitId}"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;
public &lt;span class="token class-name"&gt;IActionResult&lt;/span&gt; &lt;span class="token class-name"&gt;GetUtilityUsage&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;string unitId&lt;span class="token punctuation"&gt;,&lt;/span&gt; 
&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token class-name"&gt;FromQuery&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; from&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token class-name"&gt;FromQuery&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; to&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; unit &lt;span class="token operator"&gt;=&lt;/span&gt; _session&lt;span class="token punctuation"&gt;.&lt;/span&gt;Load&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;Unit&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;unitId&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token keyword"&gt;if&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;unit &lt;span class="token operator"&gt;==&lt;/span&gt; &lt;span class="token keyword"&gt;null&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token keyword"&gt;return&lt;/span&gt; &lt;span class="token class-name"&gt;NotFound&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Unit not found"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;var&lt;/span&gt; fromDate &lt;span class="token operator"&gt;=&lt;/span&gt; from &lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime.Today.AddMonths&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token operator"&gt;-&lt;/span&gt;&lt;span class="token number"&gt;3&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; toDate &lt;span class="token operator"&gt;=&lt;/span&gt; to &lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime.Today&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;var&lt;/span&gt; result &lt;span class="token operator"&gt;=&lt;/span&gt; _session&lt;span class="token punctuation"&gt;.&lt;/span&gt;Query&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;Unit&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Where&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;u &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;u&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Id&lt;/span&gt; &lt;span class="token operator"&gt;==&lt;/span&gt; unitId&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;u &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;PowerUsage&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;RavenQuery.TimeSeries&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;u&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Power"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Where&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;ts &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ts&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;&gt;=&lt;/span&gt; fromDate &lt;span class="token operator"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ts&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;&amp;lt;=&lt;/span&gt; toDate&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;GroupBy&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;g &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;g&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Hours&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token number"&gt;1&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;g &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;g&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Sum&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToList&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;WaterUsage&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;RavenQuery.TimeSeries&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;u&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;"Water"&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Where&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;ts &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ts&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;&gt;=&lt;/span&gt; fromDate &lt;span class="token operator"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;ts&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;&amp;lt;=&lt;/span&gt; toDate&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;GroupBy&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;g &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;g&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Hours&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token number"&gt;1&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;g &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;g&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Sum&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
            &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToList&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
    &lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;


&lt;span class="token keyword"&gt;return&lt;/span&gt; &lt;span class="token class-name"&gt;Ok&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token keyword"&gt;new&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    &lt;span class="token class-name"&gt;UnitId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; unitId&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;UnitNumber&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;unit&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;UnitNumber&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;From&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; fromDate&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;To&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; toDate&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;PowerUsage&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; result&lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;PowerUsage&lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;Results&lt;span class="token operator"&gt;?&lt;/span&gt;
&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;r &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;UsageDataPoint&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;r&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;From&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Value&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;r&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Sum&lt;/span&gt;&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token number"&gt;0&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToList&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt; &lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;List&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;UsageDataPoint&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token class-name"&gt;WaterUsage&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; result&lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;WaterUsage&lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;Results&lt;span class="token operator"&gt;?&lt;/span&gt;
&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Select&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;r &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&gt;&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;UsageDataPoint&lt;/span&gt;
    &lt;span class="token punctuation"&gt;{&lt;/span&gt;
        &lt;span class="token class-name"&gt;Timestamp&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;r&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;From&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
        &lt;span class="token class-name"&gt;Value&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;r&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Sum&lt;/span&gt;&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token number"&gt;0&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;
    &lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;ToList&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt; &lt;span class="token operator"&gt;?&lt;/span&gt;&lt;span class="token operator"&gt;?&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;List&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;UsageDataPoint&lt;/span&gt;&lt;span class="token punctuation"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;As you can see, we run a single query to fetch data from multiple time series, which allows us to render this page.&lt;/p&gt;&lt;p&gt;By now, I think you have a pretty good grasp of what the application is about. So get ready for &lt;a href="https://ayende.com/blog/203621-B/propertyspheres-intelligent-telegram-bot?key=1802d1b262ad40169d1fcac2ebf1acff"&gt;the &lt;/a&gt;&lt;em&gt;&lt;a href="https://ayende.com/blog/203621-B/propertyspheres-intelligent-telegram-bot?key=1802d1b262ad40169d1fcac2ebf1acff"&gt;next &lt;/a&gt;&lt;/em&gt;&lt;a href="https://ayende.com/blog/203621-B/propertyspheres-intelligent-telegram-bot?key=1802d1b262ad40169d1fcac2ebf1acff"&gt;post&lt;/a&gt;, where I will talk about how to add AI capabilities to the mix.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203620-b/propertysphere-sample-application?Key=2ab9814a-35aa-48ee-86f3-f3f9b1accd57</link><guid>http://ayende.org/203620-b/propertysphere-sample-application?Key=2ab9814a-35aa-48ee-86f3-f3f9b1accd57</guid><pubDate>Fri, 19 Dec 2025 12:00:00 GMT</pubDate></item><item><title>RavenDB Kubernetes Operator </title><description>&lt;p&gt;I&amp;rsquo;m happy to announce the official release of the RavenDB Kubernetes Operator. &lt;/p&gt;&lt;p&gt;As organizations use Kubernetes for more and more parts of their infrastructure, the complexity of deploying databases in such an environment is quite a challenge. For RavenDB, you need to handle certificates, persistence, and upgrades, and it is easy for that to become a bottleneck. This release bridges the gap between RavenDB&amp;rsquo;s ease of use and the declarative power of Kubernetes.&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/f7WrI1kJoEBQT5keUwCnQQ.png"/&gt;&lt;/p&gt;&lt;p&gt;If you are new to the concept, think of an operator as software that acts like a Site Reliability Engineer (SRE).&amp;nbsp;Kubernetes is excellent at managing stateless applications, but databases require specific knowledge to manage correctly (e.g., &amp;quot;Don&amp;#39;t upgrade all nodes at once&amp;quot; or &amp;quot;Ensure the leader is stable before restarting&amp;quot;).&lt;/p&gt;&lt;p&gt;The RavenDB Operator extends the Kubernetes API. It allows you to define &lt;em&gt;what&lt;/em&gt;&amp;nbsp;you want your cluster to look like (the &amp;quot;Manifest&amp;quot;), and the Operator works tirelessly in the background to make sure your infrastructure matches that state.&lt;/p&gt;&lt;h3&gt;Why This Matters&lt;/h3&gt;&lt;p&gt;Previously, deploying a secure, clustered RavenDB instance on K8s required manual configuration of StatefulSets, Services, and complex TLS certificate chains.&lt;/p&gt;&lt;p&gt;With the RavenDB Kubernetes Operator, everything is driven by a single custom resource: &lt;code&gt;RavenDBCluster&lt;/code&gt;. You provide the specs, and the Operator handles the heavy lifting, ensuring your deployments are fully reproducible, secure, and declarative.&lt;/p&gt;&lt;p&gt;Here is what the Operator brings to the table:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Automated Security &amp;amp; Certificate Management: Whether you are using Let&amp;rsquo;s Encrypt or Self-Signed certificates, the Operator handles bootstrapping, distribution, and rotation.For the Operator&amp;rsquo;s own webhook certificate, the Operator uses cert-manager behind the scenes, since that is not exposed externally.&lt;/li&gt;&lt;li&gt;Safe Rolling Upgrades: Database upgrades can be scary. The Operator orchestrates upgrades node-by-node, using safety gates to ensure the cluster is healthy and data is safe before moving to the next node. If a gate fails, the upgrade stops automatically.&lt;/li&gt;&lt;li&gt;Flexible External Access: Exposing a database outside K8s is often a networking headache. We&amp;rsquo;ve added dedicated support for AWS NLB, Azure Load Balancer, HAProxy, Traefik, and NGINX, giving you production-ready access strategies out of the box.&lt;/li&gt;&lt;li&gt;Storage Orchestration: Declarative control over your data, logs, and audit volumes, supporting local paths, AWS EBS, and Azure Disks.&lt;/li&gt;&lt;li&gt;One-Click Deploy: Using our official Helm chart, you can spin up a fully operational cluster in minutes.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The Operator is available now via Helm and works on EKS, AKS, Kind, Minikube, and Kubeadm clusters.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;ArtifactHub (Helm Chart):&lt;a href="https://artifacthub.io/packages/helm/ravendb-operator/ravendb-operator"&gt;Get the Chart&lt;/a&gt;&lt;/li&gt;&lt;li&gt;GitHub Repository:&lt;a href="https://github.com/ravendb/ravendb-operator"&gt;View Source &amp;amp; Examples&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Quickstart Guide:&lt;a href="https://www.google.com/search?q=https://github.com/ravendb/ravendb-operator%3Ftab%3Dreadme-ov-file%23installation"&gt;Read the Docs&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We look forward to seeing what you build with RavenDB on Kubernetes!&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203587-b/ravendb-kubernetes-operator?Key=1d5af4d7-9a6e-42a5-84a2-5d446342e2bb</link><guid>http://ayende.org/203587-b/ravendb-kubernetes-operator?Key=1d5af4d7-9a6e-42a5-84a2-5d446342e2bb</guid><pubDate>Mon, 15 Dec 2025 12:00:00 GMT</pubDate></item><item><title>Choosing "naked" vms or Kubernetes for hosting databases in the cloud</title><description>&lt;p&gt;We are a database company, and many of our customers and users are running in the cloud. Fairly often, we field questions about the recommended deployment pattern for RavenDB.&lt;/p&gt;&lt;p&gt;Given the&amp;hellip; rich landscape of DevOps options, RavenDB supports all sorts of deployment models:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Embedded in your application&lt;/li&gt;&lt;li&gt;Physical hardware (from a Raspberry Pi to massive servers)&lt;/li&gt;&lt;li&gt;Virtual machines in the cloud&lt;/li&gt;&lt;li&gt;Docker&lt;/li&gt;&lt;li&gt;AWS / Azure marketplaces&lt;/li&gt;&lt;li&gt;Kubernetes&lt;/li&gt;&lt;li&gt;Ansible&lt;/li&gt;&lt;li&gt;Terraform&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As well as some pretty fancy permutations of the above in every shape and form.&lt;/p&gt;&lt;p&gt;With so many choices, the question is: what do you &lt;em&gt;recommend?&lt;/em&gt;&amp;nbsp;In particular, we were recently asked about deployment to a &amp;ldquo;naked machine&amp;rdquo; in the cloud versus using Kubernetes. The core requirements are to ensure high performance and high availability. &lt;/p&gt;&lt;p&gt;Our short answer is almost always: Best to go with direct VMs and skip Kubernetes for RavenDB.&lt;/p&gt;&lt;p&gt;While Kubernetes has revolutionized the deployment of stateless microservices, deploying stateful applications, particularly databases, on K8s introduces significant complexities that often outweigh the benefits, especially when performance and operational simplicity are paramount.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A great quote in the DevOps world is &amp;ldquo;&lt;a href="https://cloudscaling.com/blog/cloud-computing/the-history-of-pets-vs-cattle/"&gt;cattle, not pets&lt;/a&gt;&amp;rdquo;, in reference to how you should manage your servers. That works great if you are dealing with stateless services. But when it comes to data management, your databases are &lt;em&gt;cherished&lt;/em&gt;&amp;nbsp;pets, and you should treat them as such. &lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;The Operational Complexity of Kubernetes for Stateful Systems&lt;/h2&gt;&lt;p&gt;Using an orchestration layer like Kubernetes complicates the operational management of persistent state. While K8s provides tools for stateful workloads, they require a deep understanding of storage classes, Persistent Volumes (PVs), and Persistent Volume Claims (PVCs).&lt;/p&gt;&lt;p&gt;Consider a common, simple maintenance task: Changing a VM&amp;#39;s disk type or size.&lt;/p&gt;&lt;p&gt;As a VM, this is typically a very easy operation and can be done with no downtime.The process is straightforward, well-documented, and often takes minutes.&lt;/p&gt;&lt;p&gt;For K8s, this becomes a significantly more complex task. You have to go deep into Kubernetes storage primitives to figure out how to properly migrate the data to a new disk specification. &lt;/p&gt;&lt;p&gt;There is an &lt;code&gt;allowVolumeExpansion: true&lt;/code&gt;&amp;nbsp;option that &lt;em&gt;should&lt;/em&gt;&amp;nbsp;make it work, but the details matter, and for databases, that is usually something DBAs are really careful about.&lt;/p&gt;&lt;p&gt;Databases tend to &lt;em&gt;care&lt;/em&gt;&amp;nbsp;about their disk. So what happens if we don&amp;rsquo;t want to just change the size of the disk, but also its &lt;em&gt;type?&lt;/em&gt;&amp;nbsp;Such as moving from Standard to Premium. Doing that using VMs is as simple as changing the size. You may need to detach, change, and reattach the disk, but that is a well-trodden path.&lt;/p&gt;&lt;p&gt;In Kubernetes, you need to run a migration, delete the StatefulSets, make the configuration change, and reapply (crossing your fingers and hoping everything works).&lt;/p&gt;&lt;h2&gt;Database nodes are not homogeneous&lt;/h2&gt;&lt;p&gt;Databases running in a cluster configuration often require granular control over node upgrades and maintenance. I may want to designate a node as &amp;ldquo;this one is doing backups&amp;rdquo;, so it needs a bigger disk. Easy to do if each node is a dedicated VM, but much harder in practice inside K8s.&lt;/p&gt;&lt;p&gt;A recent example we ran into is controlling the upgrade process of a cluster. As any database administrator can tell you, upgrades are something you approach cautiously. RavenDB has &lt;em&gt;great&lt;/em&gt;&amp;nbsp;support for running cross-version clusters.&lt;/p&gt;&lt;p&gt;In other words, take a node in your cluster, upgrade that to an updated version (including across major versions!), and it will just work. That allows you to dip your toes into the waters with a single node, instead of doing a hard switch to the new version.&lt;/p&gt;&lt;p&gt;In a VM environment: Upgrading a single node in a RavenDB cluster is a simple, controlled process. You stop the database on the VM, perform the upgrade (often just replacing binaries), start the database, and allow the cluster to heal and synchronize. This allows you to manage the cluster&amp;#39;s rolling upgrades with precision.&lt;/p&gt;&lt;p&gt;In K8s: Performing a targeted upgrade on just one node of the cluster is &lt;em&gt;hard&lt;/em&gt;. The K8s deployment model (StatefulSets) is designed to manage homogeneous replicas. While you can use features like &amp;quot;on delete&amp;quot; update strategy, blue/green deployments, or canary releases, they add layers of abstraction and complexity that are necessary for stateless services but actively harmful for stateful systems. &lt;/p&gt;&lt;h1&gt;Summary&lt;/h1&gt;&lt;p&gt;For mission-critical database infrastructure where high performance, high availability, and operational simplicity are non-negotiable, the added layer of abstraction introduced by Kubernetes for managing persistence often introduces more friction than value.&lt;/p&gt;&lt;p&gt;While Kubernetes is an excellent platform for stateless services, we strongly recommend deploying RavenDB directly on dedicated Virtual Machines. This provides a cleaner operational surface, simpler maintenance procedures, and more direct control over the underlying resources&amp;mdash;all critical factors for a stateful, high-performance database cluster.&lt;/p&gt;&lt;p&gt;Remember, your database nodes are &lt;em&gt;cherished&lt;/em&gt;&amp;nbsp;pets, don&amp;rsquo;t make them sleep in the barn with the cattle.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203555-a/choosing-naked-vms-or-kubernetes-for-hosting-databases-in-the-cloud?Key=12c9738a-271c-40a8-97c1-6ad4d1cfe089</link><guid>http://ayende.org/203555-a/choosing-naked-vms-or-kubernetes-for-hosting-databases-in-the-cloud?Key=12c9738a-271c-40a8-97c1-6ad4d1cfe089</guid><pubDate>Thu, 11 Dec 2025 12:00:00 GMT</pubDate></item><item><title>Implementing Agentic Reminders in RavenDB</title><description>&lt;p&gt;A really interesting problem for developers building agentic systems is moving away from chatting with the AI model. For example, consider the following conversation:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/kigqhoDT1Wih1A8CpRXj9A.png"/&gt;&lt;/p&gt;&lt;p&gt;This is a pretty simple scenario where we need to actually step out of the chat and do something else. This seems like an obvious request, right? But it turns out to be a bit complex to build.&lt;/p&gt;&lt;p&gt;The reason for that is simple. AI models don&amp;rsquo;t actually behave like you would expect them to if your usage is primarily as a chat interface. Here is a typical invocation of a model in code:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-csharp'&gt;&lt;code class='line-numbers language-csharp'&gt;&lt;span class="token keyword"&gt;class&lt;/span&gt; &lt;span class="token class-name"&gt;MessageTuple&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;NamedTuple&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt;
    role&lt;span class="token punctuation"&gt;:&lt;/span&gt; &lt;span class="token class-name"&gt;str&lt;/span&gt;
    content&lt;span class="token punctuation"&gt;:&lt;/span&gt; str
&lt;p&gt;&lt;span class="token return-type class-name"&gt;def&lt;/span&gt; &lt;span class="token function"&gt;call_model&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span class="token named-parameter punctuation"&gt;message_history&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt; List&lt;span class="token punctuation"&gt;[&lt;/span&gt;MessageTuple&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token named-parameter punctuation"&gt;tools&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt; List&lt;span class="token punctuation"&gt;[&lt;/span&gt;Callable&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; None&lt;br /&gt;
&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;:&lt;/span&gt;&lt;br /&gt;
pass # redacted&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;In other words, it is the responsibility of the caller to keep track of the conversation and send the &lt;em&gt;entire&lt;/em&gt; conversation to the agent on each round. Here is what this looks like in code:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-json'&gt;&lt;code class='line-numbers language-json'&gt;conversation_history = &lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;role&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;user&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;content&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;When do I get my anniversary gift?&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;role&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;agent&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;content&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;Based on our records, your two-year anniversary is in three days. This milestone means you're eligible for a gift card as part of our company's recognition program.\nOur policy awards a $100 gift card for each year of service. Since you've completed two years, a $200 gift card will be sent to you via SMS on October 1, 2025.&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;role&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;user&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token property"&gt;&amp;quot;content&amp;quot;&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;Remind me to double check I got that in a week&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;Let’s assume that we have a tool call for setting up reminders for users. In RavenDB, this looks like the screenshot below (&lt;a href="https://docs.ravendb.net/7.1/ai-integration/ai-agents/creating-ai-agents/creating-ai-agents_api#action-tools"&gt;more on agentic actions in RavenDB here&lt;/a&gt;):&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/uVtTZ17MGY_Vx9AVw05Y_Q.png"/&gt;&lt;/p&gt;&lt;p&gt;And in the backend, we have the following code:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-dart'&gt;&lt;code class='line-numbers language-dart'&gt;&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Handle&lt;/span&gt;&lt;span class="token generics"&gt;&lt;span class="token punctuation"&gt;&amp;lt;&lt;/span&gt;&lt;span class="token class-name"&gt;CreateReminderArgs&lt;/span&gt;&lt;span class="token punctuation"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;&amp;quot;CreateReminder&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; &lt;span class="token keyword"&gt;async&lt;/span&gt; &lt;span class="token punctuation"&gt;(&lt;/span&gt;args&lt;span class="token punctuation"&gt;)&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt;&lt;span class="token operator"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
using &lt;span class="token keyword"&gt;var&lt;/span&gt; session &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;OpenAsyncSession&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; at &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;DateTime.Parse&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;args&lt;span class="token punctuation"&gt;.&lt;/span&gt;at&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; reminder &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;new&lt;/span&gt; &lt;span class="token class-name"&gt;Reminder&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="token class-name"&gt;EmployeeId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;request&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;EmployeeId&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token class-name"&gt;ConversationId&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Id&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token class-name"&gt;Message&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; args&lt;span class="token punctuation"&gt;.&lt;/span&gt;msg&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;StoreAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;reminder&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;Advanced.GetMetadataFor&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;reminder&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;[&lt;/span&gt;&lt;span class="token string-literal"&gt;&lt;span class="token string"&gt;&amp;quot;@refresh&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="token punctuation"&gt;]&lt;/span&gt; &lt;span class="token operator"&gt;=&lt;/span&gt; at&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token class-name"&gt;&lt;span class="token namespace"&gt;session&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;/span&gt;SaveChangesAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;span class=&amp;quot;token keyword&amp;quot;&amp;gt;return&amp;lt;/span&amp;gt; $&amp;lt;span class=&amp;quot;token string-literal&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;token string&amp;quot;&amp;gt;&amp;quot;Reminder set for {at} {reminder.Id}&amp;quot;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span class=&amp;quot;token punctuation&amp;quot;&amp;gt;;&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;This code uses several of RavenDB’s features to perform its task. First we have the conversation handler, which is the backend handling for the tool call we just saw. Next we have the use of the &lt;code&gt;@refresh &lt;/code&gt;feature of RavenDB. &lt;a href="https://ayende.com/blog/203203-B/scheduling-with-ravendb"&gt;I recently posted about how you can use this feature for scheduling&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In short, we set up a &lt;a href="https://docs.ravendb.net/6.2/client-api/data-subscriptions/what-are-data-subscriptions/"&gt;RavenDB Subscription&lt;/a&gt; Task to be called when those reminders should be raised. Here is what the subscription looks like:&lt;/p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;from Reminders &lt;span class="token keyword"&gt;as&lt;/span&gt; r&lt;br /&gt;
where r&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token string"&gt;'@metadata'&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token string"&gt;'@refresh'&lt;/span&gt; &lt;span class="token operator"&gt;!=&lt;/span&gt; &lt;span class="token keyword"&gt;null&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;p&gt;And here is the client code to actually handle it:&lt;/p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-javascript'&gt;&lt;code class='line-numbers language-javascript'&gt;&lt;span class="token keyword"&gt;async&lt;/span&gt; Task &lt;span class="token function"&gt;HandleReminder&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token parameter"&gt;Reminder reminder&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; conversation &lt;span class="token operator"&gt;=&lt;/span&gt; _documentStore&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token constant"&gt;AI&lt;/span&gt;&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;Conversation&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span class="token literal-property property"&gt;agentId&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token string"&gt;&amp;quot;smartest-agent&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
reminder&lt;span class="token punctuation"&gt;.&lt;/span&gt;ConversationId&lt;span class="token punctuation"&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span class="token literal-property property"&gt;creationOptions&lt;/span&gt;&lt;span class="token operator"&gt;:&lt;/span&gt; &lt;span class="token keyword"&gt;null&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;AddArtificialActionWithResponse&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span class="token string"&gt;&amp;quot;GetRaisedReminders&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;,&lt;/span&gt; reminder&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;var&lt;/span&gt; result &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token keyword"&gt;await&lt;/span&gt; conversation&lt;span class="token punctuation"&gt;.&lt;/span&gt;&lt;span class="token function"&gt;RunAsync&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token keyword"&gt;await&lt;/span&gt; &lt;span class="token function"&gt;MessageUser&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;conversation&lt;span class="token punctuation"&gt;,&lt;/span&gt; result&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;p&gt;The question now is, what should we &lt;em&gt;do&lt;/em&gt; with the reminder?&lt;/p&gt;&lt;p&gt;Going back to the top of this post, we know that we need to add the reminder to the conversation. The problem is that this isn’t part of the actual model of the conversation. This is neither a user prompt nor a model answer. How do we deal with this?&lt;/p&gt;&lt;p&gt;We use a really elegant approach here: we inject an artificial tool call into the conversation history. This makes the model think that it checked for reminders and received one in return, even though this happened outside the chat. This lets the agent respond naturally, as if the reminder were part of the ongoing conversation, preserving the full context.&lt;/p&gt;&lt;p&gt;Finally, since we’re not actively chatting with the user at this point, we need to send a message prompting them to check back on the conversation with the model.&lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;This is a high-level post, meant specifically to give you some ideas about how you can take your agentic systems to a higher level than a simple chat with the model. The reminder example is a pretty straightforward example, but a truly powerful one. It transforms a simple chat into a much more complex interaction model with the AI.&lt;/p&gt;&lt;p&gt;RavenDB’s unique approach of &amp;quot;inserting&amp;quot; a tool call back into the conversation history effectively tells the AI model, &amp;quot;I've checked for reminders and found a reminder for this user.&amp;quot; This allows the agent to handle the reminder within the context of the original conversation, rather than initiating a new one. It also allows the agent to maintain a single, coherent conversational thread with the user, even when the system needs to perform background tasks and re-engage with them later.&lt;/p&gt;&lt;p&gt;You can also use the same infrastructure to create a &lt;em&gt;new&lt;/em&gt; conversation, if that makes sense in your domain, and use the previous conversation as “background material”, so to speak. There is a wide variety of options available to fit your exact scenario.&lt;/p&gt;&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;
</description><link>http://ayende.org/203523-c/implementing-agentic-reminders-in-ravendb?Key=a4ed6127-e4fa-4df6-b2a5-4f17b1792a3b</link><guid>http://ayende.org/203523-c/implementing-agentic-reminders-in-ravendb?Key=a4ed6127-e4fa-4df6-b2a5-4f17b1792a3b</guid><pubDate>Mon, 08 Dec 2025 12:00:00 GMT</pubDate></item><item><title>Recording: Build AI that understands your business</title><description>&lt;p&gt;I gave the following talk at Microsoft Ignite 2025:&lt;/p&gt;&lt;p&gt;Connecting LLMs to your secure, operational database involves complexity, security risks, and hallucinations. This session shows how to build context-aware AI agents directly on your existing data, going from live database to production-ready, secure AI agent in hours. You'll see how to ship personalized experiences that will define the next generation of software. RavenDB's CEO will demonstrate this approach.&lt;/p&gt;&lt;p&gt;&lt;iframe width="1840" height="1035" title="Build AI that understands your business | ODSP1462" src="https://www.youtube.com/embed/CpdCQZzT-Rk" frameborder="0" allowfullscreen="" referrerpolicy="strict-origin-when-cross-origin" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://ayende.org/203491-b/recording-build-ai-that-understands-your-business?Key=c7410eb4-6886-4390-b631-faedd7d7231e</link><guid>http://ayende.org/203491-b/recording-build-ai-that-understands-your-business?Key=c7410eb4-6886-4390-b631-faedd7d7231e</guid><pubDate>Fri, 05 Dec 2025 12:00:00 GMT</pubDate></item><item><title>Recording: From CRUD TO AI – building an intelligent Telegram bot in &lt; 200 lines of code with RavenDB</title><description>&lt;p&gt;Want to see how modern applications handle complexity, scale, and cutting-edge features without becoming unmanageable? In this deep-dive webinar, we move From CRUD to AI Agents, showcasing how RavenDB, a high-performance document database, simplifies the development of a complex Property Management application.&lt;/p&gt;&lt;p&gt;&lt;iframe width="1840" height="1035" title="From CRUD to AI Agents How To Build a Telegram Bot with Vector Search in 200 Lines of Code | RavenDB" src="https://www.youtube.com/embed/XOdXDNIGzxE" frameborder="0" allowfullscreen="" referrerpolicy="strict-origin-when-cross-origin" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://ayende.org/203459-b/recording-from-crud-to-ai-building-an-intelligent-telegram-bot-in-200-lines-of-code-with-ravendb?Key=61bbfd87-8de3-48e7-81a3-6f7fc69d3eb9</link><guid>http://ayende.org/203459-b/recording-from-crud-to-ai-building-an-intelligent-telegram-bot-in-200-lines-of-code-with-ravendb?Key=61bbfd87-8de3-48e7-81a3-6f7fc69d3eb9</guid><pubDate>Tue, 02 Dec 2025 12:00:00 GMT</pubDate></item><item><title>Using multi-staged actions with AI Agents to reduce costs &amp; time</title><description>&lt;p&gt;When building AI Agents, one of the challenges you have to deal with is the sheer amount of data that the agent may need to go through. A natural way to deal with that is &lt;em&gt;not&lt;/em&gt;&amp;nbsp;to hand the information directly to the model, but rather allow it to query for the information as it sees fit.&lt;/p&gt;&lt;p&gt;For example, in the case of a human resource assistant, we may want to expose the employer&amp;rsquo;s policies to the agent, so it can answer questions such as &amp;ldquo;What is the required holiday request time?&amp;rdquo;.&lt;/p&gt;&lt;p&gt;We can do that easily enough using the following agent-query mechanism:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/cCCT52Mq4ifxZuCvxXcHfg.png"/&gt;&lt;/p&gt;&lt;p&gt;If the agent needs to answer a question about a policy, it can use this tool to get the policies and find out what the answer is.&lt;/p&gt;&lt;p&gt;That works if you are a mom &amp;amp; pop shop, but what happens if you happen to be a big organization, with policies on everything from requesting time off to bringing your own device to modern slavery prohibition? Calling this tool is going to give &lt;em&gt;all &lt;/em&gt;those policies to the model? &lt;/p&gt;&lt;p&gt;That is going to be &lt;em&gt;incredibly&lt;/em&gt;&amp;nbsp;expensive, since you have to burn through a lot of tokens that are simply not relevant to the problem at hand.&lt;/p&gt;&lt;p&gt;The next step is &lt;em&gt;not&lt;/em&gt;&amp;nbsp;to return all of the policies and filter them. We can do that using vector search and utilize the model&amp;rsquo;s understanding of the data to help us find exactly what we want.&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/bmTBXHayEHFLnzmm1E8qmA.png"/&gt;&lt;/p&gt;&lt;p&gt;That is much better, but a search for &amp;ldquo;confidentiality contract&amp;rdquo; will get you the Non-Disclosure Agreement as well as the processes for hiring a new employee when their current employer isn&amp;rsquo;t aware they are looking, etc.&lt;/p&gt;&lt;p&gt;That can &lt;em&gt;still&lt;/em&gt;&amp;nbsp;be a lot of text to go through. It isn&amp;rsquo;t as much as &lt;em&gt;everything&lt;/em&gt;, but still a pretty heavy weight. &lt;/p&gt;&lt;p&gt;A nice alternative to this is to break it into two separate operations, as you can see below:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/d4G2hpZReWWKxjY-hGu05g.png"/&gt;&lt;/p&gt;&lt;p&gt;The model will first run the &lt;code&gt;FindPolicies&lt;/code&gt;&amp;nbsp;query to get the list of potential policies. It can then decide, based on their titles, which ones it is actually interested in reading the full text of. &lt;/p&gt;&lt;p&gt;You need to perform two tool calls in this case, but it actually ends up being both faster and cheaper in the end. &lt;/p&gt;&lt;p&gt;This is a surprisingly elegant solution, because it matches roughly how people think. No one is going to read a dozen books cover to cover to answer a question. We continuously narrow our scope until we find enough information to answer. &lt;/p&gt;&lt;p&gt;This approach gives your AI model the same capability to narrowly target the information it needs to answer the user&amp;rsquo;s query efficiently and quickly.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203430-c/using-multi-staged-actions-with-ai-agents-to-reduce-costs-time?Key=38244b26-20b7-4900-9b80-4b105cea21b2</link><guid>http://ayende.org/203430-c/using-multi-staged-actions-with-ai-agents-to-reduce-costs-time?Key=38244b26-20b7-4900-9b80-4b105cea21b2</guid><pubDate>Mon, 17 Nov 2025 12:00:00 GMT</pubDate></item><item><title>Reducing AI context load using actions</title><description>&lt;p&gt;When using an AI model, one of the things that you need to pay attention to is the number of tokens you send to the model. They &lt;em&gt;literally&lt;/em&gt;&amp;nbsp;cost you money, so you have to balance the amount of data you send to the model against how much of it is &lt;em&gt;relevant&lt;/em&gt;&amp;nbsp;to what you want it to do.&lt;/p&gt;&lt;p&gt;That is especially important when you are building generic agents, which may be assigned a &lt;em&gt;bunch&lt;/em&gt;&amp;nbsp;of different tasks. The classic example is the human resources assistant, which may be tasked with checking your vacation days balance or called upon to get the current number of overtime hours that an employee has worked this month.&lt;/p&gt;&lt;p&gt;Let&amp;rsquo;s assume that we want to provide the model with a bit of context. We want to give the model all the recent HR tickets by the current employee. These can range from onboarding tasks to filling out the yearly evaluation, etc. &lt;/p&gt;&lt;p&gt;That sounds like it can give the model a big hand in understanding the state of the employee and what they want. Of course, that assumes the user is going to ask a question related to those issues.&lt;/p&gt;&lt;p&gt;What if they ask about the date of the next bank holiday? If we just unconditionally fed all the data to the model preemptively, that would be:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Quite confusing to the model, since it will have to sift through a lot of irrelevant data.&lt;/li&gt;&lt;li&gt;Pretty expensive, since we&amp;rsquo;re going to send a &lt;em&gt;lot&lt;/em&gt;&amp;nbsp;of data (and pay for it) to the model, which then has to ignore it.&lt;/li&gt;&lt;li&gt;Compounding effect as the user &amp;amp; the model keep the conversation going, with all this unneeded information weighing everything down.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A nice trick that can really help is to &lt;em&gt;not &lt;/em&gt;expose the data directly, but rather provide it to the model as a set of actions it can invoke. In other words, when defining the agent, I don&amp;rsquo;t bother providing it with all the data it needs.&lt;/p&gt;&lt;p&gt;Rather, I provide the model a &lt;em&gt;way to access the data&lt;/em&gt;. Here is what this looks like in RavenDB:&lt;/p&gt;&lt;p&gt;&lt;img src="/blog/Images/IAtwhrjTjb9youuoOByI3Q.png"/&gt;&lt;/p&gt;&lt;p&gt;The agent is provided with a bunch of queries that it can call to find out various interesting details about the current employee. The end result is that the model will invoke those queries to get &lt;em&gt;just&lt;/em&gt;&amp;nbsp;the information it wants.&lt;/p&gt;&lt;p&gt;The overall number of tokens that we are going to consume will be &lt;em&gt;greatly&lt;/em&gt;&amp;nbsp;reduced, while the ability of the model to actually access relevant information is enhanced. We don&amp;rsquo;t need to go through stuff we don&amp;rsquo;t care about, after all. &lt;/p&gt;&lt;p&gt;This approach gives you a very focused model for the task at hand, and it is easy to&amp;nbsp;extend the agent with additional information-retrieval capabilities.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203429-c/reducing-ai-context-load-using-actions?Key=34b3dc56-9e87-445e-972d-348f105e80aa</link><guid>http://ayende.org/203429-c/reducing-ai-context-load-using-actions?Key=34b3dc56-9e87-445e-972d-348f105e80aa</guid><pubDate>Fri, 14 Nov 2025 12:00:00 GMT</pubDate></item><item><title>Using AI Agents parameters outside of the model's scope</title><description>&lt;p&gt;Building an AI Agent in RavenDB is very much like defining a class, you define all the things that it can do, the initial prompt to the AI model, and you specify which parameters the agent requires. Like a class, you can create an instance of an AI agent by starting a new conversation with it. Each conversation is a separate instance of the agent, with different parameters, an initial user prompt, and its own history.&lt;/p&gt;&lt;p&gt;Here is a simple example of a non-trivial agent. For the purpose of this post, I want to focus on the parameters that we pass to the model. &lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-bash'&gt;&lt;code class='line-numbers language-bash'&gt;var agent &lt;span class="token operator"&gt;=&lt;/span&gt; new AiAgentConfiguration&lt;span class="token punctuation"&gt;(&lt;/span&gt;
&lt;span class="token string"&gt;"shopping assistant"&lt;/span&gt;, 
config.ConnectionStringName,
&lt;span class="token string"&gt;"You are an AI agent of an online shop..."&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;
&lt;span class="token punctuation"&gt;{&lt;/span&gt;
    Parameters &lt;span class="token operator"&gt;=&lt;/span&gt;
    &lt;span class="token punctuation"&gt;[&lt;/span&gt; 
       new AiAgentParameter&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"lang"&lt;/span&gt;, 
&lt;span class="token string"&gt;"The language the model should respond with."&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;,
        new AiAgentParameter&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"currency"&lt;/span&gt;, &lt;span class="token string"&gt;"Preferred currency for the user"&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;,
        new AiAgentParameter&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token string"&gt;"customerId"&lt;/span&gt;, null, sendToModel: &lt;span class="token boolean"&gt;false&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;,
    &lt;span class="token punctuation"&gt;]&lt;/span&gt;,
    Queries &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt; /* redacted&lt;span class="token punctuation"&gt;..&lt;/span&gt;. */ &lt;span class="token punctuation"&gt;]&lt;/span&gt;,
    Actions &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token punctuation"&gt;[&lt;/span&gt; /* redacted&lt;span class="token punctuation"&gt;..&lt;/span&gt;. */ &lt;span class="token punctuation"&gt;]&lt;/span&gt;,
&lt;span class="token punctuation"&gt;}&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;As you can see in the configuration, we define the &lt;code&gt;lang&lt;/code&gt;&amp;nbsp;and &lt;code&gt;currency&lt;/code&gt;&amp;nbsp;parameters as standard agent parameters. These are defined with a description for the model and are passed to the model when we create a new conversation. &lt;/p&gt;&lt;p&gt;But what about the &lt;code&gt;customerId&lt;/code&gt;&amp;nbsp;parameter? It is marked as &lt;code&gt;sendToModel: false&lt;/code&gt;. What is the &lt;em&gt;point&lt;/em&gt;&amp;nbsp;of that? To understand this, you need to know a bit more about how RavenDB deals with the model, conversations, and memory.&lt;/p&gt;&lt;p&gt;Each conversation with the model is recorded using a conversation document, and part of this includes the parameters you pass to the conversation when you create it. In this case, we don&amp;rsquo;t need to pass the &lt;code&gt;customerId&lt;/code&gt;&amp;nbsp;parameter to the model; it doesn&amp;rsquo;t hold any meaning for the model and would just waste tokens.&lt;/p&gt;&lt;p&gt;The key is that you can &lt;em&gt;query based &lt;/em&gt;on those parameters. For example, if you want to get all the conversations for a particular customer (to show them their conversation history), you can use the following query:&lt;/p&gt;&lt;p&gt;&lt;hr/&gt;&lt;pre class='line-numbers language-php'&gt;&lt;code class='line-numbers language-php'&gt;from &lt;span class="token string double-quoted-string"&gt;"@conversations"&lt;/span&gt; 
where Parameters&lt;span class="token operator"&gt;.&lt;/span&gt;customerId &lt;span class="token operator"&gt;=&lt;/span&gt; &lt;span class="token variable"&gt;$customerId&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr/&gt;&lt;/p&gt;&lt;p&gt;This is also &lt;em&gt;very&lt;/em&gt;&amp;nbsp;useful when you have data that you genuinely don&amp;rsquo;t want to expose to the model but still want to attach to the conversation. You can set up a query that the model may call to get the most recent orders for a customer, and RavenDB will do that (using &lt;code&gt;customerId&lt;/code&gt;) without letting the model actually see that value. &lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203428-c/using-ai-agents-parameters-outside-of-the-models-scope?Key=9fb498ed-4de8-473a-a3e6-78221253f0c6</link><guid>http://ayende.org/203428-c/using-ai-agents-parameters-outside-of-the-models-scope?Key=9fb498ed-4de8-473a-a3e6-78221253f0c6</guid><pubDate>Wed, 12 Nov 2025 12:00:00 GMT</pubDate></item><item><title>Join RavenDB at Microsoft Ignite Next Week</title><description>&lt;p&gt;&lt;a href="https://ignite.microsoft.com/en-US/sponsors/79e19247-5db8-4153-b5d5-95735931ce16?"&gt;The RavenDB team will be at Microsoft Ignite in San Francisco&lt;/a&gt;&amp;nbsp;next week, as will be yours truly in person &amp;#128578;. We are going to show off RavenDB and its features both new and old. &lt;/p&gt;&lt;p&gt;&lt;a href="https://ignite.microsoft.com/en-US/sessions/ODSP1462"&gt;I&amp;#39;ll be hosting a session demonstrating how to build powerful AI Agents using RavenDB&lt;/a&gt;.I&amp;rsquo;ll show practical examples and the features that make RavenDB suitable for AI-driven applications.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re at Microsoft Ignite or in the San Francisco area next week, I&amp;#39;d like to meet up.Feel free to reach out to discuss RavenDB, AI, architecture or anything else.&lt;/p&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;</description><link>http://ayende.org/203427-c/join-ravendb-at-microsoft-ignite-next-week?Key=d706c934-a477-4509-8b7b-c5430ec0d7f5</link><guid>http://ayende.org/203427-c/join-ravendb-at-microsoft-ignite-next-week?Key=d706c934-a477-4509-8b7b-c5430ec0d7f5</guid><pubDate>Mon, 10 Nov 2025 12:00:00 GMT</pubDate></item><item><title>RavenDB's new offices</title><description>&lt;p&gt;RavenDB Ltd (formerly Hibernating Rhinos) has been around for quite some time!In its current form, we've been building the RavenDB database for over 15 years now.In late 2010, we officially moved into our first real offices.&lt;/p&gt;
&lt;p&gt;Our first place was a small second-story office space deep in the industrial section, a bit out of the way, but it served us incredibly well until we grew and needed more space.Then we grew again, and again, and again!Last month, we moved offices yet again.&lt;/p&gt;
&lt;p&gt;This new location represents our fifth office, with each relocation necessitated by our growth exceeding the capacity of the previous premises.&lt;/p&gt;
&lt;p&gt;If you ever pass by Hadera, where our offices now proudly reside, you'll spot a big sign as you enter the city!&lt;/p&gt;
&lt;p&gt;&lt;img src="/blog/Images/trLAGZy5Ge7pyfGBQDomtA.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;You can also see how it looks like from the inside:&lt;/p&gt;
&lt;p&gt;&lt;iframe title="Welcome to Our New Office Space at the RavenDB Headquarters in Hadera, Israel | RavenDB" src="https://www.youtube.com/embed/XVsz6hQdpOA" width="640" height="480" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;/p&gt;
</description><link>http://ayende.org/203395-c/ravendbs-new-offices?Key=9ecab156-ca92-4011-9eac-86218105d966</link><guid>http://ayende.org/203395-c/ravendbs-new-offices?Key=9ecab156-ca92-4011-9eac-86218105d966</guid><pubDate>Thu, 23 Oct 2025 12:00:00 GMT</pubDate></item></channel></rss>