0% read on this device
Browse the curriculum

Start Here

Vision

First Principles

Operating Model

Domain Model

Agent Factory

Runtime Architecture

AI Engineering

Autonomous Workflows

Verification & Delivery

Factory Platform

Quality Engineering

Security & Governance

Case Studies

Labs

Interview Practice

Research Journal

Reference

Curriculum/AI Engineering/A rapid review of the chapter’s existing Quick Read, principles, definitions, lessons, and review material.
AI Engineering18 min readchapterQuick Read

Agent Architecture, MCP, Tools, Context, and Memory

Define the complete, versioned runtime surrounding a model driven engineering worker.

Status: Review readyRisk: highLifecycle: plan · execute · verify · learnContent reviewed 2026-08-30Maturity guide →
Claim boundaryThis is curriculum guidance. It does not by itself prove a production implementation.
study mode

A rapid review of the chapter’s existing Quick Read, principles, definitions, lessons, and review material.

Quick Read

The chapter in one pass.

~4 min
  • Purpose: Define the complete, versioned runtime surrounding a model-driven engineering worker.
  • Best for: AI engineers, architects, platform teams, security reviewers, and technical leaders.
  • Prerequisites: Control Plane and Execution Plane.
  • Reading time: 18 minutes.
  • You will learn: How identity, instructions, model profiles, tools, MCP, context, memory, policy, budgets, state, evidence, and evaluation form one governed agent configuration.

Keep five ideas:

  1. An agent is a runtime composition, not a model with a long prompt.
  2. The model may propose an action; only the runtime may authorize it.
  3. MCP standardizes interoperable sessions and capabilities; it does not grant trust, authority, or acceptance.
  4. Context and memory are governed inputs with provenance and lifecycle, not undifferentiated text.
  5. Reproducibility requires freezing the complete execution manifest and retaining the resulting trace and evidence.

Protocol version note: Normative MCP statements in this chapter are pinned to the stable 2025-11-25 specification. Experimental features are labeled. Draft behavior may change and should not silently redefine a production contract.

Whiteboard exercise

Reconstruct and defend this chapter’s architecture.

Reconstruct the architecture, name each boundary, and defend the tradeoffs.

agent runtimemodelscontext18 min chapter
Jump to validation criteria
Open the source exercise

Draw a host containing an agent runtime, one MCP client per connected server, a context compiler, memory view, model profile, policy gateway, durable state, tool adapters, and an independent evidence path.

Add a malicious repository document that asks the agent to read a synthetic secret and send it to an unapproved remote service. Show:

  • where the content enters as untrusted reference context;
  • which identity, scope, egress, and approval checks deny the action;
  • how the denial and attempted call are recorded;
  • how the agent continues or escalates safely; and
  • which evidence a reviewer receives.

3. Enduring Principle

An agent is a governed runtime composition

An engineering agent is a versioned composition of:

identity + objective + instructions + model profile + tools + context + memory view + policy + budgets + state + evaluation profile

ComponentResponsibilityWhat must be frozen or recorded
IdentityNames the agent role and acting principalAgent version, tenant, user or service principal
ObjectiveStates the bounded outcomeWorkOrder and approved Plan references
InstructionsDefines trusted operating behaviorSystem instructions, skills, workflow versions
Model profileSelects reasoning capabilityProvider, model, parameters, routing policy
Tool grantsDefines possible actionsTool names, versions, scopes, schema hashes
ContextSupplies decision-relevant knowledgeSource revisions, selection reasons, content hashes
Memory viewSupplies governed prior knowledgeSnapshot, query, scope, provenance, lifecycle filters
PolicyLimits authorityPolicy bundle, risk class, required approvals
BudgetsLimits resource useTime, tokens, cost, attempts, concurrency
StateMakes execution durableTask, Attempt, lease, checkpoints, cancellation state
Evaluation profileDefines expected behaviorDataset, graders, thresholds, evidence requirements

Changing any material component changes the worker configuration and may invalidate evidence from an earlier Attempt. A model name alone is never a sufficient reproducibility record.

Separate reasoning from authority

The model can interpret intent, form hypotheses, choose among allowed options, and propose a tool call. It cannot expand its own scope. Before execution, the runtime validates the acting identity, input schema, policy, repository and path scope, risk, budget, approval state, idempotency strategy, and environment.

The result returns as an observation, never as trusted instructions. The runtime records both approved and denied calls so a reviewer can reconstruct what the agent attempted, what actually ran, and why.

Freeze an execution manifest

Every Attempt should resolve mutable configuration into one immutable manifest before work begins. A minimal manifest contains:

attempt_id: attempt-123
work_order_revision: sha256:...
plan_revision: sha256:...
agent_version: agent-implementation-v4
model_profile: code-reasoning-standard-v2
instruction_bundle: sha256:...
tool_grants:
  - name: repository.read_file
    version: 3.2.0
    schema_hash: sha256:...
    scope: read
context_lock: sha256:...
memory_snapshot: sha256:...
policy_bundle: engineering-medium-risk-v5
budgets:
  wall_clock_seconds: 1800
  attempts: 3
evaluation_profile: repository-change-v7

The manifest is a contract, not a log assembled after execution. Runtime events and evidence must point back to it.

MCP is an interoperability boundary

The Model Context Protocol uses a host–client–server architecture over JSON-RPC. The host coordinates model access, consent, security policy, and context. It creates a client for each server connection. The client negotiates protocol version and capabilities, maintains the stateful session, and routes messages. The server exposes focused capabilities.

The stable specification defines stdio and Streamable HTTP transports. A production contract must pin the protocol version, transport, server identity, and negotiated capabilities; “supports MCP” is too vague to be meaningful.

MCP primitives have different control expectations:

PrimitivePrimary purposeTypical control modelFactory treatment
ToolsPerform computation or side effectsModel-controlled, with host/runtime approvalApply schema, scope, risk, budget, and evidence policy
ResourcesExpose addressable data or contentApplication-controlledTreat content and annotations as untrusted; retain URI, revision, and provenance
PromptsExpose reusable message templatesUser-controlledTreat server-supplied instructions as versioned content, not platform authority
SamplingLet a server request model generation through the clientClient-controlled with user oversightConstrain model access, tool loops, context, cost, and approvals
ElicitationLet a server request additional user inputUser-controlledMake the requesting server visible; protect sensitive-data boundaries
TasksRepresent deferred, durable request executionNegotiated; experimental in 2025-11-25Bind task state to authorization context; set TTL, cancellation, polling, and audit rules

Capability negotiation proves that both sides speak a compatible protocol. It does not prove that a server is trustworthy, that a tool is safe, or that the current WorkOrder authorizes its use.

Govern the MCP connection, not only the tool call

An enterprise MCP gateway should require a connection contract with:

ControlRequired decision
Server identityWhich organization, package, binary, endpoint, and version are trusted?
TransportIs the connection local stdio or remote Streamable HTTP, and which network boundary does it cross?
AuthenticationWhich principal is connecting and how is it verified?
AuthorizationWhich server resource is the token intended for, which scopes apply, and can scope increase require new consent?
Capability allowlistWhich tools, resources, prompts, sampling, elicitation, or task features may be negotiated?
Data policyWhat may leave the repository or tenant, and what must be redacted?
Invocation policyWhich calls are read-only, reversible, consequential, or prohibited?
Operational boundsWhat timeout, concurrency, rate, output-size, retry, and cancellation limits apply?
EvidenceWhich request, response, approval, denial, and artifact receipts must be retained?
RevocationHow can a server, capability, credential, or version be disabled immediately?

For HTTP authorization, tokens must be audience-bound to the intended MCP server. Token passthrough to unrelated downstream services collapses trust boundaries and must not be treated as a shortcut.

Each MCP server is simultaneously a software supply-chain dependency, an identity boundary, and a possible data-egress path.

Tools are behavioral contracts

A tool is not safe because its arguments satisfy JSON Schema. Its contract must also define behavior under success, failure, retry, cancellation, and partial completion.

Contract fieldWhy it matters
Input and output schemaMakes validation and downstream interpretation explicit
Acting identityAttributes the action to the correct user, service, and agent
ScopeLimits repositories, paths, records, operations, and environments
Side-effect classSeparates observation from reversible and consequential mutation
IdempotencyPrevents retries from duplicating commits, messages, deployments, or records
Timeout and cancellationBounds abandoned or long-running work
Retry policyDistinguishes safe transient recovery from repeated harmful action
Result envelopeSeparates structured data, human-readable explanation, and error state
Evidence receiptTies the call to inputs, outputs, artifacts, and policy decisions
Version and schema hashMakes behavioral changes detectable and evaluable

Protocol errors and tool-execution errors should remain distinct. A malformed request is different from a valid request whose business operation failed. Structured failures help a model correct an input without hiding operational or policy failure.

Context engineering is controlled compilation

Context compilation selects the smallest sufficient set of trusted directives and relevant observations for a decision. It is not a bulk copy of everything the system can retrieve.

The compiler should process inputs in this order:

  1. Load authoritative intent, Plan, policy, identity, budgets, and exact source state.
  2. Resolve domain terms to canonical concepts and identifiers.
  3. Select applicable instructions, skills, and workflow contracts.
  4. Retrieve candidate repository facts, documentation, history, and memory within tenant, repository, sensitivity, and time boundaries.
  5. Rank candidates by authority, relevance, freshness, diversity, and risk of omission.
  6. Detect duplicates, conflicts, staleness, and unresolved terminology.
  7. Allocate the context budget, preserving governing constraints before optional examples or history.
  8. Emit an ordered context package with source, revision, hash, selection reason, trust class, and truncation record.

Good context architecture keeps five categories visibly separate:

  • instructions: trusted runtime directives;
  • authoritative context: approved contracts, policy, identity, and source state;
  • reference context: documentation and retrieved knowledge;
  • working context: transient hypotheses and scratch state; and
  • evidence: observations tied to exact actions and artifacts.

More context is not automatically better. Irrelevant content consumes tokens, increases conflicting cues, and can hide the governing constraint.

Memory is governed, typed, and revisable

Memory should improve future decisions without becoming a shadow system of record.

Memory typeUseful forMain riskRequired control
SessionCurrent Attempt state and scratch workTreating a hypothesis as factAttempt scope and automatic expiry
EpisodicWhat happened during prior runsCopying a past solution into a different caseArtifact links, outcome, time, and similarity evidence
SemanticClaims, entities, terminology, and relationshipsStale or contradictory knowledgeProvenance, confidence, validity interval, contradiction links
ProceduralSkills, prompts, workflows, and runbooksPromoting an unsafe behaviorEvaluation, ownership, approval, versioning, rollback

A safe lifecycle is:

observe → quarantine → classify → evaluate → approve → publish → retrieve → correct, expire, or revoke

Memory writes should retain source, scope, time, confidence, sensitivity, owner, lifecycle state, and the evidence supporting promotion. Retrieval must filter by the current identity and authority, return citations and “why retrieved,” and expose contradictions rather than silently choosing a winner.

Deletion, correction, expiry, tenant isolation, and permission changes are first-class lifecycle events. Operational records remain authoritative; memory may reference them but must not rewrite them.

Use multiple agents only for a measurable reason

Add another agent when independent verification, parallelism, context isolation, or specialized expertise produces a measurable gain. Do not create agents merely to imitate an organization chart.

Every handoff needs an explicit input contract, output schema, authority, budget, termination condition, and owner. Shared durable state belongs in the runtime, not in private message history. Independent validation requires a separate evidence path, different incentives or tools where appropriate, and protection against correlated failure—not a different persona name.

Evaluate the complete agent configuration and workflow. A model benchmark alone cannot show whether context selection, tool policy, memory, recovery, or multi-agent coordination works.

8. Notes and lessons learned

  • Context locks make invisible behavioral inputs versioned and attributable.
  • Schema validation is necessary but cannot express the complete behavioral or authority contract of a tool.
  • Protocol capability and organizational permission are separate decisions.
  • Memory quality depends more on write admission and correction than on vector search quality.
  • Traceability improves only when records share stable Attempt, manifest, artifact, and policy identifiers.
  • A small governed agent is usually safer and easier to improve than a large agent whose tools, memory, and context continually expand.

9. Interview and discussion questions

  1. What makes an agent different from a model invocation or provider-managed conversation?
  2. Which inputs must an execution manifest freeze, and which runtime events must refer back to it?
  3. What does MCP standardize, and which governance decisions remain with the host and factory runtime?
  4. How do tools, resources, prompts, sampling, elicitation, and tasks differ?
  5. Why are JSON Schema validation and capability negotiation insufficient authorization controls?
  6. How do you prevent retrieved text, tool descriptions, and tool results from becoming authority?
  7. What makes a retry safe for a consequential tool?
  8. How should memory contradictions, correction, expiry, and revocation work?
  9. When is multi-agent orchestration justified?
  10. Which evidence would prove that one complete agent configuration is safer or more effective than another?
External review

Review this chapter.

Challenge a claim, boundary, missing failure mode, unclear term, or unsupported evidence statement.

  • Claim
  • Boundary
  • Failure
  • Evidence