Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Course
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM Tools
Machine Learning
Machine Learning & AI
Machine Learning Tools
Manage Data
MLOps
Natural Language Processing
Newsletter Archive
NumPy
Pandas
Polars
PySpark
Python Helpers
Python Tips
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Newsletter #313: smolagents: Build an AI Agent in 4 Lines of Code

Newsletter #313: smolagents: Build an AI Agent in 4 Lines of Code

Grab your coffee. Here are this week’s highlights.


📅 Today’s Picks

Claude Code: Run Tasks to Completion with /goal

Code example: Claude Code: Run Tasks to Completion with /goal

Problem

Starting a task in Claude Code often means spending multiple turns going back and forth before it finally reaches the result you wanted.

Solution

Claude Code‘s /goal command lets you define a completion condition once, then continues working until that condition is met.

After each turn, a lightweight model evaluates the conversation against your condition. If the goal is not satisfied, Claude gets sent back for another turn with a short explanation of what still needs to be done.

To get the most out of /goal, write a condition the evaluator can actually verify.

  • Name a measurable end state instead of a vague target (e.g. “all tests in test/auth pass” instead of “auth is working”)
  • List constraints that must hold along the way (e.g. “no other test file is modified” or “no tests are skipped or deleted”)
  • Add a safety limit like “stop after 20 turns” to avoid endless iterations.

smolagents: Build an AI Agent in 4 Lines of Code

Code example: smolagents: Build an AI Agent in 4 Lines of Code

Problem

LangChain and LangGraph are powerful, but they also come with concepts like chains, runnables, and state graphs.

That is useful for complex workflows, but overkill when you just want to give a model a tool and let it solve a task.

Solution

smolagents from Hugging Face is a barebones agent library designed for simplicity.

In roughly 1,000 lines of code, it gives you the core pieces needed to build a working agent with a single import and three lines of setup.

Key features:

  • Agents act by writing Python in a sandbox, the same way you’d script a task in a notebook
  • Model-agnostic design, swap between OpenAI, Anthropic, local Ollama, or Hugging Face Inference
  • Push agents to the Hugging Face Hub to share with the community

Stay Current with CodeCut

Actionable Python tips, curated for busy data pros. Skim in under 2 minutes, three times a week.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran