<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vivek Agrawal on Medium]]></title>
        <description><![CDATA[Stories by Vivek Agrawal on Medium]]></description>
        <link>https://medium.com/@vkweb?source=rss-831b54c52c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*o5k30HwnMKSCwteBUxiCOg.png</url>
            <title>Stories by Vivek Agrawal on Medium</title>
            <link>https://medium.com/@vkweb?source=rss-831b54c52c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:54:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vkweb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Started with an AI agent, now doing a thing that won’t scale — my startup journey so far]]></title>
            <link>https://medium.com/@vkweb/started-with-an-ai-agent-now-doing-a-thing-that-wont-scale-my-startup-journey-so-far-49a053f01f8c?source=rss-831b54c52c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/49a053f01f8c</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[founders]]></category>
            <category><![CDATA[founder-stories]]></category>
            <category><![CDATA[ycombinator]]></category>
            <dc:creator><![CDATA[Vivek Agrawal]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 15:39:36 GMT</pubDate>
            <atom:updated>2024-08-31T18:17:10.720Z</atom:updated>
            <content:encoded><![CDATA[<h3>Started with an AI agent, now doing a thing that won’t scale — my startup journey so far</h3><p>This article talks about my bootstrapped startup journey so far. You will get to know lots about web AI agents, the importance of reaching users as early as possible and see how &amp; why I pivoted to do things that won’t scale.</p><h3>Idea</h3><p>I had a startup idea around 12 months back. It was somewhere between August 2023. I was working as a contract full-stack engineer at a Google.org funded non-profit — <a href="https://learningequality.org/">Learning Equality</a>.</p><p>I heard about AutoGPT in one of Sandeep Maheshwari’s AI videos. I curiously looked into AutoGPT’s GitHub. I cloned and ran it locally using my OpenAI API key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJ4zCALBk5iFbJOoAx2i9g.gif" /><figcaption>AutoGPT navigating to a GitHub repo and reading the webpage</figcaption></figure><p>AutoGPT at that time was an AI agent that would take a natural language instruction and step-by-step it would execute that instruction.</p><p>For example, if you said AutoGPT to “search for flights from Mumbai to SF” then AutoGPT would open a browser, then navigate to Google.com, search for flights by filling up the form, parse the results from the webpage and finally return it to the command line.</p><p>AutoGPT worked by prompting GPT-4. It would first make a step by step plan and then execute each step by giving GPT-4 a list of available commands it could execute to complete the step.</p><p>At Learning Equality, we were doing manual QA testing of our web app using Gherkin stories. A Gherkin story is a natural language description of how a feature should work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vvtJzBuvSMmdh-jW37snJQ.png" /><figcaption>Gherkin story for one of the feature of Learning Equality’s Studio web app</figcaption></figure><p>I thought to myself, an AI agent should be able to read this Gherkin story and intelligently perform the steps.</p><p>An idea for my startup was born.</p><p>An AI agent that can automate manual QA testing.</p><h3>Digging into web AI agents</h3><p>I knew nothing about AI. And I knew very little about QA testing.</p><p>So, the first thing I did was I went deep into QA testing. I learned that Gherkin stories can already be automated using end-to-end (E2E) testing libraries like Playwright, Cypress or Selenium.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXDctpLf6UGfh6m0bm_K9g.png" /><figcaption>Each gherkin story’s step can be automated using Playwright</figcaption></figure><p>End-to-end testing simulates how a real user would perform a feature in your app. Usually these days, QA automation engineers write end-to-end test cases in Playwright.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*86RwOYPZfKqUS19akiBVBg.png" /><figcaption>Example of an end-to-end test written using Playwright</figcaption></figure><p>For example, in case of Doordash, to make sure adding food to the cart works, there will be an end-to-end test that will perform all the steps to add food to the cart just like a user would do.</p><p>I talked to my few developer mates, and I learned that end-to-end testing has two major challenges:</p><ul><li>E2E tests are flaky, they break when the app’s code changes.</li><li>writing and maintaining E2E tests are no-fun for a software team.</li></ul><p>My mind ran fast.</p><p>I thought, even if the app’s code changes, an AI agent should be able to figure out the right element to click on because the AI agent won’t be dependent on DOM selectors to locate an element. The AI agent will look at the screen just like a human and figure out the right element to interact with.</p><p>So, now it was time for me to develop the AI agent!</p><p>I thought I will need some sort of reinforcement learning to train an agent to perform browser tasks. I had no idea about reinforcement learning. So, I took an AI course taught by <a href="https://x.com/nagaraj_arvind">Arvind Nagaraj</a> and <a href="https://www.quora.com/profile/Dr-Balaji-Viswanathan">Balaji Vishwanathan</a>.</p><p>Via that course together with my two AI-enthusiast friends, I learned neural networks from scratch. I developed a convolutional neural network model for the famous MNIST dataset that could recognize handwritten digits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*FqUV8aoUTwO9H9YG.png" /><figcaption>MNIST dataset: a collection of handwritten mathematical digits</figcaption></figure><p>I learned how LLMs are trained and basics of how they work under the hood. I learned about vector databases, embeddings and multi-modality.</p><p>That course made me realize that reinforcement learning won’t be the right path forward. We already have intelligent models (GPT-3.5 &amp; 4) that could be utilized.</p><p>I made the very first proof-of-concept — a GPT-3.5 powered AI agent which was able to execute only very simple steps like clicking on primary buttons or typing on form fields. Upgrading to GPT-4 also didn’t yield satisfactory results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5XRx79X3-khxh5AcPY7psg.gif" /><figcaption>My GPT-3.5 agent PoC: clicking on a card</figcaption></figure><p>The GPT-4 powered agent was expensive and failed on majority of steps. I felt demotivated. But internally I knew there must be a way to make it work.</p><p>I kept researching on web agents. During my research, I learned about <a href="https://www.adept.ai/">Adept</a>. A company building AI agents that can automate browser tasks.</p><p>I signed up for their Adept Experiments program, basically, it was a beta access to their AI agent via a Chrome extension.</p><p>I got invited to try out their Chrome extension. It was the most accurate AI web agent I had seen so far. My mind was blown away. I could see the huge potential of web AI agents!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cqCa2oYg6ZiTKDR1" /><figcaption>Adept’s chrome extension, it was called workflow builder by the Adept team</figcaption></figure><p>I thought, what if I could use their internal models via an API?</p><p>I cold-emailed their founders and some senior employees. One of their employees replied saying that they weren’t focused on providing third-party access to their in-house models.</p><p>Now, I thought, I will need to build stuff in-house. I started reading research papers on autonomous web UI agents. I landed on a promising paper “<a href="https://arxiv.org/pdf/2309.11436">You Only Look at Screens: Multimodal Chain-of-Action Agents</a>”.</p><p>The authors (Zhuosheng Zhang, Aston Zhang) developed a model called Auto-UI that used a vision encoder to directly look at the webpage like a human eyes.</p><p>While I was learning about neural nets and LLM internals, I had realised that the closer we get to how a human mind’s think, the closer we will get to human-like artificial intelligence.</p><p>The Auto-UI model worked just like how we humans interact with webpages — by looking at the screen and trying to figure out the right element to click on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5V8f_a5mY-O23J8H" /><figcaption>Auto-UI model architecture</figcaption></figure><p>I thought, “yeah. I have found it! It’s time to run the model”.</p><p>For around next 20–25 days, me and my friend <a href="https://akash5100.github.io/blog/">Akash</a> tried understanding &amp; running the model locally. But we were not able to.</p><p>Again, I was surrounded by the feeling of not knowing what to do next.</p><p>It was January 2024, time for CES 2024. Everyone who was interested in the AI space got their Twitter filled with videos and tweets of Rabbit R1 and their Large Action Model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RNdS28edX7CE32pw" /><figcaption>Rabbit’s Large Action Model adding a song to a Playlist on Spotify</figcaption></figure><p>I was not interested in the R1 device. But I was impressed with the idea of the Large Action Model.</p><p>I called my friend Akash, told him about the Large Action Model. I told him, either we need to build our own Large Action Model or we need an API access to it somehow.</p><p>I messaged my teacher Arvind Nagaraj, asking if he has any advice on building something similar to the Rabbit’s Large Action Model.</p><p>We talked on Discord for the next week or so, he told me about Multi-On and Open Interpreter. They had their APIs available for use.</p><p>I tried Multi-On’s chrome extension, back then, it failed to perform steps I expected it to pass.</p><p>Some days later we met on Google Meet and I told Arvind sir everything — about my idea, Adept model’s potential, the failed PoC and the failed Auto-UI model attempt.</p><p>During the last 10–15 minutes of the call, he suggested me to try using a vision model like GPT-4 Vision. He suggested me to prompt the model with the screenshot of the web page and try to figure out a way for utilizing <br>GPT-4 Vision capabilities to act on web pages.</p><p>That thought stayed with me for some days. After some days, I saw the <a href="https://arxiv.org/abs/2401.01614">SeeAct paper</a> on Twitter that Arvind sir retweeted. I read the paper.</p><p>That paper showed me some hope that a good-enough AI agent can be built to perform steps on a browser by following natural language instructions like “Click on the ‘Search’ button on the side of the input box”.</p><h3>Going full-time with my startup</h3><p>I always wanted to work on my own thing full-time. And I had found it.</p><p>I met a founder of a software consultancy business. He had built and maintains several software products for his clients. I shared with him that I am building an AI agent to automate the QA testing of web apps.</p><p>I asked him if he would be interested in using my AI agent for testing the web apps he had built. He looked interested and told me that he might invest if the product worked well.</p><p>All these past months, I had been trying to balance my part-time job at Learning Equality and working slowly on my idea.</p><p>I assumed the worst case would be I get failed at building this startup. I was ready for this worst case. But I could not stop myself from following my heart because I was in love with the idea of helping software companies.</p><p>So, I decided to leave my part-time job and focus entirely on my startup.</p><p>I set a deadline for myself. 30 days. To get the MVP ready by building an AI agent using GPT-4 Vision.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.canva.com%2Fdesign%2FDAGPPU9Z0Vg%2FzaBjw0I49RotDKnJiuu0Hg%2Fview%3Fembed%26meta&amp;display_name=Canva&amp;url=https%3A%2F%2Fwww.canva.com%2Fdesign%2FDAGPPU9Z0Vg%2FzaBjw0I49RotDKnJiuu0Hg%2Fedit%3Futm_content%3DDAGPPU9Z0Vg%26utm_campaign%3Ddesignshare%26utm_medium%3Dlink2%26utm_source%3Dsharebutton&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=canva" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/01d4ce51c207a0903ad6f1e2b40cb6d3/href">https://medium.com/media/01d4ce51c207a0903ad6f1e2b40cb6d3/href</a></iframe><p>I completed my challenge and built the MVP in 30 days. It worked by labeling the interactive elements on the web page with numbers. Then it asked GPT-4 Vision to pick the most accurate element number to click on given the natural language description of the element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEMZVy8PzUFay5zziUWFRQ.png" /><figcaption>Drawing numbered boxes around interactive elements on the page for GPT-4V to figure out the right element</figcaption></figure><p>It worked well in many situations. But I could see it failing in many more situations.</p><p>I decided to find a user and iterate on my MVP with the user’s feedback.</p><h3>Working with a YC-funded company’s CTO</h3><p>I first met Ujjwal, co-founder &amp; CTO of GimBooks (YC W21) at a cafe. We discussed about my idea and he told me to show the MVP. We planned a meet.</p><p>I showed him the MVP, he played with it. He saw potential in the idea. He connected me to his QA engineer.</p><p>I met the QA engineer over Google Meet. I asked about how they have been doing QA of their web app. I carefully listened to his answers and also looked at the end-to-end test code he tried writing at some point in the past.</p><p>Then, I met the QA engineer in-person to let him play with the MVP and to talk more deeply with him about the problems GimBooks have been facing with QA.</p><p>I realized that the QA engineer has no bandwidth to write end-to-end tests in the first place. He was already very occupied doing exploratory testing of their mobile apps.</p><p>So, I decided to write the end-to-end tests for GimBooks by myself.</p><h3>Doing the thing that won’t scale</h3><p>After deciding to write the end-to-end tests for them by myself. I had two options. First, to use my AI product to write the tests. Second, to code the tests manually by hand using Playwright.</p><p>My AI agent was not reliable enough to be able to cover the test cases so I decided to manually write using Playwright. Also I thought, using Playwright to write the E2E tests would make me experience the pains of a QA automation engineer.</p><p>I had read Paul Graham sir’s most talked-about essay, <a href="https://paulgraham.com/ds.html">Do things that don’t scale</a>. I could see it happening. I was actually doing a thing that’s not going to scale.</p><p>I spent most of my time learning about how experienced QA automation engineers approached writing E2E tests for an application. Then, I wrote around 20–25 E2E tests and developed a new MVP for the GimBooks team. The new MVP was built for the CTO and their developers to look at the test cases’ steps and run in real-time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiGe0jpJ2TP_TEXgGF8STw.gif" /><figcaption>QA Rangers MVP-2: Real-time run of a test case with each step in plain English</figcaption></figure><p>Up-till now, I had just words of Paul Graham sir on my mind. But now I understood why a startup initially needs to do things that don’t scale.</p><p>To provide the highest amount of value possible as fast as a founder can to initial users, it needs to do thing that won’t scale.</p><p>How a founder can reach a position where he can do the thing that won’t scale?</p><p>First, reach a user as quickly as you can and do everything to genuinely help them. If you want to get anything out of this story. Get this. <strong>Reach a user as early as possible.</strong></p><p>Second, spend a lot of time with your user. Don’t just listen to what they are saying. Ask them about what they did to solve it in the past. Look at their past actions. Try figuring out why they are not able to solve it even now. <a href="https://invertedpassion.com/evidence-of-desire-customer-behavior/">Their past and current behavior is more important</a> than what words they say.</p><p>In my case, the user had no bandwidth for writing E2E tests. So, I did.</p><h3>Looking forward</h3><p>GimBooks did not convert to a paying customer. Ujjwal (the co-founder) told me that they were more focused on their mobile apps and QA automation testing of their web app was not their priority at that time.</p><p>A failure and a success.</p><p>I failed at getting a paying customer but succeeded at experiencing the doing of things that won’t scale.</p><p>So, what’s the path forward from here, if it’s not going to scale?</p><p>Recently, I read some parts of Sahil Lavingia’s book, <a href="https://www.amazon.in/MINIMALIST-ENTREPRENEUR-GREAT-FOUNDERS-MORE/dp/034943140X">The Minimalist Entrepreneur</a>, it suggested that doing freelance initially for the first set of customers can be a great way to learn and to get positive cash flow which would give some breathing room for future steps. I relate with it.</p><p>So currently, all my focus is to serve my initial customers by providing them E2E testing as a service. And then, I will let my customers give direction to my journey. I will listen &amp; observe them. They will take me to the right place. Like GimBooks took me to doing a thing that won’t scale.</p><p>I will really love to hear from you guys about the things you did in your journey that didn’t scale. Please, <a href="https://x.com/vkwebdev">share those with me on Twitter</a> (DMs are open for all). You should also follow me there as I will be sharing learnings and stories of my journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49a053f01f8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Contributions to Kolibri for Google Summer of Code 2021]]></title>
            <link>https://medium.com/learning-equality/contributions-to-kolibri-for-google-summer-of-code-2021-aeac44634c64?source=rss-831b54c52c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeac44634c64</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[google-summer-of-code]]></category>
            <category><![CDATA[kolibri]]></category>
            <dc:creator><![CDATA[Vivek Agrawal]]></dc:creator>
            <pubDate>Fri, 20 Aug 2021 20:34:59 GMT</pubDate>
            <atom:updated>2021-08-20T21:05:18.783Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://learningequality.org/"><em>Learning Equality</em></a><em> participated as a mentor in the 2021 </em><a href="https://summerofcode.withgoogle.com/"><em>Google Summer of Code</em></a><em> program, a global initiative focused on bringing more student developers into open source software development.</em></p><p><em>This guest blog post, by GSoC student Vivek Agrawal, details the experience of participating in the program and the contributions made to </em><a href="https://learningequality.org/kolibri/"><em>Kolibri</em></a><em>.</em></p><h3>Overview: Supporting the Kolibri backend Tasks system</h3><p>As part of the Google Summer of Code (GSoC) program, I worked on Learning Equality’s Kolibri Learning Platform this summer. I contributed to Kolibri’s backend Tasks system, which is an asynchronous task queue that handles processing of time consuming tasks via worker threads / processes built in pure Python.</p><p>The primary pain point of the existing Tasks system was that to add a new category of jobs to the Tasks backend for execution required modifying the <a href="https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/core/tasks/api.py">core Tasks API</a>. My project aimed to address this exact pain point.</p><p>Here are <a href="https://github.com/learningequality/kolibri/pulls?q=is%3Apr+author%3Avkweb">all the pull requests that I created this summer</a> to implement my project.</p><h3>The Starting Point</h3><p>I first applied as an applicant in 2020. The seed for Google Summer of Code was sown when one of my friends studying at National Institute of Technology, Raipur, India told me about the program.</p><p>I was going through my first semester at that time and I was new to programming. I looked up on the Internet and found Google Summer of Code to be an opportunity that closely aligned with my career interests and development.</p><p>I decided to apply for GSoC 2020 and was unfortunately not selected, but I was motivated to continue building my developer skills and apply again the next year.</p><p>Then came March 2021, when the organizations list for GSoC 2021 was announced. In this one year gap, I had worked hard to build up my programming skills and a strong foundation to be able to contribute successfully to the work at the organizations that were listed.</p><p>I first shortlisted a few organizations like Accord, Chromium, Joplin and Wikimedia. But the lightning moment came when I looked at Learning Equality’s GSoC organization page. The values and vision of Learning Equality matched exactly with my passion of providing education to low resources communities. I made the decision that if I were to apply for GSoC 2021, it would only be for Learning Equality.</p><h3>Understanding the Problem Statement</h3><p>The <a href="https://docs.google.com/document/u/1/d/e/2PACX-1vRNU9LAVw-NKDPDPFAsm2Xi45YKDqAppqR-YQJPu43GvwwE6HmRYuBEetQl28pQF2EZznNxZ6eFaEWS/pub#h.ky5628sgw643">ideas list page</a> outlined ideas for varying individual capacities. Since I was more interested in servers and databases, I chose the idea titled “Tasks API is messy and difficult to work with.”</p><p>I made it clear to myself that understanding the problem thoroughly was the most important part, recognizing that if I don’t interpret the problem correctly, then it would become impossible to write a good solution.</p><p>I started by reading the <a href="https://kolibri-dev.readthedocs.io/">Kolibri developer documentation</a> and setting up the developer environment. I then continued with the developer documentation to get an overview of the Kolibri architecture.</p><p>I searched <a href="https://github.com/learningequality/kolibri/issues?q=is%3Aopen+is%3Aissue+label%3A%22TAG%3A+beginner+friendly%22">issues</a> related to the Tasks backend on GitHub and found some low hanging issues that I could help with. Writing code to solve those initial issues provided me with a solid understanding of the Tasks backend.</p><p>I submitted these pull requests when I was trying to get my head around the Tasks backend:</p><ul><li><a href="https://github.com/learningequality/kolibri/pull/7940">https://github.com/learningequality/kolibri/pull/7940</a></li><li><a href="https://github.com/learningequality/kolibri/pull/7951">https://github.com/learningequality/kolibri/pull/7951</a></li><li><a href="https://github.com/learningequality/kolibri/pull/7950">https://github.com/learningequality/kolibri/pull/7950</a></li></ul><p>After submitting these pull requests, there was still a remaining question: <em>What problems were the developers actually facing with the Tasks backend?</em></p><p>Reaching out on the Learning Equality #GSoC Slack channel to discuss this question with the Co-Founder and Product Lead, Richard Tibbles, helped further my understanding of the challenges and where I could best contribute to the team.</p><p>Following our discussion, I wrote a detailed proposal and submitted it for review. I took the opportunity to connect again with Richard via Slack for feedback on the proposal and revising it before submitting a final version.</p><h3>Getting Selected and the Community Bonding Period</h3><p>After submitting the proposal, I didn’t settle. With one month remaining before the result day, I continued getting a deeper understanding of the Kolibri backend and Tasks backend in particular.</p><p>I submitted these pull requests to fix issues related to the Tasks backend:</p><ul><li><a href="https://github.com/learningequality/kolibri/pull/7959">https://github.com/learningequality/kolibri/pull/7959</a></li><li><a href="https://github.com/learningequality/kolibri/pull/8030">https://github.com/learningequality/kolibri/pull/8030</a></li><li><a href="https://github.com/learningequality/kolibri/pull/8063">https://github.com/learningequality/kolibri/pull/8063</a></li></ul><p>In the one month period before the results, I learned about software testing and I did a detailed study on threads, processes and concurrency at the operating system level.</p><p>The day that we all GSoC participants were waiting for finally arrived — May 17, 2021. Around 11:30 PM, I received an email from Google stating that I had been selected as a Student Developer at Learning Equality for the summer!</p><p>Wow — what a great moment it was for me and for my family &amp; friends as well! This marked the start of the Community Bonding Period. I logged into Slack and a meeting was scheduled for the next day with my mentors, Richard Tibbles and Jonathan Boiser.</p><p>In the meeting, I was introduced to my mentors and we then discussed a plan for refactoring the Tasks backend to address the developer pain points. The discussion gave a very clear perspective of what needed to be done.</p><p>In the remainder of the Community Bonding Period, I continued learning about topics that I had less experience with — Django Rest Framework and the concurrent.futures library. Also, during the community bonding period, I made a roadmap for myself for the GSoC work period.</p><h3>Completed Work Items</h3><h3>1. Registering tasks</h3><p>The first challenge was to enable Kolibri plugins to register tasks on the Tasks backend for later enqueuing and monitoring of those task functions. We decided to implement a decorator-based registration functionality inspired from Kolibri’s own @version_upgrade.</p><p>The Kolibri plugins get added to the INSTALLED_APPS Django setting, so to register tasks on the Tasks backend, we run a loop through the INSTALLED_APPS and import tasks.py module programmatically.</p><p>This, in effect, runs the tasks.py module and hence the @register_task decorator gets to run. I implemented the@register_task decorator that, when run, creates an object of the RegisteredJob class, which gets stored in the JobRegistry for later querying.</p><p>For example, to register a function add, we would write:</p><pre>@register_task<br>def add(x, y):<br>    return x + y</pre><p>The methods in RegisteredJob class namely enqueue, enqueue_at and enqueue_in get binded to the decorated function. So if the plugin developer wants to enqueue this function via the Python backend, then they can do it by writing add.enqueue(4, 2). This will enqueue the add function with arguments 4 and 2.</p><p>We can pass a validator function as a parameter to the decorator. When the frontend client sends an API request for enqueuing this task, the validator runs within the HTTP request / response cycle. If the validator doesn’t raise any exception, that means we are good to go with enqueuing the task.</p><p>For example, to register a function add and its validator add_validator, we would write:</p><pre>def add_validator(request):<br>    assert isinstance(request.data[“x”], int)<br>    assert isinstance(request.data[“y”], int)</pre><pre>@register_task(validator=add_validator)<br>def add(x, y):<br>    return x + y</pre><p><a href="https://github.com/learningequality/kolibri/pull/8142">Pull request #8142</a> implemented this whole functionality.</p><h3>2. Enqueuing any type of task via an API endpoint</h3><p>Now, with the functionality of registering tasks to the Tasks backend on our hand, an API endpoint was required for enqueuing task of any type. The POST /api/tasks/tasks API endpoint will be consumed by our frontend client to enqueue tasks.</p><p>The POST payload for this endpoint expects a task parameter that should contain a dotted path to the task function decorated with @register_task. Now, if a validator was assigned to the task, then that validator runs with request as its argument and the return value of the validator is then passed to the task function as keyword arguments.</p><p>If a validator was not assigned to the task, then we pass everything that came with the request payload, except task, as keyword arguments to the task function.</p><p><a href="https://github.com/learningequality/kolibri/pull/8186">Pull request #8186</a> implemented this functionality.</p><h3>3. Single worker pool</h3><p>The existing task worker model was strictly tied to three queues. Each worker group would only look for tasks in their assigned queue. This model restricted our plugin developers to assign tasks to one of those three queues only.</p><p>The @register_task decorator accepts priority as one of its parameters. The possible values of priority can be regular or high. Tasks with regular priority are those that can wait for some time before they actually start executing and high priority is for tasks that want execution as soon as possible.</p><p>I implemented a priority-based single worker pool. We have two groups of workers: regular and high. The high workers come into action only when all regular workers are busy and we still have jobs with high priority.</p><p>If there are fewer workers running than there are regular workers, we look first for jobs with high priority. If found, we run it, otherwise we look for jobs with regular priority and run those if found.</p><p>If all regular workers are busy, then the remaining workers only look for high priority jobs. If we find one, we run it. This algorithm makes sure high priority jobs don’t need to wait for their execution.</p><p><a href="https://github.com/learningequality/kolibri/pull/8299">Pull request #8299</a> implemented this functionality.</p><h3>4. Refactoring the Tasks API endpoints</h3><p>This new architecture work around single worker pool and decorator-based registration enabled refactoring the Tasks management API endpoint methods like list, retrieve and restarttask.</p><p>The @register_task decorator accepts permission_classes as one of its parameters. The permission_classes parameter takes in Django Rest Framework’s permission classes.</p><p>When the user sends a request to POST /api/tasks/tasks/, we check whether the user is authorized to proceed with the help of permission_classes. All other task API endpoint methods have been refactored to use the same permission_classes to authorize the request.</p><p><a href="https://github.com/learningequality/kolibri/pull/8303">Pull request #8303</a> implements this functionality.</p><h3>Work In Progress Items</h3><h3>1. API documentation</h3><p>The documentation for the new tasks backend architecture and consumable APIs is a work in progress.</p><p>The <a href="https://github.com/learningequality/kolibri/pull/8336">draft pull request #8336</a> aims to address this.</p><h3>2. Decoupling the monolithic tasks module</h3><p>The tasks in the kolibri.core.tasks.api monolithic module need to be decoupled to their respective Django apps.</p><p>Completing this work might take some time as it requires a lot of manual testing. I’ll continue to push commits to the <a href="https://github.com/learningequality/kolibri/pull/8269">draft pull request #8269</a> to get this done.</p><h3>The Future</h3><h3>1. Going from Pickle to JSON</h3><p>We have observed some issues in the past with using pickle as our binary serialization method. Job objects get serialized via pickle and then get persisted on the database which are later deserialized when retrieved. This has some security implications too.</p><p>So to future proof our tasks backend, our long term goal is to completely move away from pickle and instead store job data in the JSON standard.</p><h3>2. Extending the create API method to handle scheduled tasks</h3><p>The POST /api/tasks/tasks/ API endpoint implementation currently does not handle scheduling of tasks for enqueuing at some future point in time.</p><p>We should be extending the API to include this use case. It should be fairly easy to implement, given the current architecture.</p><h3>Closing Thoughts</h3><p>First of all, I would like to thank with all my heart Sir Richard Tibbles for his amazing guidance throughout the program. Without his guidance and ideas I would have not been able to implement this project.</p><p>Around three months back, when I started with my Google Summer of Code 2021 journey, I had almost zero practical experience with backend development. These three months of work with Learning Equality’s Kolibri platform has made me a very confident backend developer.</p><p>When I look back and see myself, I feel proud :)</p><p>Also, I would like to thank the whole Learning Equality team for creating an atmosphere that kept me relaxed throughout the program and I enjoyed every moment of this program.</p><p>Thank you Learning Equality ❤</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeac44634c64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/learning-equality/contributions-to-kolibri-for-google-summer-of-code-2021-aeac44634c64">Contributions to Kolibri for Google Summer of Code 2021</a> was originally published in <a href="https://medium.com/learning-equality">Learning Equality</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>