DEV Community

Cover image for Building AI with AI
TS Lim
TS Lim

Posted on Originally published at clipsoflogic.com

Building AI with AI

In my previous posts, I've shared more about my AI workflows, extensions and tooling to help manage my administrative tasks at work. I've also explored how you can use AI to learn anything by getting it to build interactive guides and learning experiences.

This time, I want to share some lessons I've learned from building software with AI (coding agents) and also building AI-powered systems at work. Most of these insights come from hands-on experience building a few projects, primarily using Pi.dev and Cursor IDE, powered by OpenAI Codex and Cursor subscriptions.

Building with AI

First, let's talk about using AI coding agents to design and develop software. I build mostly web applications, so some these lessons may not apply to other types of software. Still, I think many of the principles are general enough to be useful regardless of what you're building.

1. Models are getting really good

Every few months, we get bigger and better models from the frontier labs. But things have moved and improved so much that even the smaller, open-weight models are now good enough for coding, especially for well-scoped problems and tasks.

Frontier models often feels smarter and better because they seem more capable of filling in the gaps when we don't provide enough details. They have stronger reasoning, broader knowledge and a better ability to infer intent, so it can sometimes feel like they are reading your mind. But if we are being honest, most of the time we haven't actually thought through what we want and are just glad they're able to fill in the gaps.

The danger here is that if we never thought about what we really want, the assumptions made by the models aren't necessarily correct and can take us down the wrong trajectory. Like a really smart person, they can provide really convincing justification for why their proposed solutions make sense. If we don't understand the domain well enough, we can easily be taken along for the ride.

2. Plans and research are useful up to a point

Most coding agents have a plan mode, which you should definitely leverage whenever possible. It helps you shape the problem and review the proposed solution before implementation.

You can also ask them to research alternative solutions and run experiments or spikes to validate assumptions, especially for changes that impact a large portion of your codebase.

However, remember that models are probabilistic and may not have all the required context, so plans and research can still miss things. The larger the scope you ask an agent to cover, the more opportunities there are for things to go wrong and the harder it becomes for you to comprehend and review the proposed changes.

I like to ask for diagrams, request flow or other visualizations to help me understand the proposed solution. Your input in scoping the problem, providing constraints and making strategic choices goes a long way towards building the right thing.

3. Treat the agent like a fellow developer

This may not be obvious to some of you, but I like to think of and talk to a coding agent as if it were another developer. Brief it as you would someone taking over a project from you and review its work by probing areas you think are important.

Give it as much context and background information as you can about the problem. Explain what you think the approach should be and discuss the trade-offs. Collaborate with the agent rather than viewing it simply as a machine that spits out code.

Recently I tried using Nico Bailon's pi-better extension, which rewrites your prompt using Felix Rieseberg's "Depth" prompt. It grounds the prompt in your existing code and files, giving the agent additional context that you might not have explicitly provided without expanding the scope of the task.

However, much like working with people, agents can sometimes become overly focused on a particular requirement and over-engineer a solution just to make sure it is satisfied. Even though you're collaborating with the agent, you're still the decision maker. You need to consciously play that role rather than delegate those decisions to it.

4. Don't trust the guardrails blindly

One of the best practices is to define an AGENTS.md / CLAUDE.md instruction file containing coding guidelines, guardrails and dos & don'ts for your codebase. These instructions provide the agent with guidance on how it should work and what it should or shouldn't do.

However, models are non-deterministic. Giving the same prompt twice doesn't guarantee the same result. We shouldn't rely solely on these instructions to ensure compliance. Prefer actual code-based checks such as linters, type checkers and tests, wherever possible. Also, limit the agent's permission and access through your coding harness to prevent it from doing things it shouldn't.

Beware of reward hacking, particularly when asking agents to fix failing tests or change existing behavior. They might modify the test to make them pass or change a feature to match what the test expects, rather than addressing the underlying issue. Just because the tests are green doesn't mean the solution is correct.

5. Your eyes are still important

In the past, we tended to skip tests or not write enough of them. With coding agents, they will almost always write tests by default, and sometimes it can feel like they write too many. You may need to challenge them on whether all those tests are necessary.

As agents get better at using computer and browsers, I find them very useful as manual QA testers. You can simply ask them to test the application and explore whether things are working as expected. Since they can also read the related code, the bug reports they produce can be valuable input for the coding agent to investigate and fix.

That said, nothing beats using the application yourself to discover problems and issues. You have a better understanding of how things should work and it's difficult for an agent to evaluate usability, visual consistency, interaction patterns and overall feel of an application.

Building AI-powered applications

Now, let's talk about some of the insights and lessons I've learned building AI-powered workflows and applications. These are based on actual projects I've worked on, but it's obviously not an exhaustive list. The lessons are also limited to the types of features and capabilities I've worked with.

1. Look at your RAG extraction and retrieval first

One of the most common types of AI-powered applications I've worked on is a RAG (Retrieval-Augmented Generation) system where you can ask an AI agent to search through a corpus of documents or knowledge base and return relevant information.

Naturally, the accuracy of the results is critical. It's worth starting at the ingestion stage and checking whether information is being extracted from the source documents properly. You can't retrieve information that wasn't captured in the first place.

Extracting text is generally more reliable than extracting information from diagrams, graphs and other visual content. Some services can convert these into text descriptions, making the information easier to chunk and retrieve. Don't overlook metadata such as document structure, page numbers and annotations either. These can provide useful context during retrieval and help trace information back to its source.

Next, review your retrieval strategies and algorithms before tweaking your agent's prompt or switching to a better model. Don't assume your RAG accuracy problem is an LLM problem. First, verify that you have extracted the right information and that your retrieval process is actually finding it.

2. You don't always need an LLM

In many agentic workflows, people have a tendency to rely too much on LLMs for things that deterministic code could perform much better and more reliably. LLMs are smart and can handle irregular inputs, but they're also much slower and more expensive than a few simple if statements.

Here are some examples of things you should generally avoid using LLMs for: calculations, enforcing business rules or permissions, validating data against a fixed set of requirements and orchestrating a predefined sequence of workflows. These are tasks where the expected behavior is known and can be expressed clearly in code.

Reserve LLMs for situations where you actually need reasoning or where interpreting the input isn't straightforward. For example, understanding a user's intent, extracting information from unstructured content or deciding which workflow should handle a request.

Even then, you don't always need the most capable reasoning model. System 1 Models or decision models such as TypeSafe Jev, OpenAI Decisions API and Gemini Decision 1 allow us to make fast probabilistic decisions within our workflows.

In fact, you can just ask your coding agent to review your workflow and identify which parts should be handled by deterministic code instead. It can even help you implement them. The key to building a robust agentic workflow is knowing where to use LLMs and just as importantly, where not to.

3. Enforce constraints outside the model

Just as you shouldn't blindly trust the guardrails set up around your coding agent, you should enforce and limit a model's capabilities through the harness or runtime it's operating in, rather than relying on prompts.

If you need to ensure a tool respects the user's access and permission levels, don't rely on the model to pass the correct user information to the tool. The tool itself should enforce those checks and constraints, using trusted identity and permission information that the model cannot manipulate.

Similarly, you can prompt your agent to always require human approval and implement a Human-in-the-Loop (HITL) approval process but the approval requirements need to be enforced by your harness, tools and runtime. The best way to prevent your model from doing something is to remove its ability to do it in the first place.

4. Understand your agentic primitives

It's important to have the right mental model of agents and how they work. By understanding the fundamental building blocks of an agentic system, you'll be able to combine them to create different types of agentic applications and workflows.

Here are some primitives to get you started. This space is evolving quickly, so make sure you keep up with the latest development.

Primitive What it represents
Model The underlying intelligence that interprets information, reasons and generates responses.
Instructions What the agent is supposed to do, including its role, objectives and behavioural constraints.
Tools What the agent can do, including interacting with external systems, retrieving information and executing actions.
Context Information available to the model when making decisions, including instructions, conversation history and retrieved information.
Session / State Information maintained during an interaction or task, including progress, intermediate results and execution state.
Memory Information retained for future use, such as user preferences, past experiences and accumulated knowledge.
Harness / Runtime The system that executes and manages the agent, including its environment, tool access and execution lifecycle.
Orchestration How multiple steps, workflows or agents are coordinated to accomplish a task.
Guardrails Controls around inputs, outputs and actions, including permissions, validation and human approval.

Use these primitives to build prototypes that emulate agentic products and workflows you see in the market. Design a deep research agent that can plan, conduct web searches across the internet and put together a report. Figure out how to build a Personal Agent like GrokBot, Instinct or Muse.

The best way to learn to build AI systems is to build one yourself, with the help of AI, of course.

5. Observe, evaluate and optimize your agents

When working with agentic systems, make sure you have some way to observe what's happening behind the scenes. Set up observability tools like MLflow to capture traces of your LLMs and tool executions. This allows you to see what exactly is sent to and returned from LLMs, which tools are executed and what results they produced.

These traces are invaluable when you are trying to figure out what's wrong or how to improve the performance, efficiency and latency of your system. You can even paste the full traces into your coding agent and ask it to help debug the issue. Agents can be quite persistent in trying to complete their tasks and their tool execution trajectories aren't always the most efficient in terms of token usage or number of tool calls.

You can also setup evaluations (Evals) to regularly check whether your agentic workflows are still behaving as expected as you tweak and update your system. They can help detect model drift and regressions as you improve your prompts, switch models and optimize your workflow.

Building in the age of AI

As AI agents continue to improve, they have greatly accelerated our ability to build software and complex systems. Things that used to take weeks can now be done in hours or even minutes. This changes the calculus of what's possible and opens up all sorts of new possibilities for us to explore.

But I've come to realize that we can only reliably move as fast as our mental models allow us to. When the agent executes faster than our understanding, we lose sight of the bigger picture. We may build something that works, but don't really understand how or why it works. Sometimes, we don't even know if it's what we intended to build.

Maybe as the models continue to improve and the tooling matures, many of these problems will become a thing of the past. Some of these insights and lessons may no longer be applicable by then. But I suspect that, as builders, we will always need to be clear on what we intend to build.

Top comments (1)

Collapse
 
alexshev profile image
Alex Shev •

Using AI to build AI is most productive when the feedback loop is grounded in executable evidence. I’d keep generated changes small, attach tests or evaluation cases to each claim, and record the model and tool versions used. That preserves speed while keeping the system debuggable when behavior shifts.