AI Agent Engineering: Coding Collaboration, Long-Running Tasks, and Cost Evaluation
Reliable AI agents need to deliver verifiable outcomes, not just convincing responses. This article outlines practical approaches to coding workflows, long-running task management, multi-agent collaboration, financial document analysis, cost measurement, and security. It explains how clear acceptance criteria, execution evidence, recoverable checkpoints, and controlled permissions turn agent capabilities into dependable productivity.
1. Evaluate Agents by Task Delivery, Not Response Quality
The value of an AI agent extends beyond generating code or writing a report. Given a clear objective and constraints, it should be able to read relevant materials, create a plan, use tools, observe results, and continue working based on feedback.
Evaluation therefore needs to move from individual outputs to the full execution workflow. A polished application prototype may not connect to real data. A code change that runs successfully may simply bypass the failing path. A fluent analysis report may still mix incompatible reporting definitions.
Three questions matter most:
- Does the system understand the actual delivery scope? A request to “build a financial reporting monitoring application” may include a user interface, data storage, scheduled collection, access controls, and deployment configuration. Completing the interface does not mean completing the system.
- Can the system obtain reliable feedback through tools? Code generation is only the starting point. Build results, test reports, runtime logs, and observed interface behavior determine whether a change works.
- Is the total cost of completing the task manageable? Model usage is only one expense. Human review, failed attempts, execution environments, and ongoing maintenance also count.
These questions reflect production requirements more accurately than comparing isolated responses.
2. Agentic Coding Requires a Verifiable Development Loop
Define Delivery Levels Before Claiming Completion
For a financial reporting monitoring application, delivery can be divided into four levels:
- Interactive prototype: Page layouts, filters, detail views, and mock data.
- Functional application: Connected frontend and backend, data reads and writes, input validation, and error handling.
- Deployable system: Configuration management, persistent storage, logging, and deployment instructions.
- Operational service: Authentication, authorization, monitoring and alerts, backups, and recovery mechanisms.
Not every project needs to reach all four levels at once. The purpose is to describe the current deliverable accurately. Mock data is entirely appropriate for a prototype, but it should be clearly labeled so that demonstration capability is not mistaken for production readiness.
An effective task specification should identify, at a minimum:
- Target users and core workflows.
- Inputs and outputs.
- Runtime environment and data sources.
- Areas that must not be modified.
- Acceptance criteria.
For an existing project, it should also specify compatibility requirements and behaviors that must remain unchanged.
Turn Natural-Language Requirements into Acceptance Checks
Requirements such as “the page should be easy to use” or “the analysis should be accurate” are difficult to verify directly. Break them down into observable behavior.
For example, a financial reporting monitoring application might have these acceptance checks:
- Records can be filtered by company, reporting period, and processing status.
- An empty result displays a clear message rather than a blank page.
- Failed data requests preserve necessary context and provide a retry option.
- Saved data remains available after a page refresh.
- The server returns understandable errors for invalid fields.
- Unauthorized users cannot read protected data.
- Critical calculation logic has automated tests.
- Deployment instructions allow someone else to reproduce the setup in a clean environment.
Clear acceptance criteria help the agent create a useful execution plan and give human reviewers a concrete basis for evaluation.
Use Execution Evidence to Guide Corrections
A reliable coding workflow generally follows this sequence:
Understand the task → Inspect the project → Plan the work → Make small changes → Run validation → Analyze failures → Apply targeted fixes → Summarize delivery.
Validation is the critical step. An agent saying “fixed” does not prove that the tests pass. Saying “the page works” does not prove that the important interactions were checked.
The delivery report should distinguish three categories:
- Checks that were executed and passed.
- Checks that were executed and failed.
- Checks that were not executed because of environment, permission, or time constraints.
This distinction reduces false confidence in completion and makes handoffs easier.
3. Long-Running Tasks Need State That Survives Interruptions
Complex tasks often require multiple rounds of changes. As the process grows longer, an agent may forget earlier constraints, repeat failed approaches, or develop an inaccurate understanding of the current codebase.
The central requirement is not simply a large context window. It is the ability to maintain trustworthy task state over time.
Save Structured Checkpoints
At meaningful milestones, record the following information:
| State category | Information to record |
|---|---|
| Objectives and constraints | Current requirements, protected areas, and acceptance criteria |
| Execution progress | Completed work, remaining work, and current blockers |
| Project changes | Modified files, reasons for changes, and related dependencies |
| Validation results | Checks performed, failure details, and untested areas |
| Recovery information | Next actions, required configuration, and rollback procedures |
A checkpoint should do more than say “some features are complete.” It should contain enough detail for another executor to resume the work.
Set Boundaries for Retries
Automatic retries are useful only when the failure is recoverable. Temporary network interruptions may justify a bounded retry policy. Authentication failures, insufficient permissions, or missing credentials usually will not improve through repetition.
Useful control principles include:
- When the same error repeats, reassess the cause before expanding the scope of changes.
- Pause for confirmation before deleting data, changing permissions, or publishing externally.
- When a time or cost budget is exceeded, report progress and blockers.
- Preserve a recoverable version before making broad changes.
- Explicitly label unverified results rather than describing them as successful.
Budgets should reflect the risk of the task. There is no single threshold suitable for every project.
Prefer Minimal Fixes to Unbounded Refactoring
A common risk in existing projects is rewriting large amounts of code to solve a local problem. This can obscure the original failure and introduce compatibility issues.
A safer approach is to identify the triggering conditions, add a test that reproduces the problem, and apply the smallest effective fix. If refactoring is necessary, explain its benefits, impact, and migration costs separately rather than hiding it inside an ordinary bug fix.
4. Multi-Agent Collaboration Needs Task Boundaries and Evidence Standards
A multi-agent system is not simply several agents answering the same question at once. Its potential benefits come from effective division of labor, but it also adds scheduling, communication, result-merging, and conflict-resolution costs.
Parallelize Loosely Coupled Work
Tasks suited to parallel execution generally have independent inputs and clearly defined outputs. Examples include:
- Organizing financial reports for different companies.
- Inspecting separate functional modules.
- Conducting security reviews and functional validation independently.
- Cleaning non-overlapping data partitions.
If several agents modify the same core module, or later steps depend on earlier results, adding more parallel workers may be counterproductive.
Choose multi-agent execution based on task dependencies, not on how complex the task appears.
Standardize Structured Outputs
For financial reporting research, each execution unit can return the same fields:
- Company identifier and reporting period.
- Metric name, value, unit, and currency.
- Source document name and location within the source.
- Factual excerpts and analytical conclusions.
- Missing fields, differences in reporting definitions, and items requiring verification.
This allows the aggregation stage to validate fields, detect duplicates, and check comparability instead of merely concatenating prose.
Do Not Resolve Conflicts by Majority Vote
Agreement among several agents does not establish correctness. They may all rely on the same outdated document or share the same misunderstanding.
When results conflict, examine the original evidence, document dates, metric definitions, and calculation steps. If discrepancies cannot be resolved, preserve the uncertainty rather than forcing a single conclusion.
A useful scheduling strategy is to start with a small number of agents for task decomposition and sample validation. Expand parallel execution only after the data and output format are stable.
5. Long Context Does Not Guarantee Reliable Financial Analysis
Long-text input reduces the need to split documents manually, but it does not automatically ensure complete extraction, accurate citations, or correct reasoning. Financial reports are particularly vulnerable to comparisons across incompatible periods, currencies, and reporting definitions.
Maintain a Document Inventory and Source Traceability
Before analysis, record each document’s source, reporting period, publication date, version, and parsing status. Preserve relationships between narrative text, tables, and notes wherever possible.
Scanned documents also require attention to optical character recognition errors. Misread minus signs, parentheses, units, or decimal points can materially change financial meaning. Critical values should be traceable to their original locations, not accepted solely from a summary.
Separate Extraction, Calculation, and Interpretation
A more robust workflow is:
Parse documents → Extract fields → Check reporting consistency → Perform deterministic calculations → Generate conclusions → Verify citations.
Models can help identify field meanings and interpret context. Growth rates, proportions, and totals should preferably be calculated with reproducible program logic.
For example, year-over-year growth is commonly calculated as:
Year-over-year growth = (Current-period value − Prior-year comparable value) / Prior-year comparable value.
However, displaying a percentage mechanically can be misleading when the baseline is zero or negative, or when reporting definitions have changed. The system should detect these cases and explain them instead of applying the formula without qualification.
Distinguish Facts from Inferences
“Revenue increased” is a fact that can be checked against a report. “The company’s competitive advantage strengthened” is a judgment requiring additional evidence.
High-quality output should distinguish:
- Facts directly traceable to sources.
- Calculated results derived from explicit formulas.
- Interpretations based on those facts.
- Unconfirmed assumptions and risks.
This improves readability and prevents fluent language from concealing weak evidence.
6. Measure the Real Cost per Accepted Task
Agent economics cannot be assessed from subscription fees, per-call prices, or remaining usage allowances alone. Context length, tool-call frequency, and retry counts can vary substantially across tasks.
A more useful measure is:
Cost per accepted task = Total relevant expenditure during the evaluation period / Number of tasks that pass acceptance.
Total expenditure should include model calls, execution environments, storage, tool usage, human review, failed attempts and rework, and maintenance. Attempts that fail acceptance still consume resources and must remain in the numerator.
Track these additional indicators:
- End-to-end completion time.
- Whether the task passed its first acceptance review.
- Number and duration of human interventions.
- Retry counts and causes.
- Regressions introduced by changes.
- Number of confirmations required for high-risk actions.
A single demonstration or a small task sample cannot establish long-term cost-effectiveness. Evaluation should cover different difficulty levels, project sizes, and failure conditions, with repeated tests where practical.
7. Security and Open-Source Evaluation Require Clear Responsibility Boundaries
Once an agent can read files, execute programs, or access external resources, it needs explicit constraints.
Run tasks in isolated environments and grant access only to necessary directories and network resources. Separate permissions for reading, modifying, deleting, and publishing. Supply sensitive credentials through controlled mechanisms so they do not enter source code, logs, or task records.
External documents should also be treated as untrusted input. Instructions found inside a document must not automatically gain execution authority or override the task’s existing constraints. Data exports, credential access, and irreversible changes require independent checks and human confirmation.
When considering open-weight or open-source options, examine each of the following separately:
- Licenses.
- Available components.
- Deployment dependencies.
- Hardware requirements.
- Maintenance responsibilities.
“Available to download” does not mean “unrestricted commercial use.” An accessible model also does not imply that its surrounding execution system is fully open.
8. Start with a Baseline, Then Expand Automation Gradually
Begin with a low-risk task that has clear acceptance criteria, such as fixing a known defect, generating an internal report, or building an interactive prototype.
Stage 1: Establish a baseline. Fix the task inputs and acceptance criteria, and record how long the work takes when performed manually.
Stage 2: Introduce agent execution with human review. Collect failure categories and reasons for rework.
Stage 3: Strengthen the engineering controls. Address recurring problems with tests, permission controls, checkpoints, and evidence traceability.
Stage 4: Expand only what is consistently verified. Increase automation for tasks that reliably pass validation, while continuing to monitor cost and quality.
The goal is not an impressive one-off output. It is consistent delivery within explicit boundaries: tasks that can be accepted, processes that can be traced, failures that can be recovered, costs that can be measured, and risks that can be controlled.
These engineering foundations are what turn long-running execution, multi-agent collaboration, and agentic coding into dependable productivity.
