Cheat sheet · Specialise
AI agents and MCP cheat sheet (Python)
Opens with creditsFor Python developers who can already call a model API and want to build agents that hold up in real use: tool calling, Pydantic validation, memory, planning, LangGraph, the OpenAI Agents SDK, the Claude Agent SDK, MCP servers, evals and guardrails. Every snippet is Python.
Chapters
10 chapters · 74 concepts
1How agents workWhat makes a program an agent, the loop every agent runs, and how to decide whether a task needs an agent at all or a simpler workflow.6 concepts
- 1Agent loopA loop in your code: send the conversation and tool list to the model, run any tool calls it returns, append the results, and call the model again until it…
- 2Workflow vs agentIn a workflow your code decides the steps and the model fills in parts of a fixed path.
- 3Augmented LLMA language model given three extras by your code: tools it can call, retrieval that brings in relevant documents, and memory that carries facts between calls.
- 4ReAct patternThe idea, from a 2022 research paper, that a model alternates between reasoning about what to do, taking an action with a tool and observing the result before…
- 5Ground truth from the environmentReal results from the world, such as test output, an API response or a database row, that the agent reads after each action to judge whether it is on track.
- 6When not to use an agentA quick test before building: is the task multi-step and hard to specify in advance, is the outcome worth extra cost and latency, can a model do it, and can…
6 in this chapterOpen this chapter2Tool calling from scratchHow a model asks your code to act: tool definitions, the call and result messages, tool choice, parallel calls and errors, shown with one provider API and no framework.8 concepts
- 1Tool definitionA name, a description and a JSON Schema for the arguments, sent with every request.
- 2Tool call and tool resultThe model replies with a tool call carrying an id, a tool name and JSON arguments.
- 3Provider differences in tool callingEvery major provider has the same loop with different field names.
- 4Tool choiceA request setting that lets the model decide freely (auto), forces a tool call (any or required, or one named tool), or blocks tools (none).
- 5Parallel tool callsOne model turn can contain several tool calls.
- 6Tool errors the model can act onWhen a tool fails, return a result marked as an error with a short message saying what went wrong and what to try instead, rather than throwing and crashing the…
- 7Writing tool descriptionsDescribe each tool as you would for a new teammate: what it does, when to use it, when not to, what it returns and any limits.
- 8Keeping tool results smallReturn only what the model needs to decide the next step: a few relevant fields, a page of results with a way to get more, and readable ids instead of raw…
8 in this chapterOpen this chapter- Structured output and validationGetting data your code can trust from a model: JSON Schema, strict modes, validation with Pydantic or Zod, and what to do when the output is wrong.6 conceptsOpens with credits
- Memory and stateWhat an agent remembers within one run and across runs: the context window, context engineering, compaction, long-term memory stores and explicit state.7 conceptsOpens with credits
- Planning and multi-agent patternsThe reusable shapes for multi-step work, from simple chains to orchestrators and handoffs, and when splitting work across several agents is worth the cost.8 conceptsOpens with credits
- Agent frameworksLangGraph, the OpenAI Agents SDK and the Claude Agent SDK: what each gives you over a hand-written loop, the core API of each, and how to choose.7 conceptsOpens with credits
- Building and publishing MCP serversThe Model Context Protocol from the server side: roles, primitives, transports, the stateless 2026-07-28 revision, the official SDKs, testing with the Inspector, auth and the registry.8 conceptsOpens with credits
- Evals and testing agentsHow to know an agent works before and after every change: tasks and trials, graders, trajectory checks, pass rates, model judges and a regression suite in CI.8 conceptsOpens with credits
- Guardrails, cost and safetyKeeping agents safe and affordable: prompt injection, the lethal trifecta, least privilege, human approval, sandboxes, step and budget limits, and the cost maths of a run.8 conceptsOpens with credits
- Observability and shippingRunning agents in production: tracing every step, OpenTelemetry conventions, durable execution, retries, streaming progress, model fallbacks and turning production traces into evals.8 conceptsOpens with credits
- 11Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.128 terms
About this sheet
Tool calling, MCP servers, evals.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- Best Practices for Building LLM AppsHow to build LLM apps and agents that hold up in production: prompts, evals, prompt injection, tool permissions, cost, logging and privacy.
- Best Practices for AI Coding AssistantsHow to get reliable code from AI coding assistants and agents: instruction files, task prompts, verification, review, security, dependencies and session hygiene.
- Prompt Engineering Best PracticesHow to write prompts that work the same way on the hundredth input as on the first: clear instructions, structure, examples, reasoning, output control and testing.
Checklists
See all- RAG Production ChecklistA RAG production checklist: chunking, embeddings, hybrid search, reranking, per-user permissions, citations, evals, re-indexing and cost, with how to verify each check.
- LLM Evaluation ChecklistAn LLM evaluation checklist: success criteria, eval datasets, code and model graders, judge calibration, agent evals, safety tests and production monitoring, with how to verify each check.
- AI Feature Launch ChecklistAn AI feature launch checklist: use case fit, evals, UX for errors, disclosure, human override, abuse filters, rate limits, cost caps, prompt privacy, monitoring and rollback.
Project structures
See all- GenAI RAG app (FastAPI) project structureFor developers turning a "chat with your documents" demo into an app people can rely on. A FastAPI backend where every layer has a home: ingestion workers, retrieval, prompts as versioned files, model clients with fallbacks and cost caps, guards, evals that gate CI, and tracing, so a wrong answer can be traced to the step that caused it.
- AI agent with an MCP server project structureFor developers who want to give AI assistants safe access to their own data or API. A TypeScript MCP server built on the official SDK, organised by feature (tasks, projects) with each feature owning its tools, resources and prompts, served over stdio for local hosts and Streamable HTTP with OAuth for remote ones, plus a small agent and the evals that prove a model can use it.
- Python AI agent with LangGraph project structureFor Python developers moving from "call a model in a loop" to an agent that can pause, resume and be debugged. It starts from the official LangGraph template (langgraph.json, a src/agent package, unit and integration tests) and grows into a customer support agent with typed state, one file per node and tool, human approval before refunds, evals that score whole trajectories, tracing, auth and a deployable server image.
Career questions
See all- How do I start learning AI agents as a software engineer?Start with one LLM API and plain code: a loop that calls the model, lets it pick a tool, runs the tool and feeds the result back. Build one small agent that does a real task end to end, add evaluation and guardrails, and only then reach for a framework. Agents are software engineering first.
- Should I learn LangGraph, CrewAI or the OpenAI Agents SDK first, or build AI agents without a framework?Build one small agent without a framework first: the tool-calling loop is about fifty lines and every framework wraps it. Then learn one framework deeply, chosen by what your project needs: LangGraph for explicit state and approvals, the OpenAI Agents SDK for quick assistants with handoffs, the Claude Agent SDK for agents that work on files.
- What is MCP, and do I need to learn it?MCP, the Model Context Protocol, is an open standard for connecting AI applications to tools and data. You do not need to study it in depth, but if you build with LLMs, writing one small MCP server takes an afternoon and teaches you how agents really use tools. Learn the concepts; skip the hype.
Cheat sheets
See all- GenAI app architecture cheat sheetHow a production GenAI app fits together: request flow, layers, RAG, agent loop, memory, caching, guards, evals, tracing, folder layout and launch checklist.
- RAG cheat sheetRetrieval augmented generation end to end: chunking, embeddings, hybrid retrieval, reranking, grounded prompts, evaluation and failure modes.
- AI evals cheat sheetEvals for LLM apps and agents: golden datasets, metrics, LLM-as-judge and its biases, RAG and agent metrics, offline and online evals, CI, human review, tools.
Work with me
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com