Technical Analysis and Practice of AI Agent Execution Frameworks
This article explains how AI agent execution frameworks shift large language models from giving suggestions to completing verifiable tasks. It covers the underlying system architecture, token-based cost models, sandbox runtime design, local setup steps, prompt and context engineering, security and cost governance, and key criteria for evaluating an execution framework.
1. From Giving Advice to Getting Work Done: A Shift in Technical Paradigm
Over the past two years, the dominant interaction pattern with large language models has been conversation: a user asks a question, and the model returns text, code, or written content. The boundary of this pattern is clear—it produces suggestions, while execution, verification, and delivery are still handled by people. A new pattern has recently emerged across the industry and is commonly referred to as an agentic harness: the model no longer just answers questions but is placed in a controlled runtime environment where it can autonomously call tools, read and write files, execute commands, run tests, and iterate based on feedback until the task reaches an acceptable, verifiable state.
It is important to emphasize that this is not a single breakthrough in model capability but a systems engineering effort combining the model, runtime, toolchain, and permission boundaries. Understanding this is the key to avoiding the mistake of treating it as a smarter chat window.
1.1 Capability Differences Between the Two Patterns
- Conversational pattern: takes context as input and outputs text; has no side effects, is not verifiable, and deliverables must be moved manually.
- Execution pattern: provides tool interfaces such as a file system, terminal, browser, and code repository; has side effects, is verifiable (compilation, testing, static checks), and deliverables land directly in the project.
1.2 Why It Has Matured Only Now
First, models have become more stable in long-context handling and instruction following, so multi-step planning no longer falls apart midway. Second, tool calling (Function Calling) and structured output have become general capabilities. Third, containerized sandboxes and low-cost cloud capabilities such as object storage, logging services, and monitoring and alerting make it cheap to give a model a disposable machine.
2. Understanding the Billing Model: Cost Under Usage-Based Pricing
Model services aimed at developers commonly bill by token volume with time-of-day pricing. This is a separate product line from free conversational products aimed at general users. Understanding the billing basis is the prerequisite for cost governance.
2.1 An Intuition for Token Conversion
One Chinese character is usually close to 2 tokens, and punctuation, spaces, and English words are counted as well. For example, with an input question of 100 characters plus 800 characters of output, the input is about 200 tokens and the output about 1600 tokens, for a total of roughly 1800 tokens. Because output-side token consumption is significantly higher than input-side consumption, and output tokens usually cost more per unit, making the model write less filler and more useful content is the most direct way to save money.
2.2 Peak and Off-Peak Hours
A common industry practice is to designate core collaboration hours on workdays as peak and the rest as off-peak, with a discount applied during off-peak hours. Peak pricing follows the logic of scarcity-based resource pricing. For developers, tasks without real-time human interaction—such as batch refactoring, batch documentation generation, and overnight regression fixes—can be scheduled during off-peak hours, where the cost difference can be substantial.
2.3 An Illustrative Cost Estimation Implementation
# Illustration: estimate the cost of a single task by token usage and time-of-day factorPEAK_HOURS = {(9, 12), (14, 18)}def is_peak(hour: int) -> bool:return any(start <= hour < end for start, end in PEAK_HOURS)def estimate_cost(in_tokens: int, out_tokens: int,price_in: float, price_out: float,hour: int, off_peak_discount: float = 0.5) -> float:base = in_tokens * price_in + out_tokens * price_outreturn base * (1.0 if is_peak(hour) else off_peak_discount)
The parameters here are generic placeholders. Actual unit prices should follow the provider’s published pricing, and no unconfirmed values should be written into capacity planning.
2.4 Overlooked Hidden Costs
The execution pattern introduces expenses that the conversational pattern does not have: repeated context expansion caused by multiple tool-call rounds; duplicate token consumption from retries after failures; and storage and retrieval overhead from retaining logs and traces. Mature teams set a token budget and a step limit for each task, and abort and roll back once either is exceeded.
3. A General Architecture for Execution Frameworks
A usable agent execution framework typically consists of five layers:
- Model access layer: provides a unified wrapper for conversational and tool-calling interfaces and handles timeouts, rate limiting, and retry backoff.
- Planning and control layer: handles task decomposition, plan generation, step budgets, and termination condition checks.
- Tool and integration layer: handles file reading and writing, terminal commands, code retrieval, test execution, and dependency management.
- Sandbox runtime layer: provides a containerized isolated environment that can be discarded and rebuilt with one action, with controlled network egress.
- Observability and governance layer: records full-chain traces, collects metrics, and provides alerting and auditing.
The sandbox runtime is the key to security. The recommended minimum constraints include running as a non-root user, a read-only root file system, a separate working volume, an egress allowlist, resource quotas (CPU/memory/duration), and command-level auditing.
4. A General Process for Setting Up a Local Environment
Because installation details vary significantly across products and keep changing, the following tool-agnostic steps apply to localizing any “intelligent coding tool”:
- Confirm runtime dependencies: align versions of the language runtime, package manager, and container runtime.
- Prepare credentials: inject them via environment variables or a key management service, and never commit them to the repository.
export MODEL_API_KEY="<your-key>"export SANDBOX_IMAGE="<your-sandbox-image>"
- Initialize the workspace: create a separate directory, put it under version control, configure ignore rules, and avoid committing secrets and build artifacts.
- Start the sandbox and run a connectivity self-check: verify that the container can be created, directories can be mounted, and the egress policy takes effect.
- Run the smallest end-to-end loop: have the framework complete the shortest path of “read a file → modify one line → run tests → output a report,” and confirm the toolchain works before expanding the task scope.
5. Key Points for Prompt and Context Engineering
- Make the goal verifiable: rewrite “optimize this module” as “make a specific test suite pass entirely and reduce response time,” so the model can judge completion on its own.
- State constraints upfront: explain coding standards, dependency versions, and directories that must not be changed all at once to reduce back-and-forth.
- Layer the context: inject system constraints, repository structure, the current task, and historical traces into separate sections to avoid cross-contamination.
- Commit in small steps: immediately persist and test each small verifiable change to reduce rollback cost.
6. A Checklist for Security, Compliance, and Cost Governance
- Least privilege: default to read-only, and grant write permission at directory granularity.
- Data boundaries: keep sensitive data out of the context; when processing is truly necessary, perform redaction and minimal sampling first.
- Full traceability: record commands, parameters, return codes, and diffs to support later audits.
- Dual budgets: set both a token budget and an execution step budget, and stop when either is exceeded.
- Human gates: actions involving production environments, permission changes, or data deletion require human confirmation.
7. Evaluation Dimensions for Selection
When evaluating a class of execution frameworks, it is recommended to score them across six dimensions: task completion rate, verifiability (whether testing and static checks are built in), sandbox isolation strength, observability, cost controllability, and extensibility (the cost of swapping tools and models). Avoid making decisions based on a single demo result; instead, run a set of real tasks on your own repository to establish a baseline comparison.
8. Conclusion
The shift from conversation to execution is essentially about embedding the model into the software delivery pipeline and having it take on verifiable stages. The deciding factors in engineering implementation are not how strong the model is, but whether the sandbox is secure, whether budgets are controllable, and whether traces are auditable. If an enterprise wants to build this capability in its own cloud environment, it can use general capabilities such as Baidu AI Cloud’s container platform, object storage, logging services, and monitoring and alerting to build an isolated runtime and a full-chain observability system, steadily improving R&D automation while ensuring compliance and cost control.
