Agent Design Fundamentals
Defines core agent components, control loop pseudocode, autonomy levels, memory strategies, safety considerations, and design anti-patterns for building AI agents.
What this file does
Defines core agent components, control loop pseudocode, autonomy levels, memory strategies, safety considerations, and design anti-patterns for building AI agents.
When to use it
- Designing a new agentic AI system from scratch
- Reviewing an existing agent architecture for gaps
- Teaching agent design patterns to a team
- Evaluating trade-offs between autonomy levels
Agent Design Fundamentals
Core Components
| Component | Responsibility | Example |
|---|---|---|
| Perception | Normalize/parse inputs | User text → structured intent |
| Planning | Break goal into steps | High-level plan tree |
| Memory | Persist relevant info | Conversation history store |
| Tooling | Extend capabilities | Web search, DB query |
| Reasoning | Infer intermediate states | Hypothesize missing facts |
| Action Execution | Perform step | Call API, write file |
| Evaluation | Score outputs | JSON validity, factuality |
| Governance | Enforce policies | Output filter, rate limiter |
Control Loop Pseudocode
while not goal_reached and iterations < max_iters:
observe_state()
plan = planner.decide(next_goal)
if plan.requires_tool:
tool_result = tool_executor.execute(plan.tool, plan.args)
reasoning = reasoner.reflect(plan, tool_result)
updated_state = state_updater.apply(tool_result, reasoning)
if governance.blocked(updated_state):
escalate_or_abort()
Autonomy Levels
- Scripted sequence
- Tool suggestions (human approve)
- Semi-autonomous loops (bounded iterations)
- Fully autonomous with guardrails & budget caps
Memory Strategy
| Type | Lifetime | Storage |
|---|---|---|
| Working | Single loop | In-prompt tokens |
| Short-term | Session | Redis / in-memory buffer |
| Long-term | Persistent | Vector store + metadata |
Safety Considerations
- Explicit tool allowlist
- Hard iteration cap
- Cost/time budget enforcement
- Output classification (toxicity / PII)
Design Anti-Patterns
| Anti-Pattern | Why Harmful | Alternative |
|---|---|---|
| Monolithic giant prompt | Unmaintainable, costly | Layered modular prompts |
| No evaluation loop | Stagnant quality | Golden set regression eval |
| Blind tool execution | Security risk | Validate tool schema & intent |
| Infinite loops | Resource drain | Iteration + timeout cap |
Extensibility Tips
- Use registries for tools & skills
- Keep data schemas explicit (Pydantic or dataclasses)
- Centralize model client selection
Minimal File Layout Example
src/
agents/base.py
llm/clients.py
prompt/templating.py
tools/registry.py
eval/metrics.py
What's inside
8 component descriptions, 1 pseudocode loop, 4 autonomy levels, 3 memory types, 5 safety items, 4 anti-patterns, 1 file layout
Change this for your project
- Replace
src/agents/base.pywith your own project's agent module path - Replace
src/tools/registry.pywith your own tool registration module - Replace
src/eval/metrics.pywith your own evaluation module path
Where it goes
Load as policy context for the agent, or keep beside the code enforcing the rules.
Related Documents
DeepSeek R1: Case Study in Failed Extrinsic Alignment
Compiles public security research and independent findings to argue that extrinsic alignment methods are insufficient for AI safety, using DeepSeek R1 as a case study.
Guardrails, Safety & Content Filtering
Implements a layered guardrail system with input validation, output validation, and content filtering to protect LLM applications from prompt injection, jailbreaks, and data leaks.
My Hyprland Rice Setup - Context for Claude Code
Documents a Hyprland rice setup with system specs, aesthetic preferences, workflow safety practices, and a list of current issues to solve.
AI Safety & Guardrails for Voice Assistants
Defines a multi-layer safety architecture for voice assistants, covering input filtering, deterministic FAQ routing, RAG-grounded AI responses, and output guardrails.