Giving LLMs Tools to Act: How Agent Runtime Frameworks Work
This article explains how agent runtime frameworks connect a large language model to external tools. It covers the perceive, decide, act, and observe loop, core components such as tool registration, controlled file and command access, state management, and error retries, plus a minimal implementation sketch, common design trade-offs, and a rollout plan.
1. Why Large Language Models Need “Hands and Feet”
Large language models are good at understanding text, organizing language, and generating code snippets. However, they cannot interact with external environments directly. A model cannot open a local file, view a directory structure, or run a command and read its output. A model only generates text based on its input. Any real action must be carried out by an external program.
This creates an engineering problem: how to turn the model’s decisions into program actions while keeping the whole process controllable, traceable, and recoverable. An agent runtime framework (hereafter “runtime framework”) is the middle layer designed to solve this problem. It receives the model’s output, parses the action it intends, calls the matching tool, and returns the result to the model, forming a closed loop.
2. The Basic Working Loop of an Agent
Most agent runtimes follow four stages:
- Perceive: Collect the current task goal, conversation history, and existing execution results.
- Decide: The model judges the next action based on the context, or gives a final answer directly.
- Act: The framework parses the model’s instruction and calls the corresponding tool, such as reading a file or running a search.
- Observe: The framework writes the tool’s result into the context for the next decision.
This loop repeats until the model determines the task is complete or a preset maximum number of steps is reached. Understanding this loop is the key to understanding the whole framework. Many features that look complex are, in essence, additions built around these four steps.
3. Core Components
3.1 Tool Registration and Invocation
A runtime framework usually maintains a tool table. Each tool requires three pieces of information: a name, a description of its purpose, and a parameter schema. The model chooses a tool based on its description, and the framework validates the input against the parameter schema.
An example tool description looks like this:
{"name": "read_file","description": "Read the text content of a file at the specified path","parameters": {"path": { "type": "string", "description": "Relative path of the file" }}}
Parameter validation should happen on the framework side. The model’s output should never be fully trusted. The model occasionally generates parameters with incorrect formats or missing fields. Validation before execution can catch these problems and reduce unexpected behavior.
3.2 Controlled File and Command Access
Letting a model read and write files and run commands also increases risk. Mature implementations usually include the following measures:
- Path allowlist: Permit access only to designated project directories, and block access to sensitive system locations.
- Command tiers: Read-only commands can run directly, while commands that modify or delete data require human confirmation.
- Isolated execution: Run commands in a separate container or restricted environment, limiting network access and resource usage.
- Least privilege: Grant each task only the permissions it needs, and revoke them promptly when the task ends.
These measures follow the same security principles as traditional backend services: least privilege and input validation. The difference is that the input source has changed from user forms to model output. Therefore, model output must be treated as untrusted data and reviewed to the same standard as user input.
3.3 Task State and Memory Management
Long tasks often need many steps to finish. The framework records each step’s goal, execution result, and status. Common statuses include pending, running, completed, and failed. With state persisted, a task can resume from the most recent checkpoint after a process interruption, without starting over.
The context window has limited capacity, so history cannot grow without bounds. A common approach keeps detailed records of the most recent few rounds, compresses earlier content into summaries, and preserves key decisions and artifact paths. This controls inference cost without losing the main thread of the task.
3.4 Error Handling and Retries
Tool calls can fail because of network jitter, missing files, or commands returning non-zero exit codes. The framework needs to distinguish two types of errors:
- Retryable errors: For example, temporary timeouts or temporarily unavailable resources. Retry with exponential backoff and set a maximum number of attempts.
- Non-retryable errors: For example, invalid parameters or insufficient permissions. Return these errors to the model along with the original message so the model can adjust its plan.
Returning the original error text to the model is usually more helpful than reporting only “execution failed.” The model can rewrite its parameters based on the specific error or choose a different approach to reach the goal.
4. A Minimal Loop Sketch
The pseudocode below shows the skeleton of a runtime framework. It omits language- and library-specific details and is meant only to illustrate the structure:
function run_agent(goal, tools, max_steps):state = load_checkpoint_or_init(goal)while state.steps < max_steps and not state.done:decision = model.decide(state.history, tools.schemas())if decision.type == "final_answer":state.done = truebreaktool = tools.lookup(decision.tool_name)if tool is None or not validate(tool, decision.arguments):observation = "invalid tool call: " + decision.tool_nameelse:observation = safe_execute(tool, decision.arguments, retries=3)state.history.append(decision, observation)save_checkpoint(state)state.steps += 1return state.result
This code illustrates several key points. Tool calls are validated before execution. Results are written to history whether they succeed or fail. A checkpoint is saved after every step, and a maximum step count prevents infinite loops. These four points form the shared foundation of most implementations.
5. Common Design Trade-offs
When implementing a runtime framework, teams usually need to balance the following pairs:
- Autonomy vs. control: Higher autonomy speeds up task progress but increases the risk of mistakes. Adding human confirmation at critical points is a practical compromise.
- Context length vs. cost: Keeping more history helps the model make decisions, but it increases inference cost and response latency.
- Tool granularity: Fine-grained tools require the model to combine many steps to complete a single task, which increases the number of steps. Coarse-grained tools reduce flexibility. Dividing tools by common business operations is recommended.
- Observability: Record the input and output of each step to make troubleshooting easier. Logs should not contain keys or sensitive personal information.
6. Rollout Recommendations
If your team plans to introduce this kind of capability, consider proceeding in the following order:
- Start with one read-only scenario, such as reading documents and generating summaries, to verify that the loop is stable.
- Define a clear parameter schema for each tool, add validation, and return complete error messages to the model.
- Introduce path allowlists and command tiers. Once the security boundaries are confirmed, gradually enable write operations.
- Set up logging and checkpoint mechanisms that record the context of each execution, so issues can be reproduced.
- Run regression tests with a fixed set of tasks after each change to confirm that behavior remains as expected.
7. Summary
The core value of a runtime framework lies in turning the model’s text-based judgments into controlled, traceable program actions. By understanding the perceive, decide, act, and observe loop, and combining it with tool registration, permission control, state persistence, and error retries, teams can build a reliable foundation for agent capabilities.
