Why You Don't Need a Framework to Build an AI Agent

    A practical look at why framework dependency is a false requirement in agent development. Learn how to handle the four core components—planning, memory, retrieval, and tool calling—with minimal general-purpose code, and when adding a dependency is actually justified.

    Why You Don’t Need a Framework to Build an AI Agent

    1. Why “Framework Dependency” Is a False Problem

    In early discussions about agent engineering, a common misconception is to tie “capability” to “framework,” as if no usable agent could be built without a ready-made orchestration library. The reality is the opposite. An agent is essentially a controlled loop: receive input, determine intent, invoke capabilities, integrate results, maintain context, and continue to the next round when necessary. Every step in this loop is an engineering problem that can be expressed in a few dozen lines of general-purpose code.

    The value of a framework is that it packages common patterns into easy-to-assemble building blocks and lowers the communication cost of a first build. At the same time, it introduces abstraction layers, version churn, and a debugging black box. When a product actually reaches production, success is usually determined by latency, cost, observability, and fallback on failure—and these require developers to have a clear grasp of the underlying flow. A more pragmatic test is therefore: Is there irreplaceable engineering complexity in this step? If not, there is no need to add an extra dependency for it.

    2. Planning: Write the Flow Down Instead of Letting the Model Imagine

    Planning makes the solution path explicit for the model. Common forms include workflow orchestration, chain-of-thought reasoning, and lightweight thinking modes. Their engineering costs differ significantly.

    • Fixed workflow: Business steps are written explicitly as nodes and branches. This offers the strongest control and predictable latency, and fits scenarios with stable flows such as reviews, ticketing, and data processing.
    • Chain-of-thought reasoning: The model outputs its full reasoning process. It works well but is slow and expensive, and is often unacceptable in real-time interactions with end users.
    • Lightweight thinking mode: Only a brief internal trade-off is kept before the conclusion. Simple and direct, it is currently the best cost-performance compromise.

    Workflow orchestration itself is not mysterious; it is an executor with state and branches:

    1. def run_workflow(state: dict) -> dict:
    2. intent = classify(state["query"]) # Intent classification
    3. if intent == "simple":
    4. state["answer"] = llm(state["query"]) # Answer directly
    5. return state
    6. ctx = retrieve(state["query"]) # Retrieve only when knowledge is needed
    7. state["answer"] = llm(state["query"], ctx)
    8. return state

    What really deserves investment is branch design: which questions take a shortcut, which must be verified, and how to degrade on failure. Complex forms that require iterative planning are still mostly at the research stage, because the latency and uncertainty of multiple rounds of “thinking” are hard for users to wait through.

    3. Memory: The Engineering Essence of Short-Term Memory Is Subtraction

    Context management across multiple turns works by maintaining a full copy of the conversation, then extracting key fragments and submitting them with the new question to the model. Its core goals come down to two words: save money, save time. Concrete strategies include removing redundant information while keeping key conclusions, discarding expired messages while keeping the latest intent, and dropping ineffective retrieval results while keeping highly relevant data.

    A working context trimmer looks roughly like this:

    1. def build_context(messages, max_tokens=3000, keep_recent=4):
    2. summary = summarize(messages[:-keep_recent]) # Compress history into a summary
    3. recent = messages[-keep_recent:] # Keep the most recent turns
    4. return [ {"role": "system", "content": summary} ] + recent

    Notably, even leading general-purpose chat products often suffer from information “bleeding” across sessions: stale information from other conversations is carried into the current one and derails the answer. This shows that context isolation and ownership tagging are general problems, not a specific weakness of any one tool. In engineering terms, sessions should be given separate namespaces at the storage layer, and retrieval should be forced to filter by session identifier.

    4. Retrieval: Decide Whether to Search Before Deciding How

    The key decision in retrieval augmentation is not which vector database to choose, but whether retrieval is needed at all. Answer simple questions directly; query the knowledge base only for complex or time-sensitive questions. This layer of short-circuiting improves both latency and cost.

    The signals can be combined: whether the question contains proper nouns, whether it triggers domain keywords, whether confidence falls below a threshold, and whether the previous turn already failed once. Illustrative logic:

    1. def need_retrieval(q, confidence):
    2. return (has_domain_term(q) or confidence < 0.6)

    On the storage and indexing side, vector databases and graph databases each have their strengths: the former excels at semantic similarity matching, the latter at explicit relationship reasoning. Deployment can be self-hosted locally or use general-purpose cloud capabilities—for example, a container platform hosting the index service, object storage holding the original documents, and logging and monitoring services with alerting handling observability. Approximate nearest neighbor (ANN) search is a common approach; parameter tuning focuses on balancing recall and latency, and must be measured against the actual business data distribution rather than copying default configurations.

    5. Tool Calling and a Practical Checklist

    Tool calling does not require a framework either: write the tool description, parameter schema, and return value contract clearly, let the model output a structured call intent, and have a local executor validate and run it. Five points are worth attention in practice:

    1. Write a minimum viable version of each step first, then decide whether to introduce a dependency;
    2. Isolate context strictly by session to avoid information pollution;
    3. Log the latency, tokens, and failure reason for every model call to establish an observability baseline;
    4. Set timeouts, retries, and fallback answers for retrieval and tool calls;
    5. Build a regression set from real business samples; tune before switching frameworks.

    Conclusion: The barrier to building agents has never been a framework checklist, but the depth of understanding and patience for tuning across the four areas of planning, memory, retrieval, and tools. With these general capabilities in hand, you can either start quickly with an existing orchestration library or build your own without a framework when needed—the latter is often more controllable in production.