Pycon Israel 2021

Resumable persistent functions in Python: how to build a chatbot the fun way
05-02, 11:30–12:15 (Asia/Jerusalem), General Track 1

In K we had a simple task: build a chatbot. With a lot of logical paths. And loops. And external interrupts. In this talk I will present our fairly exotic solution, that looks like a resumable function, which is persisted across user requests.

Source code for the examples is available on GitHub.

Slides are available here.

I will be presenting the "dialogs framework", which a library we build in-house for managing long-running persistent functions. These functions come back to life when they get a message from the user, magically resuming where they left off. I will go over the design process, the Python implementation details, and the current gaps and challenges.

The aim of this talk is to inspire similar projects, show off our framework, and reach out for community inspiration on our open challenges.

As motivation, here is the kind of code we are writing:

def greet():
    name = run(prompt("Hi, I'm a bot. What's your name?"))
    location = run(prompt(f"{name} is a beautiful name! Where are you from?"))
    run(send(f"{location}? No kidding! I grew up there!"))

After each call to run, the function terminates and the user request is answered with the next message to display. The execution state is persisted into our database, allowing the follow-up answer to be handled by a different server in the future.

Session language


Target audience

Developers, Other (please specify below)

Other (target audience)


Software Engineer at K Health, on the chatbot team.