From Models to Action: Designing and Implementing Four Agent Architectures
Large language models generate text from context, but completing real operations requires an engineering system around the model. This article explains the agent execution loop, four architecture patterns (minimal execution, shared service, memory-augmented, and multi-channel), and the shared engineering problems of context, tools, state, failures, and observability—so you can choose and evolve an architecture from the task, not from the model alone.
Model capability is not the same as agent capability
Large models are good at producing output from input context. Generating an action recommendation is not the same as completing that action safely and reliably. That gap is filled by an engineering system.
For example, a user may ask to analyze recent sales data and produce a report. The model may be able to plan analysis steps, but it cannot, from model weights alone, read a business database, verify user permissions, run queries, save files, and send results. Those actions depend on external systems and on how execution is managed.
From an engineering view, an agent can be described as:
Agent = model reasoning + runtime framework + tools and environment + state management + safety constraints.
The runtime organizes model calls, builds context, dispatches tool requests, persists execution state, and decides when a task ends. It is not a thin wrapper around a model API. It is the control layer between the model and the real business environment.
The same model can behave very differently in different runtimes: some fit short, well-bounded tasks; some share task state across clients; some reuse historical experience; some accept requests from multiple messaging channels. Those differences usually come from architectural goals, not from the model’s reasoning ability alone.
Start with the minimal execution loop
How an agent typically completes a task
A basic loop looks like this:
user request → build context → call the model → parse the result → execute tools → write results back → reason again or stop.
Model output usually falls into two classes: a final answer for the user, or a tool-call request. The runtime must distinguish them and validate tool requests.
Illustrative pseudocode (not tied to any product API):
state = initialize_task(request)while not state.finished:context = build_context(state)decision = invoke_model(context)if decision.is_final_answer:state.result = decision.answerstate.finished = truecontinuevalidate_tool_arguments(decision.tool_request)check_execution_permission(state, decision.tool_request)result = execute_tool_with_timeout(decision.tool_request)record_step(state, decision, result)if exceeds_task_budget(state):state.finished = truestate.result = summarize_partial_progress(state)
The loop is simple, but it surfaces the main engineering problems: how context is assembled, how tool arguments are validated, how permissions are decided, how failures are handled, how task budgets are enforced, and how intermediate state is stored.
Why termination conditions are required
Telling the model to “stop when the task is done” is not enough. It may retry failing tools or keep adding analysis so the task never ends.
The framework should define explicit stop conditions, such as max steps, total runtime, tool-call budget, consecutive failures, and human confirmation points. Thresholds should follow business risk and cost, not a single copied number.
When a limit is hit, the system should report completed work, remaining issues, and suggested next steps—not package an unfinished task as success.
What “the model is stateless” actually means
In typical inference calls, the model does not update its own weights because of a conversation. It can use prior information only if the application resupplies history, retrieval results, or other context.
Long-term memory is therefore maintained by external systems, not by the model “remembering the user.” Temporary compute caches during generation are not persistent business memory.
Four architectures: the control center of gravity differs, not just the name
These are general design patterns, not product reviews. They are not mutually exclusive. A real system can combine shared services, external memory, and multi-channel access.
1. Minimal execution: keep the flow understandable
This pattern organizes code around a clear loop and only the tools, state, and config needed for the current task.
The control path is short and easier to debug. Developers can see what context each model call used, which tools were requested, and how tool results changed later decisions.
It fits teaching, internal assistants, and well-bounded automation with low concurrency—for example, summarizing documents in a specified directory without a full scheduler or cross-channel session system.
Less code does not mean weaker safety. If tools modify files, write data, or talk to external systems, you still need permission checks, timeouts, and operation logs.
The main risk is that the loop accumulates business branches until it becomes an untestable monolith. Separate model calls, tool execution, and state storage early so the main loop only coordinates.
2. Shared service: one execution system, many entry points
The agent runtime lives on the server. Clients submit requests, show progress, and handle interaction.
The goal is not a “smarter model,” but consistent use of one execution system from many clients. A user may start a task on the web and later check progress from another device while the server keeps the same task state.
Distinguish user, session, and task:
- The user defines identity and permission boundaries.
- The session holds the interaction relationship and context.
- The task records one execution and its lifecycle.
They are not interchangeable. One session can contain many tasks; one user can have many sessions.
Concurrency matters. Two clients updating the same task can cause duplicate execution or overwritten results. Use version checks, queues, leases, or locks as the business requires. Last-write-wins is not enough.
For long-running work, decouple execution from the client connection. Closing a page should not drop the task. Repeated submit should not, without checks, cause duplicate charges, writes, or sends.
3. Memory-augmented: turn history into retrievable assets
External storage holds user preferences, business facts, past results, or validated operating experience, retrieved when needed.
Do not treat all information the same:
Session history records what happened in this interaction. Factual memory stores relatively stable information. Experience memory records what worked in a situation. Skill descriptions may include reusable steps, preconditions, and verification methods.
A one-off request should not automatically become a long-term preference, and a lucky success should not immediately become a trusted skill.
A reasonable memory pipeline is: extract candidates → record source → validity check → dedupe and conflict handling → store → retrieve on demand → update or delete.
For operational experience, store not only “how” but also “when it applies,” “what permissions are needed,” “how to verify results,” and “when not to use it.” Otherwise the system may reuse stale procedures after the environment changes.
Memory is not self-training and does not guarantee the agent keeps getting better. Bad information can be stored and reused. High-impact memories need review; sensitive data should follow a minimum-retention rule; users should be able to inspect, correct, and delete related records.
4. Multi-channel access: unify message semantics, not just forward traffic
Different message sources become a unified internal event, then go to the agent runtime.
The hard part is not channel count. It is differences in message format, identity, attachments, reply style, and permission rules.
An internal event can look like:
event:sourcesender_identityconversation_identityevent_identityreceived_timetextattachment_referencespermission_context
These fields illustrate the idea. Real schemas should follow the business.
The message path may duplicate, delay, or reorder events, so you need deduplication and ordering. Replies may have length or attachment limits; not every channel can show the same result unchanged.
Identity mapping is more important. Same display name is not the same user. Requests from different channels should not automatically share history and permissions. Cross-channel linking requires reliable authentication and explicit authorization.
Five engineering problems shared by all four patterns
1. Context management: more information is not always better
Dumping all history, documents, and tool output into context raises cost and can bury the signal.
Organize context by task relevance: stable system constraints, current goal, necessary history, retrieved evidence, and recent execution results. Long tool output should be reduced to key fields first. Older steps can be summarized, but important facts should keep a traceable source.
External pages, documents, and messages may contain prompt-injection style instructions. Treat them as data to analyze, not as rules that can override system policy or permissions.
2. Tool governance: valid parameters are not the same as a safe operation
Tool calls need at least two checks.
Structural: the tool exists, types are correct, required fields are present. Business: the user is allowed, the resource is in scope, and the action may need approval.
High-impact actions—delete, send, pay, bulk change—should use confirmation and show the user the object, scope, and consequences.
The runtime must decide permissions from trusted identity and policy, not from the model claiming “the user already authorized this.”
3. State persistence: saving chat is not recovering execution
Full task state usually includes current step, tool-call log, results, pending confirmations, errors, and artifact locations.
On resume, distinguish operations not yet started, operations that succeeded, and operations with unknown outcome. If an external write already happened but local success was not recorded, a blind retry can duplicate side effects.
For side-effecting operations, prefer idempotency, querying business state, or human verification. Checkpoints help recovery; they do not by themselves guarantee each external action runs only once.
4. Failure handling: retries need bounds
Transient network errors can be retried a limited number of times. Bad parameters should be fixed first. Missing permission should stop or request authorization. Persistent outages should degrade, delay, or hand off to a human.
Return failures in a structured way so the model can tell “invalid request” from “temporarily unavailable,” instead of treating every error as something to try again.
5. Observability: you improve what you can explain
Correlate user request, task steps, model calls, tool calls, and final result. Record useful latency, error types, and resource use.
Do not log sensitive data indiscriminately. Use redaction, access control, and retention tiers to balance debugging and privacy.
How to choose: define the task first
Do not start from code size or tool count. Answer four questions:
How long is the task? Short work can use a simple loop; long work needs queues, checkpoints, and recovery.
How risky are the actions? Read-only queries and production writes need different authorization, isolation, and audit.
Are there multiple entry points? If users need to view and control work across clients, a shared service is easier to keep consistent than per-client state.
Is historical experience stably valuable? Highly repetitive work may benefit from memory and skill reuse. If rules change often, prioritize source, versioning, and expiry.
When you evaluate, keep model config, tool permissions, and test tasks fixed, and measure success rate, correctness, latency, resource use, human intervention, and recovery. Otherwise you cannot tell whether gains came from the model, the prompt, or the runtime.
Evolve from a minimum viable system
A safer path: run the minimal loop on low-risk tasks; then add tool permissions, execution budgets, and audit logs; then add persistent state, shared services, external memory, and multi-channel access as needed.
Each new capability needs matching tests—for example, whether stale memory pollutes answers, whether channels isolate identity and handle duplicate delivery, and whether recovery repeats external operations around an interruption.
Agent architecture is not about wrapping the model in more complexity. It is about a controllable loop among reasoning, action, and state. The model sets how far the system can understand and reason. The runtime decides whether those capabilities can be used safely, stably, and with a trace in a real environment.
