os
sys
json
pandas
numpy
But in real-world LLM, RAG, LangGraph, Agentic AI, MCP, Multi-Agent Systems, Prompt Engineering, and AI Automation, some lesser-discussed built-in modules provide enormous value.
collectionsfrom collections import defaultdict, Counter, deque
Token frequency counting
Chat history management
Agent state tracking
Analytics
Example:
from collections import Counter
words = ["AI","AI","ML","AI"]
Counter(words)
Output:
{'AI':3,'ML':1}
Document
↓
Chunking
↓
Keyword Extraction
↓
Counter()
itertoolsimport itertools
Used heavily in:
Agent orchestration
Workflow generation
Combinations
Prompt testing
Example:
import itertools
list(itertools.product(
["GPT4","Claude"],
["Finance","Healthcare"]
))
Output:
[
('GPT4','Finance'),
('GPT4','Healthcare'),
('Claude','Finance'),
('Claude','Healthcare')
]
Models
×
Prompts
×
Datasets
Generate thousands of experiments.
functoolsfrom functools import lru_cache
One of the biggest hidden gems.
Example:
@lru_cache
def expensive_function():
...
In GenAI:
Repeated Query
↓
Skip Recalculation
↓
Save Tokens
↓
Reduce Cost
typingUsed everywhere in:
LangGraph
LangChain
FastAPI
Pydantic
Example:
from typing import List
def search(
docs: List[str]
):
...
Large AI Project
↓
Clear Interfaces
↓
Less Bugs
dataclassesExample:
from dataclasses import dataclass
@dataclass
class Document:
id:int
text:str
Instead of writing:
class Document:
...
hundreds of lines.
Chunks
Retrieval results
Agent messages
pathlibOld Way:
os.path.join()
Modern Way:
from pathlib import Path
Path("data")/"docs"
Documents
PDFs
Embeddings
Vector DB Files
Logs
contextlibExample:
from contextlib import contextmanager
Used for:
DB connections
LLM clients
Temporary resources
uuidimport uuid
uuid.uuid4()
Chat Session IDs
Agent IDs
Workflow IDs
Memory IDs
datetimeExample:
from datetime import datetime
datetime.now()
Used for:
Conversation timestamps
Memory systems
Logs
Scheduling
hashlibExample:
import hashlib
hashlib.md5(text.encode())
Document
↓
Hash
↓
Detect Duplicate Upload
Critical in RAG systems.
reAlready one of your strengths 😊
Used for:
Cleaning prompts
Parsing responses
Structured extraction
Example:
import re
re.findall(
r"\d+",
text
)
difflibExample:
from difflib import SequenceMatcher
Used for:
User Query
↓
Similarity Check
↓
Best Match
Before expensive embeddings.
inspectOne of LangGraph's favorites.
Example:
import inspect
inspect.signature(func)
Used to understand:
Functions
Tools
Agent Nodes
Dynamically.
astExample:
import ast
Used by:
Code agents
AI coding assistants
Static analysis
Visual Flow:
Python Code
↓
AST Tree
↓
Analysis
jsonEveryone knows it.
But most don't realize:
Prompt
↓
JSON Schema
↓
Structured Output
↓
Agent Workflow
Almost every modern LLM app depends on it.
loggingMost underrated module.
Instead of:
print()
Use:
import logging
User Query
↓
Agent
↓
Retriever
↓
LLM
↓
Logger
Makes debugging possible.
asyncioThe backbone of modern AI apps.
Agent1
↓
Agent2
↓
Agent3
Sequential.
Agent1 ──┐
Agent2 ──┼── Parallel
Agent3 ──┘
Huge speed boost.
concurrent.futuresParallel processing.
Useful for:
Embeddings
Batch inference
PDF processing
sqlite3Perfect local memory store.
Useful for:
Chat History
Agent Memory
Knowledge Base
Without installing PostgreSQL.
pickleStore Python objects.
import pickle
Used for:
Embeddings
Model Outputs
Caches
(Be cautious with untrusted data.)
If you're learning LangGraph, focus first on:
typing
dataclasses
collections
functools
itertools
pathlib
uuid
datetime
json
logging
asyncio
inspect
GenAI Project
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
Data Layer Agent Layer Infrastructure
│ │ │
pathlib typing logging
hashlib inspect asyncio
json dataclasses concurrent.futures
collections functools sqlite3
| Rank | Module | Why |
|---|---|---|
| 🥇 | typing | LangGraph foundation |
| 🥈 | dataclasses | State objects |
| 🥉 | collections | Data manipulation |
| 4 | functools | Caching |
| 5 | asyncio | Parallel agents |
| 6 | inspect | Tool discovery |
| 7 | pathlib | File handling |
| 8 | logging | Production debugging |
| 9 | hashlib | Document deduplication |
| 10 | itertools | Workflow generation |
GENAI ENGINEER TOOLBOX
📁 pathlib → Files
📦 dataclasses → Objects
🏷 typing → Types
📊 collections → Data
⚡ functools → Cache
🚀 asyncio → Parallelism
🔍 inspect → Reflection
📝 logging → Monitoring
🔐 hashlib → Fingerprints
🔄 itertools → Combinations
If your goal is to become a strong LangGraph / Agentic AI / GenAI Engineer, mastering these 10 modules will give you far more practical value than spending weeks on many rarely used standard-library modules.