Programming for AI
Many people stays with programming with AI, prompting a large language model (LLM) to write code. However, the opposite direction matters a lot, as the underlying AI coding agents rely on necessary tools for generating code, so that an LLM can produce more reliable outputs.
This site teaches programming for AI: how to write programs that an LLM can actually use. The programs will enhance the capabilities of AI tools and/or provide more concrete and precise information as context for AI generations.
Two directions
Programming with AI
is about how you build: using AI copilots, code generators, and chat assistants to write boilerplate and debug faster, accelerating traditional software development. Here, AI is the tool.
Programming for AI
is about what you build: accessing necessary data, engineering the data pipelines, and providing structural information that make AI possible in the first place. Here, AI is the user.
Foundation model
Before you start
This website demonstrates with Python. You do not need to be an expert. You do need:
- Basic Python — you can read and write a Python program, run a script, and install a package with
pip. - The command line — you can open a terminal and run a command.
- A modern browser — the demos run Python and LLMs in your browser. The optional live model needs desktop Chrome with its built-in AI enabled.
- No AI background needed — each page explains the interaction model as it goes. No machine learning or maths is assumed.
- No data collected — as the executions all happen in browsers, no data will leave the browser, and the server can collect nothing.
Lessons
The lessons below introduce techniques for programming for AI. Each lesson builds on its own with a detailed introduction, scaffold code to adapt, and a concrete example for demonstration.
CLI tools
A tool living in command line environment is a program that the AI agent can decide to utilize for acquiring information or performing actions. The tool should be self-explain.
MCP servers
A MCP server is a bridge program that connects AI agents to external data sources, tools, and systems using a universal open standard (i.e., Model Context Protocol).
Agent skills
A lightweight, open format for extending AI agent capabilities with specialized knowledge, workflows, and code.
Function calling
Extend models' capabilities and knowledge by providing functions they can use to follow instructions and respond to prompts.
Structured output
Contrain the model to output adhere a JSON schema so that programs can process the output easier.
RESTful API
A web service that follows a standard to let software systems communicate with externals.