Back to .md Directory

Agent Design Fundamentals

Defines core agent components, control loop pseudocode, autonomy levels, memory strategies, safety considerations, and design anti-patterns for building AI agents.

May 2, 2026
0 downloads
0 views
ai agent llm rag prompt eval guardrails safety
View source

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

ComponentResponsibilityExample
PerceptionNormalize/parse inputsUser text → structured intent
PlanningBreak goal into stepsHigh-level plan tree
MemoryPersist relevant infoConversation history store
ToolingExtend capabilitiesWeb search, DB query
ReasoningInfer intermediate statesHypothesize missing facts
Action ExecutionPerform stepCall API, write file
EvaluationScore outputsJSON validity, factuality
GovernanceEnforce policiesOutput 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

  1. Scripted sequence
  2. Tool suggestions (human approve)
  3. Semi-autonomous loops (bounded iterations)
  4. Fully autonomous with guardrails & budget caps

Memory Strategy

TypeLifetimeStorage
WorkingSingle loopIn-prompt tokens
Short-termSessionRedis / in-memory buffer
Long-termPersistentVector store + metadata

Safety Considerations

  • Explicit tool allowlist
  • Hard iteration cap
  • Cost/time budget enforcement
  • Output classification (toxicity / PII)

Design Anti-Patterns

Anti-PatternWhy HarmfulAlternative
Monolithic giant promptUnmaintainable, costlyLayered modular prompts
No evaluation loopStagnant qualityGolden set regression eval
Blind tool executionSecurity riskValidate tool schema & intent
Infinite loopsResource drainIteration + 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.py with your own project's agent module path
  • Replace src/tools/registry.py with your own tool registration module
  • Replace src/eval/metrics.py with 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