Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

AI Agent Tooling Architecture Patterns

This document synthesizes the architectural patterns found in the tool-calling systems of various AI coding agents (Qwen Code, Claude Code, Aider, OpenCode, OpenClaude, OpenClaw, Superpowers, and Open WebUI). It moves from the cognitive process of tool selection to a generalized map of how LLMs discover, invoke, and are constrained in their use of tools.

1. The Cognitive Mechanism of Tool Selection

The ability of an LLM to “know” when to call a tool is not a single feature, but a synergy between training-time capabilities and runtime context. It can be likened to the difference between knowing how to use a toolkit and knowing which specific tool in the box fits the current bolt.

1.1 Behavioral Intuition (Fine-Tuning)

Tool-calling is primarily driven by specialized fine-tuning on tool-calling trajectories. Models are not just trained on static text, but on sequences that mirror the “Reason →\rightarrow Act →\rightarrow Observe” loop:

Example Trajectory:

This instills a behavioral pattern: when the model identifies a gap in its internal knowledge (e.g., “I don’t know what’s in main.py”), its first instinct is to trigger a tool call rather than hallucinating an answer.

1.2 Semantic Mapping (The Catalog)

At runtime, the LLM treats the tool registry as a semantic catalog. This is akin to reading the labels on tools in a box to find the right match. The process follows a specific cognitive pipeline:

  1. Intent Analysis: The model decomposes the user request to identify the core objective (e.g., “The user needs to search for text”).

  2. Catalog Scan: It performs a semantic match between the objective and the description fields of available tools.

  3. Constraint Evaluation: It checks for negative steering (e.g., “DO NOT use this tool for X”) to refine the selection.

  4. Call Generation: It maps the required arguments to the tool’s parameterSchema.

Summary: Cognitive Tool-Calling Components

ComponentRoleAnalogy
Fine-TuningTeaches the concept of tool use and the syntax of calling them.Learning how to use a toolkit in general.
System PromptProvides the specific list of available tools and their purposes.Reading the labels on the tools in the current box.
DescriptionsProvides the logic for when to pick one tool over another.The “User Manual” explaining which wrench fits which bolt.
GuardrailsEnsures the execution is safe and the arguments are valid.A safety inspector checking the tool isn’t broken before it’s used.

2. Tool Definition Strategies

There are three primary ways agents define the “surface” of their capabilities:

2.1 Declarative Type-Safe Definitions (The “Engineering” Approach)

Used by Qwen Code, Claude Code, OpenClaude, and Open WebUI. Tools are defined using structured metadata—either via explicit schema objects or inferred from language constructs.

2.2 Schema-Driven Dictionaries (The “Flexible” Approach)

Used by Aider. Tools are defined as raw JSON schema dictionaries.

2.3 Behavioral “Prompt-Tools” (The “Instructional” Approach)

Used by Superpowers. Tools are not functions, but behavioral contexts (Skills).


3. Tool Discovery and Context Management

Managing the “token budget” of the system prompt is a critical constraint in tool design.

3.1 The Central Registry (Static Discovery)

Used by Qwen Code and OpenCode. All available tools are registered in a central hub and injected into every request.

3.2 Deferred Loading (Dynamic Discovery)

Used by Claude Code and OpenClaude. The agent only loads a minimal “discovery” toolset initially.

3.3 Scoped Tool Surfaces (Identity-Based Discovery)

Used by OpenClaw. The available toolset is a function of the user’s identity and the current session role.


4. Execution and Orchestration

The gap between the LLM’s “request to call” and the actual “system effect” is managed through different orchestration patterns.

4.1 The Reason →\rightarrow Act →\rightarrow Observe Loop

The standard pattern used by nearly all agents (Qwen Code, Aider, OpenCode).

4.2 Concurrency Partitioning (Safe vs. Mutating)

Used by OpenClaude and Qwen Code. Tools are categorized by their side-effects.

4.3 Decoupled Gateway Execution

Used by OpenClaw. The LLM doesn’t call the tool; it requests the gateway to do it.


5. Safety, Validation, and Steering

To prevent hallucinations and destructive actions, agents employ multi-layered guardrails.

5.1 Steering vs. Validation

A critical distinction in tool-calling architecture is the timing and purpose of constraints. This is the difference between a User Manual (guiding the choice) and a Safety Inspector (blocking the action).

5.2 The Three-Tier Steering Model

Modern coding agents (Qwen Code, Claude Code, OpenClaw) implement a hierarchical approach to steering, organizing constraints by their scope to prevent prompt pollution.

5.3 Advanced Steering Patterns

PatternExample AgentDescriptionPrimary Goal
Coder ProtocolAiderUsing strictly formatted output blocks (e.g., SEARCH/REPLACE) instead of native function calls.Precision in editing
Distributed SteeringClaude CodePairing each tool with a dedicated prompt.ts for imperative constraints.Reduced prompt bloat
Sectional CompositionOpenClawUsing PromptMode to dynamically assemble the prompt from modular sections.Scaling complexity
Skill-Based SteeringOpenClaudeGrouping tools into “Skills” with semantic when_to_use and allowed-tools metadata.Tool-overload prevention
Template-BasedOpenCodeInjecting runtime environment data (OS, shell) into tool descriptions.Reduced hallucinations
Permission-GatedOpenCodeEnforcing modality via hard API-level tool restrictions (deny edit tools for ‘planner’).Strict isolation
Structural ContextAiderUsing graph-based ranking (RepoMap) to inject a structural “compass” of the project.Large-repo navigation

5.4 The Validation Pipeline

The transition from “string arguments” to “system execution” is guarded by a pipeline.


Summary Comparison Table

PatternRepresentative AgentCore MechanismPrimary Goal
DeclarativeQwen Code, OpenClaudeZod →\rightarrow JSON SchemaType Safety
DeferredClaude CodeToolSearch →\rightarrow LoadToken Efficiency
ScopedOpenClawPolicy Pipeline →\rightarrow FilterSecurity/Isolation
PartitionedOpenClaudeSafe vs. Mutating batchesPerformance/Integrity
SteeredClaude Code, Qwen Code“NEVER” in descriptionsCorrect Tool Selection