Agentic Flows

When agents help. When they don't.

I build agentic workflows with Python, n8n, and code-first agent frameworks. Here's what I've learned about when to give an AI agent tools — and when a simple function does the job better.

The first question: agent or function?

f()

Use a function when:

  • • The logic is programmable (if/else, lookup, transform)
  • • The input and output formats are fixed
  • • Reliability matters more than flexibility
  • • You can test it with unit tests
🤖

Use an agent when:

  • • The task requires reasoning over ambiguous input
  • • Multiple tools need to be chained dynamically
  • • The path to the answer depends on intermediate results
  • • A human would need to “think about it”

How I build them.

If you can program it, don't LLM it.

Deterministic logic is faster, cheaper, and more reliable. Agents are for decisions that require reasoning — not for if/else statements wrapped in natural language. That's just expensive spaghetti.

Consolidate tools. Reduce LLM calls.

One well-designed tool that returns everything beats five tiny tools the agent has to chain together. Each LLM call is latency, cost, and a chance to hallucinate. In my experience, code agents use significantly fewer calls than tool-calling agents.

Model selection is a resource decision.

Stronger models for complex reasoning. Lighter models for simple routing. Using a 70B model to parse a date is waste. Using a 7B model for multi-step planning is a gamble. Match the model to the task.

Transparency is not optional.

Execution traces for every agent run. Detailed error logging so the LLM can self-correct. If you can't explain what the agent did and why, you can't audit it — and you can't trust it.

Escalation is designed, not improvised.

Five triggers: uncertainty above threshold, negative sentiment, complexity exceeded, timeout, error rate. When any fires, a human takes over. Not because the agent failed — because the system is designed to know its limits.

The tools I use

smolagents for code-first agents that write Python instead of structured JSON tool calls — lightweight, auditable, transparent execution traces. Claude Code for complex reasoning and multi-file tasks. n8n for visual workflow automation with human-in-the-loop. Custom Python pipelines when the task needs full control. I pick the tool that fits the problem, not the one that sounds impressive.

Building something that needs to be reliable? Let's talk.

hi@lexi-energy.com →