A Production Engineering Guide to Reliable, Secure, Observable Agents on DeepSeek Models
Introduction: The Reliability Gap
- What a harness is
- What DeepSeek Harness actually is
- The thesis
- The reference implementation
- How to read this book
Part I: Foundations and Architecture
Chapter 1: What an Agent Is and When You Should Not Build One
- The loop, in twelve lines of pseudocode
- Workflows versus agents: who holds the control flow
- The four-way trade-off: capability, cost, latency, variance
- A decision procedure and four escape hatches
- Anti-patterns, part one
- Pulling the threads together
Chapter 2: DeepSeek Models as an Engineering Substrate
- Why the serving cost is low and what that buys you
- Two models, two control planes
- Reasoning modes and the invariant that breaks naive loops
- Tool calling on the wire
- One million tokens is not an excuse
- Hosted-endpoint failure modes
- Pulling the threads together
Chapter 3: Inside the Harness. Architecture of DeepSeek Harness
- Cordis in one page
- Component map
- The life of a turn
- Three event planes
- Extension points, ranked by how much you will use them
- Where the harness stops
- Reading the source without drowning
- Pulling the threads together
Chapter 4: First Agent. Scaffold, Config and the Loop
- Repository layout and dependency pinning
- Typed settings and environment configuration
- The client wrapper
- Running one turn and reading what happened
- Structured output is a reliability primitive, not a convenience
- A Makefile you will actually use
- A debugging session, because it will be your first one
- Pulling the threads together
Chapter 5: Tools. Contracts, Registries and Consequences
- The split that defines your architecture
- The tool contract in the harness
- The result envelope
- Registry, scoping and least capability
- Parallel tool calls and why ordering is a trap
- Idempotency, or how to survive a retry you did not choose
- Error taxonomy, the highest-leverage page in the book
- A code review, abridged
- Pulling the threads together
Chapter 6: Context Engineering and Token Budgets
- Anatomy of a prompt
- Token accounting you can trust
- The compaction ladder
- Prompt caching is an architecture, not a flag
- What long context actually costs you
- Diagnosing a context problem from traces
- Pulling the threads together
Chapter 7: Memory and State
- Three kinds of state and why conflating them is the bug
- Conversation state: what the harness already does
- Task state: the part nobody designs
- Checkpointing and resumability
- Goals, todos and the difference between them
- Durable memory that does not poison
- Retrieval-backed memory versus always-in-context memory
- Anti-patterns, part two
- Pulling the threads together
Chapter 8: Retrieval and Knowledge Bases
- Retrieval is a tool, not a pipeline
- Chunking that respects structure
- Hybrid search, in the database you already have
- Embeddings, reranking and their costs
- Permissions are a retrieval problem
- Evaluating retrieval on its own
- When retrieval is the wrong answer
- Pulling the threads together
Chapter 9: Planning and Reasoning
- Thinking mode is a cost dial, not a quality switch
- The effort ladder and where it surprises you
- The parameters that silently do nothing
- The echo invariant and why a harness is the place to fix it
- Planning: three mechanisms and which one to use
- Plan-then-execute is usually the wrong shape
- Structured output while thinking
- Reading reasoning without believing it
- Pulling the threads together
Chapter 10: Orchestration, Queues and Long-Running Agents
- Two loops and the seam between them
- The queue and why not the harness scheduler
- Long-running agents
- Background jobs and subprocesses the harness already manages
- Event-driven wakeups
- Cancellation that actually works
- Pulling the threads together
Chapter 11: Multi-Agent Systems and When Not to Have Them
- The tax, stated precisely
- What the harness actually gives you
- Permissions are the real reason to delegate
- The workflow engine and its one sharp edge
- Three patterns that earn their cost
- Patterns that do not
- Debugging a delegation tree
- Pulling the threads together
Chapter 12: Coding and Computer-Use Agents
- The filesystem contract is the interesting part
- Search strategy: grep is not a fallback
- Shell discipline
- Postmortem 0003: the verification gap
- Postmortem 0004: attribution requires independent evidence
- Computer use and browser use
- Pulling the threads together
Part II: Reliability and Security
Chapter 13: Containment. Budgets, Loops and Runaway Agents
- The reliability contract
- Deterministic boundaries
- Five independent ceilings
- Infinite loops: four signatures
- Runaway agents and the blast-radius ledger
- Timeouts at every layer and the gap
- Idempotency and transactional effects
- What the harness gives you and what it does not
- Pulling the threads together
Chapter 14: Recovery. Retries, Fallbacks and Degraded Modes
- A closed vocabulary of failure
- Retries and the retry budget
- The 429 arithmetic
- Circuit breakers for tools
- Model fallback and what it costs you
- Degraded modes, defined in advance
- Dead letters and the human queue
- Concurrency control and the write-conflict problem
- Pulling the threads together
Chapter 15: Security I. Injection, Taint and Exfiltration
- The threat model, in one page
- Prompt injection is an authority problem
- How good are the defences, honestly?
- Taint tracking: the mechanism nobody ships
- Exfiltration: enumerate the channels
- SSRF, the agent-shaped version
- Malicious tool results, by name
- Pulling the threads together
Chapter 16: Security II. Isolation, Credentials and Tenancy
- What the sandbox is and what it is not
- Permission presets: the unit you should be configuring in
- The profile trap
- Credentials: the model must never hold one
- Network isolation: the container is the boundary
- Tenant isolation, three ways
- Audit logging that survives the incident
- Supply chain: plugins are code with your permissions
- The checklist and the assumption to make
- Pulling the threads together
Chapter 17: Evaluation. Knowing Whether It Got Better
- The measurement problem, stated honestly
- Your harness is a variable, not a constant
- Three tiers of assertion
- Building the eval set from production, not from imagination
- Regression detection: what changed and how do you know
- Replaying a trajectory and why the harness makes it possible
- Online evaluation: the part the eval set cannot do
- Anti-patterns in evaluation
- Pulling the threads together
Chapter 18: Observability. Traces, Trajectories and Cost
- The session log is the trace
- Spans and the vocabulary that maps onto them
- Structured logs, with the right keys
- The OTel seam and its channel discipline
- Redaction: the seam that ships empty
- Trajectory inspection: the tool that pays for itself
- Failure classification in production
- Debugging sessions: four real shapes
- Pulling the threads together
Part III: Performance, Deployment and Operations
Chapter 19: Performance and Cost Engineering
- The cost model, worked end to end
- Prompt caching as an architectural constraint
- Reasoning tokens: the biggest single lever
- Latency and where it actually goes
- Throughput and the concurrency ceiling
- Self-hosting: do the arithmetic before the architecture
- Quantisation and where it stops being free
- Total cost of ownership, honestly
- Pulling the threads together
Chapter 20: Deployment. Containers, Configuration and Graceful Shutdown
- What you are actually deploying
- The image
- Configuration: the layering trap, revisited operationally
- Secrets
- Health checks that mean something
- Graceful shutdown, the actual problem
- Rolling deployments and version skew
- Local deployment, because some of this runs on a laptop
- Backups and the recovery drill
- Pulling the threads together
Chapter 21: Scaling and Production Operations
- The four axes
- Autoscaling on a metric that means something
- Worker architecture and queue partitioning
- Postgres, the real bottleneck
- Multi-tenancy at scale
- Five runbooks
- What is different about on-calling an agent
- Cost governance
- Pulling the threads together
Chapter 22: Advanced Architectures and Choosing Your Level of Abstraction
- What a harness is actually for
- The comparison, done as architecture rather than as a league table
- The deterministic-first architecture, restated properly
- Harnesses as research, not as scaffolding
- The attribution ledger
- What I would change about Sentinel
- Migration and the volatility caveat
- Pulling the threads together
Part IV: The Audit
Chapter 23: From Prototype to Production. The Audit
- The prototype, described honestly
- Remove
- Constrain
- Redesign
- Replace
- A worked failure analysis: the duplicate pull request
- The migration order and why that order
- Before and after
- The go/no-go checklist
- Pulling the things together
Conclusion: The Discipline
- What DeepSeek Harness actually is
- The ledger, one more time
- What is genuinely hard, still
- What to do on Monday
- The last argument