LLM with Livebook - any tips or workflows you recommend?

Hi All

I use AI with my elixir coding pretty successfully. Maybe it tells more about my elixir skills level, but I manage to get quite a lot of use from Cursor Composer agent mode which suggests changes to files and I can accept/reject with a click. And I can add hex docs of needed libraries to it, so it’s aware of APIs needed!

My current project is an RnD in Livebook and… I fail to figure out a good workflow for livebooks. Just editing running livebooks’s markdown file doesn’t work as it local changes will not be loaded and even more, any changes done in livebook UI will overwrite the file.

Good workflow
The best I was able to figure so far is to just chat with my livebook content in Cursor Composer and copy-paste content from chat to livebook and back. It works, but it tedious.

What do you use for AI in livebook?

  • Same copy-paste between chats approach?
  • Or is there an [easy] way to ask livebook session refresh itself from file instead of autosaving to file somehow?
  • Or is there some agent tool able to edit livebook content in browser?
  • Something else?
3 Likes

Self-answering of what worked for me okayish so far.

Tool I use
First of all Cursor Composer Agent is good and helps (with my level of elixir skills). Indeed it is not too knowledgeable on elixir idioms, so you may need to ask it to pay more attention to elixir idiomacy (e.g. more pattern matching, less branhing) + add some documentation on the libraries you use (e.g. to its list of docs you can just add links to hexdocs of Kinio, Tesla, etc). Sure it also sometimes makes stupid mistakes, but if I look after it, then it helps me code quite significantly. Except for this issue with LiveView ignoring and overwriting the underlying files.

So here’s what I used with some success:

Option for short notebooks: Just copy-pasting
You ask for Cursor agent suggestions, but do not apply to a file. Just copy-paste them to livebook editor manually. With small livebook notebooks it actually worked surprisingly well and wasn;t too annoying.

Option for large notebooks: Agent to edit file and then reconnect
Then my notebook grew from “just a small exploration” into "let’s make an externally accessible API out of it. Still RnD, but with some thinking of proper error handling, several secrets, Livebook Teams deployment, etc) and copy-pasting across many cells became painful. I figured the following process:

  1. Type next prompt to Cursor, discuss with it whatever you want. You notebook can be running meanwhile: As long as you type nothing in the livebook UI it doesn’t seem to overwrite the underlying file
  2. Close the session via notebook’s top of page button. It takes you to the Livebook home page
  3. Click open and notebook you just worked on will be on top of the Recent ones, so quick open
  4. From address bar copy session ID (that I’ll need in the end to send HTTP request)
  5. In sidebar open secrets (keyboard shortcut “ss”) and enable whichever secrets you need
  6. In sibebar open outline (keyboard shortcut “so”) click on the final section (or whichever section starts what you need to test and evaluate it"
  7. Eventually in postman (or whichever tool you use for sending http requests) replace old session id with the one copied on step 4 and you can send requests

It looks like a lot of things to do and I am not super-happy with the process indeed. However, once I did it several times it got to muscle memory and I am relatively fast with it - faster and more accurate than with copy-pasting indeed.

Any other options?
Does anybody have a better idea? After all what I am essentially doing it just close-recreate session for the same file (and reenable same secrets). Is there possibly some way e.g. to send message from IEex console to do it all in one go?

1 Like

Maybe take a look at @thmsmlr’s quite recent GitHub - thmsmlr/livebook_tools: Powertools for livebook.dev — AI Code Editing, MCP Servers, and Running Livebooks from the CLI

2 Likes

Wow, if it works, that seems to be exactly what I was hoping for! Thanks, Leon, I’ll give it a try!

1 Like

The process for setting it up was a bit tough (e.g. I had to switch from Livebook desktop to versioned livebooks installed to asdf internals) and I had to learn how mcp servers work, but in the end it was a very good solution. Thanks, @nulltree !

2 Likes

Glad to hear it :slight_smile:

I’m curious how this works as I’ve seen videos but I’ve assumed there could be issues like this. Has any of this changed?

How are you getting on with it a month later? I’ve been a bit lost on just trying to find the right subscription because I hate canceling them. My day job gave us Copilot but I haven’t worked with agent or edit mode. I’ve gotten along decently well with just chats but its starting to feel slow. There’s now Tidewave but it doesn’t touch Livebook. Livebook is a Phoenix server under the hood though. My guess and hope is that it will eventually add tools for Livebook too.

  1. Reloading livebook on making changes to file
    This worked very well for me, just as you’d expect: you (or AI) changed something in the standalone editor and livebook’s reloaded.
    But then it stopped (I think after I started using different livebook versions or something like this). Now it throws some storage-related errors whenever tried reloading sessions. Quick research didn’t help and as my LiveBook-related task was about to finish, I didn’t have motivation to dig deeper or report a bug. Maybe will try again when working with LiveBook much next time.

  2. MCP tool for AI to read results of cells
    Didn’t find it particularly useful, but I experimented with it just a little bit. I had many cells and IMHO cursor was getting lost in where to look for the results in.

  3. Misc
    Cursor (on Claude Sonnet 3.5 mainly) was all the time getting lost with 3 VS 4 backtick formatting in livebook notebooks. That was giving headaches with manual fixing. Could be solved by better prompting probably.