← GUIDES

GUIDE / ARCHITECTURE / FIELD GUIDE

AI Agent Architecture: The Parts Every Setup Shares

Seven parts sit around one control loop in every working single-agent setup. Learn what each one does, what to record for it, and how to test it.

AI agent architecture: seven parts around one control loopSeven parts arranged around one control loop, numbered from the top. The parts and their questions are listed in order after the diagram.CONTROLloop01TriggerWhat starts a run?02ModelWhat chooses thenext action?03ToolsWhat can the agentobserve or change?04Memory and stateWhat survives eachturn?05GuardrailsWhat may enter,happen, and leave?06Human gateWhere must aperson decide?07Output sinkWhere does theresult go?
AI agent architecture: seven parts around one control loopSeven parts arranged around one control loop, numbered from the top. The parts and their questions are listed in order after the diagram.CONTROLloop01TriggerWhat starts a run?02ModelWhat chooses the next action?03ToolsWhat can the agent observe orchange?04Memory and stateWhat survives each turn?05GuardrailsWhat may enter, happen, andleave?06Human gateWhere must a person decide?07Output sinkWhere does the result go?
  1. Trigger: what starts a run?
  2. Model: what chooses the next action?
  3. Tools: what can the agent observe or change?
  4. Memory and state: what survives each turn?
  5. Guardrails: what may enter, happen, and leave?
  6. Human gate: where must a person decide?
  7. Output sink: where does the result go?
01

A model call by itself is not an agent.

02

Do not hide the model name only in application defaults.

03

Tool access should be narrower than the surrounding process whenever possible.

04

choose one authoritative history strategy for each conversation

05

The reviewed arguments matter.

06

Treat sink delivery as its own operation.

07

Then trace one real task through every row.

Examples draw on mini-SWE-agent by Kilian A. Lieret, Carlos E. Jimenez and the SWE-agent team, Claude Code Action by Anthropic, the OpenAI Agents SDK by OpenAI, GPT Researcher by Assaf Elovic and contributors, and Open SWE by LangChain. Checked 22 Oct 2026.

AI agent architecture can look different from project to project. A coding agent may start from a GitHub issue, while a research agent starts from a question. One edits files and another writes a cited report.

Under those differences, working single-agent systems tend to share the same seven parts:

  1. A trigger
  2. A model
  3. A tool layer
  4. Memory or state
  5. Guardrails
  6. A human gate
  7. An output sink

These parts form a control loop around the model. The model proposes what to do, the surrounding application decides what it may do, tools perform permitted actions, and the resulting observations become input to the next turn.

This guide explains that architecture as a practical system you can inspect. It stays with one agent and one control loop. Multi-agent delegation and handoffs are a separate architectural layer.

The smallest useful agent loop

A model call by itself is not an agent. It becomes part of an agent when application code repeatedly gives the model context, interprets its response, executes allowed actions, and returns observations.

The default mini-SWE-agent makes that loop unusually visible. Its step() method queries a model and then executes the actions in the response:

python
def step(self) -> list[dict]:
    """Query the LM, execute actions."""
    return self.execute_actions(self.query())

Its documented control flow continues until a message with the exit role is added. Model responses and formatted environment observations are added to the message history between iterations. (mini-SWE-agent control flow) The project's structure separates the same responsibilities into folders: agents for control flow and the loop, models for the language model interfaces, and environments for executing actions. (mini-SWE-agent project structure)

A generic single-agent loop therefore looks like this:

text
receive trigger
load state
build model input
call model

while response requests an action:
    validate requested action
    pause for approval if required
    execute permitted tool
    record observation
    call model again

validate final result
write result to output sink
record final state

This is an architectural sketch, not executable configuration. Frameworks give these stages different names, but the boundaries are what matter.

The seven parts of an AI agent architecture

AI agent architecture: seven parts around one control loopSeven parts arranged around one control loop, numbered from the top. The parts and their questions are listed in order after the diagram.CONTROLloop01TriggerWhat starts a run?02ModelWhat chooses thenext action?03ToolsWhat can the agentobserve or change?04Memory and stateWhat survives eachturn?05GuardrailsWhat may enter,happen, and leave?06Human gateWhere must aperson decide?07Output sinkWhere does theresult go?
AI agent architecture: seven parts around one control loopSeven parts arranged around one control loop, numbered from the top. The parts and their questions are listed in order after the diagram.CONTROLloop01TriggerWhat starts a run?02ModelWhat chooses the next action?03ToolsWhat can the agent observe orchange?04Memory and stateWhat survives each turn?05GuardrailsWhat may enter, happen, andleave?06Human gateWhere must a person decide?07Output sinkWhere does the result go?
  1. Trigger: what starts a run?
  2. Model: what chooses the next action?
  3. Tools: what can the agent observe or change?
  4. Memory and state: what survives each turn?
  5. Guardrails: what may enter, happen, and leave?
  6. Human gate: where must a person decide?
  7. Output sink: where does the result go?

Trigger

What starts a run?

Accepted events, actor validation, deduplication key

Model

What chooses the next action?

Provider, exact model identifier, instructions, settings

Tools

What can the agent observe or change?

Input schema, side effects, credential scope, timeout

Memory and state

What survives each turn?

Authoritative store, retention, resume behavior

Guardrails

What may enter, happen, and leave?

Input, tool, output, and runtime checks

Human gate

Where must a person decide?

Actions requiring approval and reviewer identity

Output sink

Where does the result go?

Artifact format, destination, and delivery failure policy

1. Trigger: what starts a run?

A trigger turns an outside event into an agent input. Common triggers include:

  • A CLI command
  • An API request
  • A scheduled job
  • A new issue or comment
  • A queue message
  • A form submission
  • A chat message

The trigger should do more than start a process. It should identify the task, actor, target resource, and relevant authorization context.

The Claude Code GitHub Action demonstrates an event-driven trigger. Its official example listens for issue comments, pull request review comments, issue events, and submitted pull request reviews:

yaml
on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned, labeled]
  pull_request_review:
    types: [submitted]

The action can also use a configurable trigger phrase, issue assignee, or issue label. Its documented default trigger phrase is @claude. (Claude Code Action usage)

The Label new GitHub issues with Claude kit is a concrete example to inspect when designing this boundary. The reusable lesson is not a particular GitHub event. It is that trigger validation belongs outside the model. The workflow should establish whether an event is eligible before untrusted text enters a tool-capable run.

It is that trigger validation belongs outside the model.

Record at least these trigger fields:

yaml
trigger:
  type: issue_comment
  actor: "<authenticated identity>"
  resource: "<repository and issue>"
  event_id: "<deduplication key>"
  received_at: "<timestamp>"

This is an architecture worksheet, not configuration for the Claude action.

2. Model: what chooses the next action?

The model interprets the task and chooses between producing an answer and requesting a tool. It does not need to own the loop, permissions, state store, or delivery mechanism.

That distinction matters. A model may suggest a shell command, but the environment decides whether and where the command runs.

The OpenAI Agents SDK documents this separation in its runner loop. The runner calls the model, inspects the output, executes requested tools, appends their results, and calls the model again. It ends when the output is classified as final, or it raises MaxTurnsExceeded when the configured turn limit is reached. (OpenAI Agents SDK runner loop)

A model configuration should be explicit enough to reproduce the run:

yaml
model:
  provider: "<provider>"
  name: "<exact configured model>"
  instructions_file: "<path>"
  settings: "<recorded generation settings>"

Do not hide the model name only in application defaults. A silent model change can alter tool selection, output shape, cost, and latency even when the rest of the architecture remains unchanged.

3. Tools: what can the agent observe or change?

Tools are typed capabilities exposed to the model. They might read files, query an API, search documents, run tests, or submit a comment.

A useful tool definition answers five questions:

  • What inputs does it accept?
  • What output does it return?
  • Does it read or mutate data?
  • Which credentials does it receive?
  • What failure information returns to the loop?

Tool access should be narrower than the surrounding process whenever possible. An agent that only reviews code does not need a deployment credential. An agent that reads an issue does not automatically need permission to merge its pull request.

The Claude Code base action illustrates why the boundary must be explicit. Anthropic describes it as a thin wrapper that does not enforce any trust boundaries on its own. Its documentation says that running the base action in a directory is equivalent to running Claude Code there and makes the caller responsible for ensuring the working directory and prompt are trusted. It directs workflows processing untrusted issue, fork pull request, or external-comment input toward the supported anthropics/claude-code-action instead. (Claude Code base action trust model)

The Fix an issue in a disposable Docker workspace kit provides a small codebase for studying the model, environment, and control-loop boundary. In mini-SWE-agent, the agent's execute_actions hands each action to the environment's execute method, so the environment, not the model, runs it. (mini-SWE-agent control flow)

For each tool, write down:

yaml
tools:
  - name: read_repository
    effect: read
    credential_scope: repository
    approval: never
  - name: write_file
    effect: mutate
    credential_scope: workspace
    approval: policy-dependent

Again, this is an inventory format, not a framework-specific manifest.

4. Memory and state: what survives each turn?

State is the data required to continue a run. Memory is the subset deliberately carried forward to influence later model calls. In a small agent, both may be represented by one list of messages. In a durable service, they are often separated.

Useful state can include:

  • Trigger metadata
  • Conversation or message history
  • Tool requests and observations
  • Files changed
  • Current run status
  • Approval decisions
  • Retry and turn counters
  • The final artifact location

The OpenAI Agents SDK documents four ways to carry conversation state: manually passing result.to_input_list(), using a session, using a server-managed conversation_id, or continuing from a previous_response_id. It warns that mixing client-managed history with OpenAI-managed state can duplicate context unless the application deliberately reconciles both layers. (OpenAI Agents SDK memory strategies)

This produces a practical design rule: choose one authoritative history strategy for each conversation. Do not let an SDK session, a database transcript, and a provider-side conversation all append the same turns independently.

mini-SWE-agent provides a simpler example. Its documented default flow adds model responses and formatted environment observations to one linear message history. That simplicity makes the next model input easy to inspect, though it does not by itself provide durable execution across processes. (mini-SWE-agent control flow)

State should also have an owner. If a process crashes after a tool acts but before the observation is saved, can the next process determine whether the action already happened? That is why external event IDs, tool call IDs, and idempotent writes matter.

5. Guardrails: what may enter, happen, and leave?

A guardrail is an enforceable check around the loop. Instructions such as "be careful" can influence the model, but they are not equivalent to application-enforced policy.

Guardrails belong at several boundaries:

  • Input guardrails reject or transform invalid tasks.
  • Tool-input guardrails inspect proposed arguments.
  • Execution policy limits which tools, paths, hosts, or operations are available.
  • Output guardrails validate the final response or artifact.
  • Runtime limits stop excessive turns, time, or resource use.

The OpenAI Agents SDK distinguishes input, output, and tool guardrails. Its tool documentation also covers approvals around sensitive tool execution. (OpenAI Agents SDK guardrails, OpenAI Agents SDK tools)

mini-SWE-agent's default flow documents explicit exceptions for step or cost limits, malformed model output, execution timeouts, user interruption, and successful submission. These conditions become visible parts of control flow rather than unspecified behavior. (mini-SWE-agent control flow)

A sound first policy is deny by default:

text
if tool is not registered:
    reject

if arguments exceed the tool's scope:
    reject

if action mutates a protected target:
    request approval

if turn, time, or cost limit is reached:
    stop with a recorded status

The exact implementation depends on the runtime. The important architectural property is that enforcement occurs in code around the model.

The important architectural property is that enforcement occurs in code around the model.

6. Human gate: where must a person decide?

A human gate pauses a proposed action until an authorized person approves or rejects it. It is most useful before consequential or difficult-to-reverse operations, such as publishing, merging, deploying, deleting, or sending externally.

This component is related to guardrails but serves a different purpose. A guardrail applies a rule. A human gate requests judgment.

A guardrail applies a rule. A human gate requests judgment.

The OpenAI Agents SDK documents a flow in which a run can return interruptions for approval, serialize its RunState, and later resume after each interruption receives an approval or rejection decision. (OpenAI Agents SDK human-in-the-loop)

A useful approval record includes:

yaml
approval:
  run_id: "<run>"
  tool_call_id: "<proposed action>"
  requested_action: "<human-readable summary>"
  arguments: "<exact reviewed arguments>"
  decision: approved | rejected
  reviewer: "<authenticated identity>"
  decided_at: "<timestamp>"

The reviewed arguments matter. Approval for "update documentation" should not become reusable permission for a later, different command.

7. Output sink: where does the result go?

An agent is not finished merely because the model emitted final text. The application needs to place the result somewhere useful and record whether delivery succeeded.

An output sink might be:

  • Standard output
  • A Markdown file
  • A pull request
  • An issue comment
  • A database record
  • Object storage
  • A review queue

GPT Researcher shows a report-oriented sink. Its upstream README describes a workflow that gathers information, summarizes and source-tracks each resource, filters and aggregates summaries, and produces a research report with citations. (GPT Researcher README)

The Produce a research report with an agent team kit is the relevant live example for inspecting report artifacts. This article does not reproduce its multi-agent organization. At the single-agent architecture level, the reusable point is that a report is a distinct artifact with a defined format and destination.

For coding systems, the sink may be a patch or pull request instead. The Implement engineering requests with Open SWE kit shows a delivery-focused implementation. Its upstream project describes a system that investigates a codebase, implements changes, validates them, and delivers a pull request. The project also warns that it is under active development and that correctness, stability, and compatibility are not guaranteed. (Open SWE README)

Treat sink delivery as its own operation. Store the generated artifact first, validate it, attempt delivery, and record the delivery response. That separation prevents a failed comment, upload, or pull request from erasing an otherwise valid result.

Map the parts before choosing a framework

A framework can implement several components, but it does not answer the architecture questions for you.

Use this worksheet before writing integration code:

ComponentDecision to record
TriggerAccepted events, actor validation, deduplication key
ModelProvider, exact model identifier, instructions, settings
ToolsInput schema, side effects, credential scope, timeout
Memory and stateAuthoritative store, retention, resume behavior
GuardrailsInput, tool, output, and runtime checks
Human gateActions requiring approval and reviewer identity
Output sinkArtifact format, destination, and delivery failure policy

Then trace one real task through every row. If a row has no answer, the setup has an implicit dependency that will be difficult to test or audit.

How the live kits fill in the parts

Each kit on this site records its trigger, memory and human approval in its kit file. This table quotes those fields. Where a kit says a gate is missing or unverified, the table says so too.

KitTriggerMemory and stateHuman gateLicense
Create a branded presentation: local Vertex AI editionmanualSelected ADK UI uses in-memory sessions/artifacts via --no_use_local_storage; LOCAL_DEV=true also prevents the recipe wrapper from selecting Vertex sessions. State is lost at shutdown. The wrapper still checks an existing GCS bucket at import.Outline review is prompt-driven; an urgent/just-generate request can bypass review in the source prompt.Apache-2.0
Label new GitHub issues with ClaudeeventIssue labels persist on GitHub. Cross-run model memory is unknown.Explicitly approve a test taxonomy and public-author access before enabling. A hard no-comment or write-call barrier is not established.MIT
Review pull requests with ClaudeeventPull-request context and tracking comments persist on GitHub. Cross-run agent memory is unknown.Repository owner must accept broad capabilities before enabling. No deterministic human gate is supplied by this example.MIT
Research an approved plan with GeminimanualADK session state contains research_plan, findings, research_evaluation, and source maps. Local UI persistence and cross-restart behavior are unverified.The planner requests approval in model instructions; this is not a deterministic permission gateApache-2.0
Produce a research report with an agent teammanualGraph state contains research/drafts; output paths are working-directory relative. The entry point does not establish durable resumability.Human-plan review is optional and can be force-accepted at a revision ceiling. It is not a mandatory sign-off boundary.Apache-2.0
Fix an issue in a disposable Docker workspacemanualLinear message trajectory and persistent working-directory files. Durable cross-run memory is unknown.The authored runner requires --approved-provider-use and a finite positive --max-cost. It does not ask before each agent-generated shell action. Human review is required before using the resulting diff.MIT
Implement engineering requests with Open SWEeventPer-thread sandbox and LangGraph thread/checkpoint state, with explicit TTL configuration. Workspace routing does not establish a credential boundary.Review installation-wide GitHub App grants and each integration before enabling. Workflow-push approval does not protect every write path.MIT
Iterate on a Kaggle modeling experimentmanualExperiment workspaces and log sessions can be loaded by path. Restoration/cleanup behavior must be reviewed before use.Choose offline modeling scope and explicit compute/iteration bounds before any run. No automatic submission is authorized.MIT
Draft daily social posts from Slack linksscheduledLangGraph thread/store records URLs and reflections. Durability depends on the selected server; the in-memory development runtime is not verified durable.Normal generate_post flow interrupts for review, but direct upload API access bypasses that workflow path. Protect graph access.MIT

How to inspect an open-source agent setup

Start with files that reveal boundaries rather than reading the entire repository.

  1. Find entry points such as workflow files, CLI commands, API routes, or queue consumers.
  2. Locate the model adapter and identify where the exact model is configured.
  3. List every tool and mark it as read-only or mutating.
  4. Follow one tool observation back into the next model call.
  5. Identify limits, validation, sandboxing, and approval checks.
  6. Find the final write, comment, patch, report, or pull request operation.
  7. Inspect tests for rejected actions, retries, timeouts, and interrupted runs.

For mini-SWE-agent, the upstream repository can be cloned with the standard command:

bash
git clone https://github.com/SWE-agent/mini-swe-agent.git

Then begin with the documented control-flow file and the source it links:

text
docs/advanced/control_flow.md
src/minisweagent/agents/default.py

Do not assume a component exists because the README uses the word "agent." Confirm its implementation and tests.

How to verify your architecture

A working setup should pass more than a happy-path demo.

Test each boundary independently:

  • Send the same trigger twice and confirm the deduplication behavior.
  • Substitute a stub model response requesting an unknown tool.
  • Request a permitted read and a forbidden write.
  • Stop the process after tool execution, then test resume behavior.
  • Exceed the configured turn, time, or resource limit.
  • Reject a pending action and confirm that it does not execute.
  • Make the output sink fail and confirm the artifact remains recoverable.
  • Inspect the saved record and confirm it contains the trigger, tool observations, decisions, final artifact, and delivery status.

The result is not proof that the model will always be correct. It is evidence that the surrounding system handles known states deliberately.

The durable pattern

The most useful way to understand AI agent architecture is to stop treating the model as the whole system.

The most useful way to understand AI agent architecture is to stop treating the model as the whole system.

The trigger admits a task. The model proposes a next step. Tools provide controlled capabilities. State carries observations forward. Guardrails enforce rules. Human gates reserve consequential decisions for people. The output sink turns the result into a durable artifact.

Once those boundaries are explicit, you can replace a model, tool implementation, state store, or delivery channel without redesigning everything around it. You also gain a concrete checklist for reviewing open-source agent kits before allowing them to act on a real repository or service.

Sources and credits

All sources checked 22 Oct 2026, at these commits:

This guide is independent and not affiliated with or endorsed by any of these projects. Found something out of date? Tell us through submit. How this site checks claims is on verification.

Your privacy choices

Choose optional tools. Rejecting them keeps the setup library available. Advertising consent stays off.

Choices stay in this browser for 90 days. You can change them using Privacy settings. Privacy and cookie details