Transcript#
This transcript was generated automatically and may contain errors.
Hello everybody, welcome. Next up we have Jeroen Janssen. PhD. He is the Head Developer of Relations at POSET. And author of the Python Polars the definite guide and data science at the command line. His talks are about turning brittle scripts into robust tools, CLIs, that your future self coding agents will thank you for. Jeroen.
Hands up. If you've ever written Python code that for example loads in some CSV, prints out its shape, first 10 rows, how many missing values there are.
Let me see those hands. You know, something like this.
Now, keep your hands up if you still know where that code actually is. You actually all got your hands down. And that is exactly what this talk is about. That's what we're going to tackle today.
We all write this code, right? We write it constantly. Whether that's in a script or in a notebook. And then we throw it away. And then a couple of weeks later we write similar code, slightly different, slightly worse. Different script, different notebook.
And so, I want to start by giving you two definitions. Two words, because that's the whole spine of this talk. On the one hand, we have scripts, and Python is great at that, right? You can use practically anything. You can let Python do practically anything. But the thing is, it's often single purpose, very context dependent, and, yeah, contrast this with a reusable tool, right? Which is often much more flexible.
And so, my general advice today is that you should, you know, put in a little bit of extra effort to turn a throwaway script into a reusable tool.
Hoi. My name is Jeroen, and yes, I love the command line. Because when I was talking about those tools, I was specifically talking about command line tools. Tools that you can run from the Unix command line. And many years ago, I wrote a book about this, which means that I've spent a lot of time thinking about this problem. Now, these days I do developer relations at Posit, which is the company behind tools such as Cordo, Shiny, GrayTables, Plotline, Positron.
All right. I also wrote this other book together with Thijs Nieuwdorp. And tomorrow, during the lunch break, we're giving away a couple of signed hard copies. So if you're interested, come visit us. It's the Posit and Polar's Boots. They're next to each other.
From throwaway scripts to reusable tools
So now back to scripts and tools. Going from a throwaway script to a reusable tool has never been really difficult, but it's been quite annoying, right? And you weren't really sure whether it was worth it. So, but now, thanks to the rise of coding agents, this has completely changed.
And at the same time, the value of creating a reusable tool has roughly doubled, because now you have a second type of user. Spoiler, it's that same agent.
So, the command line is old. It's really old. It's even older than I am. Unix came out in 1971. That's 55 years ago. Think about it. About 10 years ago, the command line became a little bit more popular again. On Hacker News, there was this period where every single day there was a new command line tool coming out that made the command line more ergonomic, faster.
And then, more recently, about a year and a half ago, over the span of four months, three different vendors came out with different coding agents. And they all chose the command line as their interface. So, all of a sudden, the command line became the most important interface again. Now, I'm expecting my book, Data Science of the Command Line, to become a bestseller any day now.
Why the command line and agents are a perfect match
And there are actually three reasons why the command line and agents are such a match made in heaven. The first reason is that agents run cli tools. If you look at what an agent actually does when it's working, it's calling all these command line tools. Grab, find, alas, cat. These tools are the hands of the agent.
Your tool, your next tool, could be on that list. Every tool that you build can become a new capability for the agent. Not through integration, not through some plug-in system. You put an executable somewhere that the agent can reach, and all of a sudden, its toolbox just got bigger.
Your tool, your next tool, could be on that list. Every tool that you build can become a new capability for the agent. Not through integration, not through some plug-in system. You put an executable somewhere that the agent can reach, and all of a sudden, its toolbox just got bigger.
Now, here's the second reason. Agents are actually well-behaved Unix tools themselves. Who's ever used CLAW like this? When you specify the dash p flag, it becomes a tool that you can pipe into. One person over here. Two, three. A few people here have tried it. Not everybody. It's great because now you can pipe into it. It produces text on standard out. It can even produce JSON data that you can further process.
That means, because it's a well-behaved Unix tool, that you can also loop over a thousand files, for example, that you wanted to process, or you can put it into your own script or notebook or tool. The agent stops becoming a chat window, and all of a sudden becomes a component that you can compose with.
The people building these agents didn't choose an interface from the 70s because it's charming. It's because it works.
The third reason, and this is the reason that will really remove your last excuse to go from that throwaway script to a reusable tool. That's because agents are really good at building CLIs. There's a lot of boilerplate. There's a lot of well-documented, heavily patterned code, and this is exactly the thing that an agent is good at. The tax that you used to pay to productionalize a script, that boilerplate that made you think, it's not worth it, that has essentially gone to zero.
Building the Peek tool
Here's the plan for today. We'll use a tool called Peek, based on those five lines I showed at the very beginning, and we'll turn it into something that you actually want to keep, that you can reuse for other projects.
Now, again, agents and the command line are a match made in heaven, so let's dive a little bit deeper into why that is.
The Unix philosophy can be summarized into three lines. Do one thing well, make it work together with other tools, and text is the universal interface. I've been quoting this as advice for years.
It's not just advice anymore, it now actually has become a spec, because each of those lines is now a requirement of whether an agent can use the tool that you're building.
Let's have a look at each line here. First line. For a human, do one thing well is about comprehensibility, but for an agent, it's a matching problem. Here's my goal. What tools do I have available, and which one fits? A tool that does one thing clear is easy to match, but if you have, say, data underscore utils dot py with 14 different subcommands and overlapping flags, now that's a tool that either the agent will use wrongly or avoid entirely.
Now, composition. The second line. Your tool doesn't have to do everything. We have curl for downloading files, we have jq for processing JSON, we have xrs to parallelize jobs, and the agent already knows how to chain those together. As long as your tool will emit structured output, you inherit the entire ecosystem for free.
And the third line has aged into something almost eerie. Text is the universal interface, and LLMs, large language models, are by definition things that consume and produce text. Unix and LLMs happen to speak the same medium, and there's no adapter layer, no SDK, no schema negotiation, no protocol version, a pipe just works.
Text is the universal interface, and LLMs, large language models, are by definition things that consume and produce text. Unix and LLMs happen to speak the same medium, and there's no adapter layer, no SDK, no schema negotiation, no protocol version, a pipe just works.
Back to our five lines. This works perfectly for exactly one file on exactly one machine, and it's about useful for about a couple of minutes. So let's fix the most obvious problem first. It only knows about one file. We can do that by adding arguments to our tools. There are three ways to do that, depending on whether you want to stay within the standard library or whether you're okay to use additional dependencies.
My personal preference is Typer, a really thin skin over a callable, and it's very different from ArcParse, which is imperative, and it's kind of like this parser bolted on the top of your script, and that separation is worth a lot. Oh, and the output of Typer also looks prettier.
Designing for two types of users
So here's the more interesting design question, and the one that I didn't really know how to ask a year ago. Who is this tool actually for? Because now there are two types of users, and they want opposite things.
Your human user, which could be yourself, wants a pretty table with aligned columns, the worst column at the front so that you can spot problems. You want color, thousand separators, but your agent wants none of that. Color codes are noise, and all that Unicode box drawing that has to be parsed with a regex that will often fail. It just wants the thing that actually matters, the tokens that actually matter.
Now the wrong answer to this is to build two different tools. The right answer is to have one tool with one flag that can produce these two renderings. So your human output is the default, and by adding dash dash JSON, you get the machine version.
Now this differs per tool still. It's an emerging convention to use dash dash JSON. Cloud itself uses dash dash output dash format equals JSON. But I guess it also depends on how many output formats you actually want to support. But I have seen dash dash JSON quite often. And it's just a couple of lines of change if you want to implement this.
Help text as a prompt
Now here's something to think about. And it really changed the way I'm writing CLIs. Command line tools. The first thing that an agent does in order to understand what a tool does is run dash dash help. And so the output of that command goes straight into the prompt of an agent.
So dash dash help is not documentation. It's a prompt. You're actually prompt engineering without you even realizing it. And so your read me meanwhile will be exactly read never by no one.
dash dash help is not documentation. It's a prompt. You're actually prompt engineering without you even realizing it.
So let's just put some examples in it. Syntax tells you what's possible. Examples explain what the tool is for. And this is useful for both types of users. But an agent specifically will find out other ways to figure this out. And that can get costly as well.
Error messages and exit codes are the same idea. If you provide a good error message, that is something that will allow the agent to recover from. Same with exit codes. It doesn't need to figure out from standard out whether it succeeded or not. This is a Unix convention that you definitely want to use.
I used to give this advice. Dangerous operations require explicit confirmation. But when it comes to an agent, an agent is unable to confirm. So you have to flip it around. Best case, it hangs forever. Worst case, it figures out that it can pipe yes into your tool and turn it into something that can ruin your entire machine. So you make dry run the default behavior, and if something is potentially destructive, you require an explicit dash dash yes.
PEP 723 and dependency management
Now we come to one of my favorite things that has happened to Python in recent times. We've all been here, right? You have a well-designed tool, and now you've hit a wall that has killed more Python tools than bad design ever did. Before you know it, you're explaining virtual environments, writing a readme, distributing or maintaining a requirements txt file. The whole distribution is growing out of proportion.
It's even worse with an agent. Very often, it'll install things in your global system, not inside a virtual environment. So you want something that just runs.
And pep 7.23 fixes all of this with an idea so simple it's kind of annoying it took so long. We can now let the script declare its own dependencies inside itself. It's a comment, so Python ignores it entirely, but a compatible runner like uv reads it, resolves those dependencies into an isolated environment and then runs your code in it. That's it.
So it goes even further. Excuse me. If you add this hashbang at the top, you can just run your tool like it is any other executable, especially if you then also put it on your global path and make it executable. But these steps really turn your Python script into something that feels like a proper tool. This is the Go binary or Rust binary experience. But then now possible in Python using a comment.
Now, of course, you need to let the agent know that your tool exists. And this is all that's necessary for our tool. These couple of lines, you either put it in agents.md or claw.md and that's remarkably little effort to extend what the agent can do. This is the whole integration, right? There's no install step for the agent to get wrong. There's no environment to guess. It works.
Live demo
So, yes, I should have demoed this. I knew it.
All right, so we're in Cloud Code and my screen size, let me get it out of this. My screen size is slightly slightly
All right. I just got a new data set. Animals.csv And because of claw.md, it knows it can use peak, right? We're now a couple of iterations further with those arguments and all. But it's a bit fast, but you can rerun this if you go to the GitHub repo where the QR code will lead you.
Okay, okay. You know what? There are all these best practices and things you can do to make it a really polished command line tool, right? Add dash dash version, make it honor the no caller setting, being able to handle broken pipes, all of this. And, you know, I was going to show you a demo of how the agent can add these things.
But then I'm like, what if I just let the agent do everything? So in this demo, I'm giving the agent a prompt and that prompt is also in the repo. I'm giving the agent a prompt that will turn those very first few lines, those five lines, into a polished command line tool. It's not even, yeah, let me just show you.
Right, so that's the prompt. UV arguments, dash dash JSON, right? No caller, sigpipe, useful examples.
It's, yeah, no boilerplate for us anymore. It's, I don't really know how to feel about this, but I do have something I want to ask you, and that is, should we actually still use Python, right? If the agent takes care of so much, if I would have added, you know, if I would have added if I would have added like, oh, and build it in Rust or build it in Go, it would have just done that. Right, use all the best practices in one go, not even five minutes of work.
So, because the command line, right, doesn't care in which language a tool has been written in. UV run still needs UV on the machine. It's something that Go shipped in 2012. One artifact, no install, but, you know, oh, wait, yeah, and another thing then to consider is that Rust and Go are compiled languages, right, so it's much better checked before it is run. Go and Rust provide good error messages that allow the agent to correct itself, and when it comes to Python, yeah, there's a whole class of errors that only appear when you're actually running the code.
Now, so, to be honest here, because it's, the answer is not as simple. It's not really compiled versus interpreted, right, it's how much, you know, how much of your program an agent can check without running it, and if you use type checkers and unit tests, then most of that loop, that's actually in the ecosystem that you need, and it's that ecosystem that makes Python so valuable as well, right? Polars, PyTorch, Scikit-learn, that's, those are things that we shouldn't forget. That's the moat here of using Python, and of course you still have to read the code, right? I mean, for now. So, it's certainly something to think about.
Right, and you could say, okay, the agent does all the boilerplate, all the boring stuff, and I, as a programmer, take care of the interface design and how it looks like, the things that require taste, but, you know, that's also, we'll see how things go in a couple of months.
Wrapping up
Hey, so, we started with five lines, you know, this throwaway script, and now we ended up with one executable that's a proper command line tool that you yourself want to use, and also agents. None of these steps were hard, but it's just that those were steps that we usually want to skip, because they take time, and they're not that exciting.
So, where does this bring us? You, yourself, future you, you're a user, but now your agent is also a user.
You, yourself, future you, you're a user, but now your agent is also a user.
Yeah. Thank you very much for listening.
Q&A
Thank you for the... Whoops. Thank you for the talk. Really nice talk. Does anybody have any questions? Yes. Watch out for your hat, so I don't...
I was wondering, what happens to the installed dependencies if I have ten tools and I need to install Polars in every one of those ten? Do I get somewhere ten installations of Polars, or...
I believe UV has a global cache that, and then individual isolated environments will link to that. I see some nodding, so yeah.
Thank you for a very inspiring talk. I was just wondering how to then now share those tools within your teammates. The tools are created, and then making them available for a broader audience inside of a team, or even maybe broader. Do you have any ideas of this, or those tools are only from your perspective, only for you and your agent created?
Yeah, so your question is about how do I share my tool with others? My teammates, so a very valid solution is to put it in a GitHub repo. And if you think it is useful for even more people, then you can put it on PyPI.
Thank you for the presentation. Very interesting concept, topic like extending our agents and making them better. You didn't touch on skills, and I was wondering do you see how this interacts, and how would you alter this if you wanted to work with skills?
What I usually do is I put this either in a global Claw.md file so that every new project knows about the tool. There's also the option to building
Yeah. I just use Claw.md. But there are different approaches to this. It's a matter of preference, I would say.
Q&A: expectations for the near future
Thank you very much for this talk. Within the presentation I think twice you said that we are reading the code for now, and we are the user for now. So what is your expectation from the near future? What do you expect it to happen within the couple months that you hinted but didn't elaborate?
So what are my expectations for the coming months? I honestly have no idea. When I first proposed this talk, I had very different ideas of what I wanted to talk about. Things are changing so fast.
Now, I still believe that having a reproducible artifact is what really matters, right? So that you can be held accountable, that you can inspect, okay, what has actually been going on.
But on the other hand, I've been building a tool myself in Go for the past few weeks. It's on PyPI, but people don't even need to know it's in Go. And I haven't read a single line myself.
Things are changing very fast, and I just don't dare to make any predictions of what is going to happen.
Things are changing very fast, and I just don't dare to make any predictions of what is going to happen.
Q&A: taming the agent
You just said, like, I don't look at the code anymore, and when building a tool, you say, yeah, you can make the tool for the agent and the tool for the human. No colors, not too much verbosity and boilerplate for your agent.
But what I often encounter is when I make these kinds of tools, or the agent pipes it to a tool that just prints out the last 10 lines, which is not a problem, which is good to manage a bit the amount of tokens consumed. But when something goes wrong, yeah, it just printed out the last 10 lines.
And lately, very often, I'm stopping the agent, rerunning the commands to actually see the full output, to see what's happening. Or when it runs tests, and it's a long test suite, and it prints out the last 20 lines, I'm getting anxious, because it's two minutes that I don't see what's happening, and I don't trust it.
So do you have the same thing, and do you have a possible solution to?
So you're running into the issue that an agent likes to do too much, right? I think this is a quite common problem. And so you're saying, excuse me, you explicitly add the example of, OK, I have this tool, and then the agent pipes it into tail to just get the last 10 lines, or something.
I wonder if you could specify in your Claw.md file that it shouldn't do that, but yeah, it's always this cat and mouse game of trying to tame the agent of not doing too much. I don't really have a good solution to this.
Thank you all for coming. One more applause for our speaker, Jeroen. And enjoy the next sessions on the agenda.
