方寸 Portal

AI Engineer Portal

Your personal operating system for career transition.

Private mode

Practice

Hands-on drills tuned for AI engineering.

Build implementation muscle memory. Each exercise includes starter code, a reference solution, and AI-powered feedback.

Agents (8)

Build a tool registry with schema validation

In any agent system, the model needs to know which tools are available, what arguments each tool expects, and how to...

agentstoolsschema-validation
intermediate

Implement a ReAct reasoning loop

The ReAct (Reasoning + Acting) pattern is the most widely used agent loop in production. The model alternates between...

agentsreactreasoning-loop
intermediate

Add retry and fallback logic to tool calls

In production agent systems, tool calls fail. APIs time out, rate limits hit, services go down. A resilient agent does...

agentsresilienceretry
intermediate

Parse structured outputs with error recovery

LLMs are asked to produce JSON constantly — tool call arguments, structured answers, classification labels, extraction...

agentsparsingstructured-output
intermediate

Conversation memory manager with token budgeting

Agents that run multi-turn conversations or long-running tasks quickly blow through context windows. A memory manager...

agentsmemorytoken-management
advanced

Multi-agent handoff protocol

As agent systems grow, a single monolithic agent becomes unwieldy. The multi-agent pattern splits work among specialist...

agentsmulti-agenthandoff
advanced

Agent evaluation harness

Building an agent is one thing; knowing whether it actually works is another. An **evaluation harness** runs an agent...

agentsevaluationtesting
advanced

Cost-tracking middleware for agent tool calls

Agent systems can burn through API budgets fast. Every LLM call, every tool invocation, every retry costs tokens and...

agentscost-trackingmiddleware
intermediate

Api Async (23)

Retry a provider call with timeout and backoff

Implement an async wrapper that retries retryable provider failures with a timeout and bounded backoff.

api-asyncretriesprovider-ops
medium

Enforce provider timeout defaults from env config

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
medium

Batch provider requests with concurrency limits

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
hard

Build an async health check for provider adapters

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
medium

Throttle background ingestion tasks with backpressure

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
hard

Retry only idempotent ingestion steps

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
hard

Wrap streaming provider responses into stable chunks

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
hard

Implement bounded polling for long-running jobs

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringapi-async
medium

Add health and readiness probes to an LLM service

Kubernetes and cloud load balancers use two distinct probes to manage container lifecycle:

deploymenthealth-checkskubernetes
medium

Enforce per-request token budgets

LLM API costs are linear with token usage. Without enforcement, a single user pasting a 50,000-token document into a...

deploymentcost-managementtoken-budgets
medium

Build a rate limiter for AI API endpoints

LLM API calls are expensive and slow. Without rate limiting at your application layer, a single misbehaving client can...

deploymentrate-limitingapi-async
medium

Implement graceful degradation with fallback tiers

Production AI services fail in partial ways: the primary LLM provider might be rate-limited, the secondary might be...

deploymentreliabilitygraceful-degradation
hard

Generate Kubernetes manifests for an LLM service

Deploying an LLM service to Kubernetes requires careful manifest design. The key differences from a typical web service:

deploymentkubernetescontainerization
hard

Build a health check endpoint for an LLM service

A production LLM service needs two health endpoints with different semantics. A naive `/ping -> 200` is useless — it...

deploymenthealth-checkskubernetes
medium

Implement token-based rate limiting for an LLM API

Request-count rate limiting is insufficient for LLM services. A user sending one 100,000-token request consumes the...

deploymentrate-limitingapi-async
medium

Build a cost monitoring middleware

Without per-request cost tracking, you discover cost problems on the monthly invoice. A cost monitoring middleware...

deploymentcost-monitoringapi-async
medium

Implement distributed tracing spans for LLM calls

Standard application tracing shows HTTP latency. For LLM pipelines you need per-span visibility: retrieval, prompt...

deploymentobservabilitytracing
medium

Implement graceful degradation with multi-level fallback tiers

When the primary LLM provider goes down, the options are: fail hard, use cached responses, try a backup model, or...

deploymentreliabilitygraceful-degradation
hard

Build a persistent semantic cache

An in-memory semantic cache loses all entries on restart. A production semantic cache needs persistence through a...

deploymentcachingsemantic-search
hard

Async provider client with semaphore rate limiting

Running LLM calls serially on a batch is 10–50x slower than running them concurrently. But unlimited concurrency...

api-asyncconcurrencysemaphore
medium

Track token usage and cost per model across async calls

Cost visibility is the first step to cost control. This exercise builds a thread-safe cost tracker that can be used as...

api-asynccost-trackingdecorators
medium

Build an async model fallback chain with latency budget

Provider reliability is imperfect. A fallback chain means one provider failing does not make your feature fail. A...

api-asyncfallbacktimeout
hard

Parse and validate LLM JSON output with extraction fallback

LLMs return almost-JSON. Your parser needs to handle: raw JSON, markdown-fenced JSON, JSON embedded in prose, and...

api-asyncparsingjson-extraction
medium

Data Transformation (16)

Aggregate model latency metrics from JSONL traces

Given a JSONL file of request traces, compute per-model latency averages, P95, and failure counts.

data-transformationmetricsobservability
medium

Summarize token usage by endpoint and model

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
easy

Validate article metadata before publish

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
easy

Group API errors into actionable retry buckets

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
medium

Clean scraped text before chunking

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
easy

Compute rolling latency stats for model routes

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
medium

Prepare dashboard series from daily usage rows

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
easy

Reconcile mismatched event timestamps

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringdata-transformation
medium

Transform JSONL trace logs into aggregated metrics

AI services emit structured logs for every LLM call: model used, input/output token counts, latency, feature name, and...

data-transformationmetricsjsonl
medium

Build a data pipeline with generator composition

Document ingestion pipelines need to process large corpora efficiently. Loading an entire dataset into memory before...

data-transformationgeneratorspipelines
hard

Implement batch processing with rate limiting

Provider APIs enforce rate limits in two dimensions: requests per minute (RPM) and tokens per minute (TPM). Exceeding...

data-transformationrate-limitingbatch-processing
hard

Build an error classification and retry policy engine

AI service calls fail in distinct categories, and each category calls for a different response. A 429 rate limit error...

data-transformationerror-handlingretry-policy
hard

Build a streaming response accumulator for LLM output

Most production LLM APIs support streaming: instead of waiting for the full response, you receive tokens as they are...

data-transformationstreamingllm-output
medium

Compute per-model cost and usage summaries from request logs

Every AI service needs basic cost visibility: which models are being used, how many tokens are flowing through each...

data-transformationcost-trackingtoken-usage
medium

Build a document chunking pipeline with overlap and metadata

Before a document can be embedded and indexed for RAG, it must be split into chunks that fit within the embedding...

data-transformationchunkingrag
medium

Implement a JSONL ingestion pipeline with error isolation

JSONL (JSON Lines) is the standard format for AI datasets, evaluation sets, and training data. An ingestion pipeline...

data-transformationingestionjsonl
hard

Deployment (6)

Evaluation (36)

Compute faithfulness and citation coverage from judge results

Take evaluation outputs and summarize pass rate, faithfulness score, and citation coverage per prompt version.

evaluationmetricsfaithfulness
medium

Compute confusion matrix from classifier review logs

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
medium

Compare benchmark runs and highlight regressions

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
medium

Score prompt variants by pass rate and cost

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
medium

Audit benchmark failures by category

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
medium

Build a review queue from low-confidence outputs

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
medium

Calculate judge agreement on evaluation labels

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringevaluation
hard

Build an LLM-as-judge evaluator

Automated evaluation with a language model as the judge is one of the most important patterns in applied AI...

evaluationllm-judgemetrics
medium

Create a golden dataset test suite

A golden dataset is a curated set of test cases you trust to detect regressions. Build the infrastructure to load, run,...

evaluationtestinggolden-dataset
medium

Implement structured request tracing

Build a span-based tracing system for LLM requests -- the core data collection layer that feeds monitoring dashboards...

evaluationtracingobservability
medium

Build a quality monitoring dashboard data pipeline

Transform raw LLM request traces into hourly quality snapshots suitable for a time-series monitoring dashboard.

evaluationmonitoringobservability
medium

Implement A/B evaluation for prompt variants

Changing a prompt without measuring the impact is one of the most common mistakes in applied AI engineering. Build a...

evaluationa-b-testingprompt-engineering
medium

Build a human feedback collection pipeline

User feedback is the ground truth that calibrates all other evaluation signals. Build a feedback collection and...

evaluationhuman-feedbackannotation
medium

Implement A/B testing for model versions

When you want to test a new model version or prompt in production, rolling it out to all users at once is risky. A/B...

deploymentab-testingexperimentation
medium

Build an LLM call tracer with span export

Observability for LLM applications goes beyond logging. When a user sees a bad response, you need to reconstruct the...

deploymentobservabilitytracing
medium

Track and alert on LLM cost per feature

Without cost visibility, you will discover that your most popular feature is generating $30,000/month in LLM costs via...

deploymentcost-managementobservability
medium

Implement A/B testing for model versions in production

Deploying a new model version without traffic splitting is risky. A/B testing routes a percentage of users to a new...

deploymentab-testingmodel-versioning
medium

Build an observability metrics aggregator

Production LLM services emit request events. An aggregator processes them into the operational metrics that matter:...

deploymentobservabilityevaluation
medium

Build a reference-based BLEU/ROUGE scorer

Reference-based metrics compare generated text to a known-good reference. They are the cheapest automated evaluation...

evaluationmetricsrouge
medium

Compute semantic similarity for evaluation

Embedding-based similarity captures whether two texts mean the same thing even with different wording — essential for...

evaluationsemantic-similarityembeddings
medium

Build a human-in-the-loop annotation queue

Automated evaluation is fast but imperfect. An annotation queue routes only the cases where human judgment adds the...

evaluationhuman-in-the-loopannotation
hard

Implement A/B evaluation framework for prompt variants

Before shipping a prompt change you need evidence it improves the metric that matters, not just anecdotal inspection of...

evaluationab-testingprompt-variants
medium

Build a regression test suite for LLM outputs

A regression suite catches when a change makes previously-passing cases fail. It focuses on non-negotiable behaviors...

evaluationregression-testingtesting
hard

Implement structured logging for AI call traces

Debugging bad AI outputs requires the full call context as a queryable structured event: prompt version, model,...

evaluationobservabilitystructured-logging
medium

Trace an agent decision chain

A bad final answer might trace back to a wrong tool call in step 2, caused by a misinterpreted instruction in step 1....

evaluationagentstracing
hard

Build a cost and latency dashboard aggregator

Without visibility into cost per feature and per model, you cannot make rational optimization decisions for production...

evaluationobservabilitycost-tracking
medium

Build a multi-metric eval pipeline

Production evaluation rarely relies on a single metric. A useful pipeline runs several scorers in parallel, aggregates...

evaluationmetricspipeline
hard

Implement a prompt version registry

When you run A/B evals or regression tests across prompt versions, you need a lightweight registry that ties eval...

evaluationprompt-managementversioning
medium

Implement a quality threshold gate for CI

An eval harness only protects your system if it blocks bad deployments. This exercise builds the gate that translates...

evaluationci-cdquality-gate
medium

Build an eval result storage and comparison layer

Eval results are only useful if you can compare them across runs. This exercise builds the persistence and comparison...

evaluationstoragecomparison
medium

Implement token-level faithfulness scoring

Faithfulness measures whether a generated answer is supported by the retrieved context. A simple approach checks...

evaluationfaithfulnessmetrics
hard

Build a production quality alert system

Quality alerts should trigger on patterns, not individual events. A single bad response is noise. A 10% decline in pass...

evaluationmonitoringalerting
hard

Implement an evaluation configuration loader

Eval pipelines need configuration: which metrics to run, what thresholds to enforce, which model to use as the judge,...

evaluationconfigurationvalidation
easy

Implement a sampling strategy for production evaluation

You cannot run an expensive LLM judge on every production request. A good sampling strategy applies the expensive...

evaluationsamplingproduction
medium

Implement a judge calibration pipeline

You have an LLM-as-judge that scores RAG responses for faithfulness, but you don't know if it agrees with humans. Build...

evaluationcalibrationllm-judge
hard

Build an evaluation-driven development workflow

Evaluation-driven development means: write the eval before you write the feature, then use eval results to guide every...

evaluationci-cdregression-testing
medium

Llm Foundations (6)

Prompt Formatting (5)

Python Ai (6)

Python Refresh (16)

Normalize provider payloads into a typed response model

Write a function that accepts a loose provider response and returns a normalized typed payload with explicit error...

python-refreshvalidationapi-boundary
easy

Parse JSONL benchmark rows into normalized records

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Build a slug generator for lesson and project records

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Parse CLI args for an evaluation runner

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Write a pathlib-based artifact export helper

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Map provider enums into internal response states

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Serialize experiment configs to reproducible snapshots

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Protect temp files during dataset generation

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringpython-refresh
easy

Validate LLM structured output with Pydantic

LLMs frequently return structured data that does not perfectly match what you asked for. A model asked to extract...

python-refreshpydanticllm-output
medium

Build a streaming token accumulator

LLM providers stream responses as a sequence of small delta chunks. Each chunk contains a fragment of the final...

python-refreshstreaminggenerators
medium

Implement token counting and cost tracking

Token usage is the billing unit for every major LLM API. Without explicit tracking, AI features run with no cost...

python-refreshcost-trackingtoken-counting
medium

Build a type-safe configuration loader for AI services

AI services have more configuration surface than typical web backends: model names, temperature, token limits, provider...

python-refreshpydanticconfiguration
medium

Build a type-safe config loader from environment variables

AI services are configured through environment variables: API keys, model names, timeout values, rate limits, feature...

python-refreshpydanticconfig
medium

Parse and extract structured data from LLM JSON responses

LLMs asked to return JSON do so imperfectly. They wrap output in markdown code fences, add explanatory prose before the...

python-refreshpydanticjson-parsing
medium

Count tokens accurately for prompt budget management

Token counting is a foundational skill in AI engineering. You need it to prevent context window overflow, to estimate...

python-refreshtoken-countingcontext-management
medium

Implement batch processing with configurable rate limiting

Production AI systems routinely send thousands of requests to provider APIs. Without rate limiting, you hit 429 errors,...

python-refreshrate-limitingbatch-processing
hard

Rag Systems (6)

Retrieval (15)

Score retrieval candidates with metadata boosts

Combine vector similarity and metadata weighting into a final retrieval score for candidate chunks.

retrievalrankingrag
medium

Detect malformed retrieval chunks before indexing

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
medium

Merge keyword and vector retrieval results

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
medium

Filter retrieval contexts by recency and source type

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
easy

Assemble citation spans from retrieved snippets

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
hard

Rank support documents with freshness boosts

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
medium

Deduplicate retrieval candidates across indexes

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
medium

Expand metadata filters into SQL-ready conditions

Implement this task with explicit validation, predictable output shape, and enough error handling that it could survive...

phase-1ai-engineeringretrieval
medium

Build a context window assembler for RAG prompts

One of the most underestimated problems in production RAG is fitting retrieved chunks into the LLM context window...

retrievalragcontext-window
medium

Implement RAG answer generation with inline citations

Most RAG implementations generate an answer and separately display source documents, with no connection between a...

retrievalragcitations
medium

Build a RAG evaluation harness with Recall@K and MRR

You cannot improve what you cannot measure. Most RAG pipelines are deployed and then tuned based on user complaints —...

retrievalragevaluation
medium

Implement query expansion for improved RAG recall

Users do not always phrase their questions the way your documents phrase their answers. A user asks "how do I cancel my...

retrievalragquery-expansion
medium

Build a production RAG pipeline with caching and fallbacks

A RAG pipeline that works in a demo rarely survives its first month in production. The embedding API goes down. The...

retrievalragproduction
hard

Implement BM25 keyword search from scratch

Every production RAG system uses hybrid search — vector (semantic) retrieval combined with keyword (BM25) retrieval....

retrievalragbm25
medium

Build a multi-stage RAG pipeline with query routing

Not all queries are the same. "What is our refund policy?" is a simple factual lookup. "Compare our Q3 2023 and Q4 2023...

retrievalragrouting
hard