Leanpub Header

Skip to main content

Building AI Agents That Actually Work with DeepSeek Harness

A Production Engineering Guide to Reliable, Secure, Observable Agents on DeepSeek Models

Building AI Agents That Actually Work with DeepSeek Harness
This book is 100% completeLast updated on 2026-10-06

What does it take to turn an AI agent from a clever demo into something you can trust in production? This hands-on guide uses DeepSeek Harness to show how to build reliable, secure and observable agents, from a simple script to a production-ready service with budgets, tracing, evals and multi-tenant support.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
270
Pages
About

About

About the Book

DeepSeek Harness (`dsh`) is an open-source agent harness that DeepSeek released in 2026 under the MIT license, built on the Cordis plugin framework, where the model adapter, the tool registry, the session log, the sandbox and the agent loop itself are all swappable plugins rather than fixed internals. This book treats it as an engineering substrate: what its components do, how a turn actually executes, where its abstractions help, where they leak and what you must build around it to run agents that a business can depend on. You will follow one reference implementation from a thirty-line script to a budgeted, traced, eval-gated, multi-tenant service and you will see the incidents that forced each change. The audience is experienced software, platform and site-reliability engineers who want implementation-level knowledge rather than a survey.

Author

About the Author

Steve Publications

Steve is a technology professional with over 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. He specializes in analyzing complex systems, identifying weaknesses and improving security.

Beyond his professional work, Steve collaborates with researchers and industry experts to create practical technical books covering software development, cybersecurity, cloud computing, DevOps, AI and enterprise technologies. His goal is to help IT professionals, students and enthusiasts develop practical skills through clear explanations, real-world examples and hands-on exercises.

At Steve Publications, we use AI to assist with translation, proofreading and editing but not to replace the research, technical expertise or hands-on experience behind our books. Some authors publish under pseudonyms for privacy or professional reasons.

Every book is written, reviewed and maintained by experienced professionals, supported by a private community of over 420 engineers and researchers. We prioritize technical accuracy, practical value and regularly updated content over mass-produced AI-generated text.

We welcome experienced professionals interested in writing or reviewing books, especially in specialized and emerging technology fields. If you'd like to contribute, contact us with your area of expertise.

We stand behind our work. If a book doesn't meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

A Production Engineering Guide to Reliable, Secure, Observable Agents on DeepSeek Models

Introduction: The Reliability Gap

  1. What a harness is
  2. What DeepSeek Harness actually is
  3. The thesis
  4. The reference implementation
  5. How to read this book

Part I: Foundations and Architecture

Chapter 1: What an Agent Is and When You Should Not Build One

  1. The loop, in twelve lines of pseudocode
  2. Workflows versus agents: who holds the control flow
  3. The four-way trade-off: capability, cost, latency, variance
  4. A decision procedure and four escape hatches
  5. Anti-patterns, part one
  6. Pulling the threads together

Chapter 2: DeepSeek Models as an Engineering Substrate

  1. Why the serving cost is low and what that buys you
  2. Two models, two control planes
  3. Reasoning modes and the invariant that breaks naive loops
  4. Tool calling on the wire
  5. One million tokens is not an excuse
  6. Hosted-endpoint failure modes
  7. Pulling the threads together

Chapter 3: Inside the Harness. Architecture of DeepSeek Harness

  1. Cordis in one page
  2. Component map
  3. The life of a turn
  4. Three event planes
  5. Extension points, ranked by how much you will use them
  6. Where the harness stops
  7. Reading the source without drowning
  8. Pulling the threads together

Chapter 4: First Agent. Scaffold, Config and the Loop

  1. Repository layout and dependency pinning
  2. Typed settings and environment configuration
  3. The client wrapper
  4. Running one turn and reading what happened
  5. Structured output is a reliability primitive, not a convenience
  6. A Makefile you will actually use
  7. A debugging session, because it will be your first one
  8. Pulling the threads together

Chapter 5: Tools. Contracts, Registries and Consequences

  1. The split that defines your architecture
  2. The tool contract in the harness
  3. The result envelope
  4. Registry, scoping and least capability
  5. Parallel tool calls and why ordering is a trap
  6. Idempotency, or how to survive a retry you did not choose
  7. Error taxonomy, the highest-leverage page in the book
  8. A code review, abridged
  9. Pulling the threads together

Chapter 6: Context Engineering and Token Budgets

  1. Anatomy of a prompt
  2. Token accounting you can trust
  3. The compaction ladder
  4. Prompt caching is an architecture, not a flag
  5. What long context actually costs you
  6. Diagnosing a context problem from traces
  7. Pulling the threads together

Chapter 7: Memory and State

  1. Three kinds of state and why conflating them is the bug
  2. Conversation state: what the harness already does
  3. Task state: the part nobody designs
  4. Checkpointing and resumability
  5. Goals, todos and the difference between them
  6. Durable memory that does not poison
  7. Retrieval-backed memory versus always-in-context memory
  8. Anti-patterns, part two
  9. Pulling the threads together

Chapter 8: Retrieval and Knowledge Bases

  1. Retrieval is a tool, not a pipeline
  2. Chunking that respects structure
  3. Hybrid search, in the database you already have
  4. Embeddings, reranking and their costs
  5. Permissions are a retrieval problem
  6. Evaluating retrieval on its own
  7. When retrieval is the wrong answer
  8. Pulling the threads together

Chapter 9: Planning and Reasoning

  1. Thinking mode is a cost dial, not a quality switch
  2. The effort ladder and where it surprises you
  3. The parameters that silently do nothing
  4. The echo invariant and why a harness is the place to fix it
  5. Planning: three mechanisms and which one to use
  6. Plan-then-execute is usually the wrong shape
  7. Structured output while thinking
  8. Reading reasoning without believing it
  9. Pulling the threads together

Chapter 10: Orchestration, Queues and Long-Running Agents

  1. Two loops and the seam between them
  2. The queue and why not the harness scheduler
  3. Long-running agents
  4. Background jobs and subprocesses the harness already manages
  5. Event-driven wakeups
  6. Cancellation that actually works
  7. Pulling the threads together

Chapter 11: Multi-Agent Systems and When Not to Have Them

  1. The tax, stated precisely
  2. What the harness actually gives you
  3. Permissions are the real reason to delegate
  4. The workflow engine and its one sharp edge
  5. Three patterns that earn their cost
  6. Patterns that do not
  7. Debugging a delegation tree
  8. Pulling the threads together

Chapter 12: Coding and Computer-Use Agents

  1. The filesystem contract is the interesting part
  2. Search strategy: grep is not a fallback
  3. Shell discipline
  4. Postmortem 0003: the verification gap
  5. Postmortem 0004: attribution requires independent evidence
  6. Computer use and browser use
  7. Pulling the threads together

Part II: Reliability and Security

Chapter 13: Containment. Budgets, Loops and Runaway Agents

  1. The reliability contract
  2. Deterministic boundaries
  3. Five independent ceilings
  4. Infinite loops: four signatures
  5. Runaway agents and the blast-radius ledger
  6. Timeouts at every layer and the gap
  7. Idempotency and transactional effects
  8. What the harness gives you and what it does not
  9. Pulling the threads together

Chapter 14: Recovery. Retries, Fallbacks and Degraded Modes

  1. A closed vocabulary of failure
  2. Retries and the retry budget
  3. The 429 arithmetic
  4. Circuit breakers for tools
  5. Model fallback and what it costs you
  6. Degraded modes, defined in advance
  7. Dead letters and the human queue
  8. Concurrency control and the write-conflict problem
  9. Pulling the threads together

Chapter 15: Security I. Injection, Taint and Exfiltration

  1. The threat model, in one page
  2. Prompt injection is an authority problem
  3. How good are the defences, honestly?
  4. Taint tracking: the mechanism nobody ships
  5. Exfiltration: enumerate the channels
  6. SSRF, the agent-shaped version
  7. Malicious tool results, by name
  8. Pulling the threads together

Chapter 16: Security II. Isolation, Credentials and Tenancy

  1. What the sandbox is and what it is not
  2. Permission presets: the unit you should be configuring in
  3. The profile trap
  4. Credentials: the model must never hold one
  5. Network isolation: the container is the boundary
  6. Tenant isolation, three ways
  7. Audit logging that survives the incident
  8. Supply chain: plugins are code with your permissions
  9. The checklist and the assumption to make
  10. Pulling the threads together

Chapter 17: Evaluation. Knowing Whether It Got Better

  1. The measurement problem, stated honestly
  2. Your harness is a variable, not a constant
  3. Three tiers of assertion
  4. Building the eval set from production, not from imagination
  5. Regression detection: what changed and how do you know
  6. Replaying a trajectory and why the harness makes it possible
  7. Online evaluation: the part the eval set cannot do
  8. Anti-patterns in evaluation
  9. Pulling the threads together

Chapter 18: Observability. Traces, Trajectories and Cost

  1. The session log is the trace
  2. Spans and the vocabulary that maps onto them
  3. Structured logs, with the right keys
  4. The OTel seam and its channel discipline
  5. Redaction: the seam that ships empty
  6. Trajectory inspection: the tool that pays for itself
  7. Failure classification in production
  8. Debugging sessions: four real shapes
  9. Pulling the threads together

Part III: Performance, Deployment and Operations

Chapter 19: Performance and Cost Engineering

  1. The cost model, worked end to end
  2. Prompt caching as an architectural constraint
  3. Reasoning tokens: the biggest single lever
  4. Latency and where it actually goes
  5. Throughput and the concurrency ceiling
  6. Self-hosting: do the arithmetic before the architecture
  7. Quantisation and where it stops being free
  8. Total cost of ownership, honestly
  9. Pulling the threads together

Chapter 20: Deployment. Containers, Configuration and Graceful Shutdown

  1. What you are actually deploying
  2. The image
  3. Configuration: the layering trap, revisited operationally
  4. Secrets
  5. Health checks that mean something
  6. Graceful shutdown, the actual problem
  7. Rolling deployments and version skew
  8. Local deployment, because some of this runs on a laptop
  9. Backups and the recovery drill
  10. Pulling the threads together

Chapter 21: Scaling and Production Operations

  1. The four axes
  2. Autoscaling on a metric that means something
  3. Worker architecture and queue partitioning
  4. Postgres, the real bottleneck
  5. Multi-tenancy at scale
  6. Five runbooks
  7. What is different about on-calling an agent
  8. Cost governance
  9. Pulling the threads together

Chapter 22: Advanced Architectures and Choosing Your Level of Abstraction

  1. What a harness is actually for
  2. The comparison, done as architecture rather than as a league table
  3. The deterministic-first architecture, restated properly
  4. Harnesses as research, not as scaffolding
  5. The attribution ledger
  6. What I would change about Sentinel
  7. Migration and the volatility caveat
  8. Pulling the threads together

Part IV: The Audit

Chapter 23: From Prototype to Production. The Audit

  1. The prototype, described honestly
  2. Remove
  3. Constrain
  4. Redesign
  5. Replace
  6. A worked failure analysis: the duplicate pull request
  7. The migration order and why that order
  8. Before and after
  9. The go/no-go checklist
  10. Pulling the things together

Conclusion: The Discipline

  1. What DeepSeek Harness actually is
  2. The ledger, one more time
  3. What is genuinely hard, still
  4. What to do on Monday
  5. The last argument

References

DeepSeek Harness: repository, architecture and subsystems

DeepSeek Harness: orchestration, telemetry and versioning

DeepSeek models, the API and the Cordis paper

Evaluation, security, context and adjacent frameworks

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub