Building General-Purpose AI Agents: Combining Reasoning and Coding in Practice
This article explores how to build general-purpose AI agents by unifying reasoning, coding, and agentic capabilities in a single foundation model. It covers the shift from conversational models to task-executing agents, the four-layer agent architecture, and why a unified model improves context consistency while reducing routing complexity. It also outlines a practical path for knowledge-intensive industries, engineering trade-offs for long-context and reasoning efficiency, deployment and hardware adaptation, and an evaluation framework that avoids common pitfalls.
1. From Conversational Models to Task-Executing Agents
Early large language models mainly handled question answering and text generation, with interactions limited to a single question and a single answer. Agents differ in a fundamental way: given a goal, they can break down tasks autonomously, call tools, observe results, and iterate until the goal is met or a termination condition is triggered. This shift places three requirements on the foundation model:
- General cognition: Understanding cross-domain semantics with common sense and transfer ability, so performance does not degrade in vertical scenarios due to shifts in corpus distribution.
- Knowledge augmentation: Using retrieval, structured knowledge bases, and tool calls to compensate for the limited freshness and accuracy of parametric knowledge.
- Complex reasoning: Maintaining logical consistency across multi-constraint, multi-step problems, with support for planning, reflection, and self-verification.
In engineering practice, an agent is usually split into four layers: the model layer (reasoning and generation), the orchestration layer (task planning and state management), the tool layer (retrieval, computation, code execution, business APIs), and the observability layer (logs, metrics, tracing). Once these four layers are decoupled, model upgrades do not force a rewrite of the upper-level workflows, which is key to controlling long-term maintenance costs.
2. Why Fuse Reasoning, Coding, and Agentic Capabilities in One Model
A common approach in the past was to prepare multiple task-specific models and dispatch requests through a routing layer. The problem is that routing errors amplify mistakes, and managing versions, evaluations, and rollbacks across several models is expensive. Building reasoning, coding, and agentic capabilities natively into a single model brings three benefits:
- Context consistency: Planning, coding, and execution feedback share the same semantic space, reducing information loss across models.
- Simpler pipelines: There is no need to maintain complex routing or multi-model canary systems, and fault localization becomes more direct.
- Controllable cost: Unified batching and caching strategies are easier to implement, making token consumption and latency more predictable.
It is worth stressing that fusion does not mean one model solves every problem. Instead, general capabilities are consolidated in the foundation model, while domain-specific differences are handled by the knowledge layer and the tool layer. This layering is a sustainable architectural choice.
3. A Practical Path for Knowledge-Intensive Industries
Finance, legal, and education scenarios share common traits: low fault tolerance, strict citation requirements, and conclusions that must be traceable. Recommended practices:
- Do knowledge governance first, then model selection. Document chunking strategy, metadata schemas, and permission models determine the upper bound of retrieval quality.
- Enforce citations and traceability. Require the model to attach source snippets when outputting conclusions; if sources are missing, downgrade the answer to “uncertain.”
- Close the loop with human-in-the-loop collaboration. Keep human review checkpoints for high-risk actions such as fund operations or finalizing legal documents.
- Build the evaluation set first. Construct a regression evaluation set from real business questions and run it after every model or prompt change, avoiding a vague sense that things “feel better.”
Illustrative retrieval-augmented call logic (pseudocode):
def agent_step(goal, state):plan = model.plan(goal, state) # Task decompositionif plan.need_knowledge:docs = retriever.search(plan.query, top_k=5)context = rerank(docs)[:3] # Truncate after reranking to control context lengthelse:context = []if plan.need_code:result = sandbox.run(plan.code) # Code runs in an isolated sandboxstate.update(result)answer = model.answer(goal, state, context)return answer if answer.citations else degrade(answer)
4. Engineering Trade-offs Between Long Context and Reasoning Efficiency
Expanding the context window from shorter specifications to the 200K token level allows an entire code base fragment or a long contract to fit in a single pass, but it also creates two practical problems: attention computation costs rise, and “lost in the middle” effects make recall unstable. Practical recommendations:
- Layered context: Keep a summary layer resident and retrieve detail layers on demand, avoiding indiscriminate full concatenation.
- Structured compression: Convert logs and tables into compact representations to cut wasted tokens.
- Cache reuse: Apply prefix caching to stable prefixes such as system prompts and specification documents, significantly reducing repeated computation.
- Budget constraints: Set token and step limits per task to prevent the agent from getting stuck in loops.
5. Deployment and Hardware Adaptation
As model size grows, the core deployment issues become quantization and hardware adaptation. The industry commonly uses post-training quantization (for example, FP8 weights with Int4 activations) to reduce memory footprint, and operators, runtime, and chips must be validated together for accuracy loss. In a domestic chip environment, integrated model-to-chip adaptation typically involves three things: operator coverage, communication library differences, and accuracy alignment. A recommended process is: small-sample accuracy baseline comparison → end-to-end business set regression → long-duration stability testing.
Supporting infrastructure can rely on general cloud capabilities: container platforms handle elastic scaling, object storage holds knowledge and model artifacts, message queues smooth out traffic spikes, and logging plus monitoring with alerting ensure observability.
6. Evaluation Systems and Common Pitfalls
Evaluation should cover four layers: foundational capabilities (general knowledge, math, code), agentic capabilities (tool selection accuracy, task completion rate, average steps), business metrics (accuracy, citation compliance rate, human takeover rate), and cost metrics (token consumption per task, P95 latency).
Common pitfalls include: looking only at leaderboard scores instead of business set performance; neglecting structured attribution of failure samples; treating prompts as long-term assets without version management; and directly executing model-generated code without sandbox isolation, which poses serious security risks. The recommendation is to default to least privilege, read-only mounts, and network isolation, and to keep an audit trail for all tool calls.
In summary, the key to building a general-purpose agent is not chasing a single parameter metric, but turning foundation capabilities, knowledge governance, orchestration constraints, and observability into an engineering loop that is iterable, rollback-capable, and measurable.
