Python AI
Python is where most of the GenAI ecosystem lives. Two paths here:
- OpenAI SDK — direct model access, you control everything
- LangChain — adds orchestration, RAG, memory, agents on top
Neither replaces the other. Learn the SDK first, then LangChain makes more sense.
When to use which?
| OpenAI SDK | LangChain | |
|---|---|---|
| Tools / function calling | Native support | Wraps it + adds agent tooling |
| RAG | You build the retrieval | Built-in retrievers + vector stores |
| Chat memory | You manage the message list | Built-in memory classes |
| Structured output | JSON mode + response_format |
Output parsers + Pydantic |
| Agents | Assistants API | AgentExecutor, LangGraph |
| Learning curve | Low — just API calls | Medium — lots of abstractions |
Simple rule: if you can do it with the SDK in under 50 lines, do that. If you're wiring up RAG + memory + tools + routing, LangChain saves you time.
What's covered here
- Getting Started — install, first API call, message structure
- Prompts — system prompts, templates, few-shot
- Agents — routing, chains, LangChain AgentExecutor
- Tools — function calling with SDK and LangChain
- Chat Memory — conversation state management
- RAG — retrieval-augmented generation
- Structured Output — JSON mode, Pydantic, strict schemas