← Reference · Nestor G Pestelos Jr

Reference Document

Agents

A citable ground-truth reference on Autonomous Agents: MDP formulation, perception-action-reflection loops, tool calling protocols, memory tiers, and multi-agent orchestration.

Companion Formats & Essays

Jump to Section

1. Formal Definition & Mathematical Model

An AI Agent is an autonomous computational system that perceives its environment through multimodal sensors/context inputs, maintains internal state and goals, formulates sequential reasoning plans, and executes discrete actions via external tools to affect environmental state across multi-turn trajectories.

Formally, an agent operates within a Partially Observable Markov Decision Process (POMDP) defined by the tuple:

$$\mathcal{M} = \langle \mathcal{S}, \mathcal{A}, \mathcal{O}, \mathcal{T}, \mathcal{Z}, \mathcal{R}, \gamma \rangle$$

The agent parameterizes an autoregressive policy $\pi_\theta(a_t \mid h_t)$ conditioned on the cumulative trajectory history $h_t = (o_0, a_0, o_1, a_1, \dots, o_t)$, optimizing expected cumulative utility:

$$\pi^* = \arg\max_\pi \mathbb{E}\left[ \sum_{t=0}^T \gamma^t \mathcal{R}(s_t, a_t) \;\Bigg|\; a_t \sim \pi(\cdot \mid h_t) \right]$$

2. The Four Core Agent Subsystems

1. Planning & Reasoning Core:

Decomposes high-level natural language objectives into executable DAGs (Directed Acyclic Graphs) of sub-tasks. Utilizes tree search (MCTS/ToT), linear rationales (CoT), or dynamic replanning upon encountering unexpected environment errors.

2. Memory Hierarchy:

3. Tool & Action Interface:

A deterministic bridge translating LLM-generated JSON/symbolic tokens into RPC, HTTP, or POSIX system calls, capturing outputs and packing them back into observations.

4. Environment & Sensor Ingestion:

Parsers converting unstructured external state (file diffs, DOM trees, compiler logs) into clean, token-efficient, schema-validated prompt payloads.

3. Execution Loops (ReAct, Reflexion, Plan-and-Solve)

ReAct Loop (Yao et al., 2022):

Interleaves internal deduction with external interaction in a continuous three-phase step: $$\text{Thought}_t \to \text{Action}_t \to \text{Observation}_t \to \text{Thought}_{t+1}$$ Prevents error compounding by grounding each reasoning step against real-time environment observations rather than hallucinating world transitions.

Reflexion (Shinn et al., 2023):

Introduces episodic self-reflection across trials. When a trajectory fails validation ($\mathcal{R}=0$), a reflection model analyzes the error trace and generates a natural language self-critique $r \in \mathcal{L}$, which is prepended into working memory for the next trial: $$h_{t}^{\text{trial } k+1} = h_0 \circ r_k \circ (o_0, a_0, \dots)$$

Plan-and-Solve (Wang et al., 2023):

Separates strategic planning from tactical execution. A planner agent produces a static sub-task list, and an executor agent executes each task sequentially, updating plan progress after each verification gate.

4. Tool Calling Protocols & Sandboxing

Modern agents interact with host operating systems via standardized tool calling protocols (e.g., Anthropic Tool Use API, OpenAI Function Calling, MCP — Model Context Protocol).

// Formal Tool Schema Specification (JSON Schema)
{
  "name": "replace_file_content",
  "description": "Edits an existing file via exact block match replacement.",
  "parameters": {
    "type": "object",
    "properties": {
      "target_file": { "type": "string", "description": "Absolute path" },
      "target_content": { "type": "string", "description": "Exact text to replace" },
      "replacement_content": { "type": "string", "description": "New content" }
    },
    "required": ["target_file", "target_content", "replacement_content"]
  }
}

Sandboxing & Execution Safety:

5. Multi-Agent Topologies & Orchestration

Complex workflows exceed the context window and cognitive capacity of a single monolithic agent. Multi-agent systems distribute work across specialized agent nodes.

Hierarchical (Supervisor-Worker):

An orchestrator decomposes the primary goal, spawns specialized subagents (e.g., Code Searcher, Test Writer, Refactorer), collects structured results, and handles task transitions. Subagent context windows remain clean and focused.

Sequential Pipeline (Assembly Line):

Output of Agent $A$ (e.g., Architectural Spec) forms the input prompt for Agent $B$ (Code Implementation), which passes artifacts to Agent $C$ (Security Auditor).

Blackboard Architecture:

Multiple autonomous agents read from and write to a shared, persistent state repository (e.g., a shared git repository or KV store) asynchronously without point-to-point message routing.

Multi-Agent Debate & Consensus (Du et al., 2023):

Multiple independent agents generate candidate solutions and critique each other's outputs across debate rounds, converging on truth via adversarial peer review.

6. Failure Modes & Defensive Guardrails

Failure Mode Root Cause Defensive Mitigation
Infinite Error-Fix Loops Agent encounters tool failure, reprompts with identical strategy, and exhausts token budget. Anti-loop watchdog counters; deterministic circuit breaker after $N=3$ identical errors.
Context Contamination Verbose tool outputs (gigabyte logs, minified JS) push system instructions out of effective attention span. Observation truncation, intermediate summarization, and ephemeral subagent scoping.
Compounding Trajectory Drift Small incorrect assumption at Step 1 snowballs into invalid refactors by Step 10. Plan-gate verification: enforcing test assertions before advancing to subsequent sub-tasks.
Indirect Prompt Injection Agent reads untrusted webpage/file containing malicious override instructions. Dual-LLM reader-actor privilege separation; XML boundary delimiters.

7. Architecture Comparison Matrix

Architecture Coordination Overhead Context Isolation Fault Tolerance Best Suited For
Monolithic Single-Agent None Low (Single context window) Low (Error halts session) Targeted scripting, single-file edits, interactive chat assistants.
Hierarchical Orchestrator Medium High (Subagents have fresh context) High (Subagent failure isolated) Full-stack software engineering, multi-repo migrations, deep research.
Sequential Pipeline Low Medium (Handoff artifacts) Medium (Stage-gated verification) Content publishing, automated code review & static analysis.
Multi-Agent Debate High High (Independent perspectives) Very High (Consensus filtering) Fact-checking, security vulnerability audits, formal verification.