Building Autonomous Agents with Smolagents and Novita AI

Key Highlights

1.AI Agent:
Enables autonomous decision-making beyond rigid, predefined workflows.
Leverages iterative reasoning, adaptive execution, and continuous learning.

2. Smolagents:
Lightweight Python library (~1,000 lines), simplifying AI-agent creation.
Directly outputs actionable Python code snippets securely executed in sandboxed environments.
Supports diverse models, modalities (text, images, audio, video), and external tool integration.

3. Novita AI Support:
Compatible with Smolagents, supporting powerful models like DeepSeek R1 Turbo with enhanced performance and affordability.

Artificial intelligence has evolved from recognizing patterns to generating creative content. The next significant leap is the emergence of agentic AI, systems capable of autonomous decision-making and action to solve complex, multi-step problems. This article explores the concept of AI agents, delves into the specifics of code agents, outlines how one might be built, discusses the performance of different underlying models, and addresses frequently asked questions about this transformative technology.

What is AI Agent?

Agentic AI addresses the challenges presented by tasks that traditional, rigid workflows struggle to handle effectively. Many real-world scenarios involve complex, nuanced processes that cannot be captured fully by static, pre-defined if-else structures. Agentic AI introduces flexibility and adaptability into workflows, empowering systems to dynamically determine and execute the optimal sequence of actions based on evolving contexts.

How it work?

Agentic AI operates through an iterative, dynamic loop of perceiving, reasoning, acting, and learning. At its core, AI agents utilize Large Language Models (LLMs) as reasoning engines to analyze situations, plan responses, coordinate specialized models, and execute tasks. The workflow typically involves the following steps:

  • Data Ingestion and Perception: Agents gather and process data from multiple sources, gaining contextual awareness to inform their decision-making processes.
  • Reasoning and Planning: Using LLMs, agents interpret data, reason about possible solutions, generate strategic plans, and determine necessary actions to achieve their goals.
  • Action and Execution: Agents integrate with external tools and predefined functions, executing tasks based on their reasoning outputs. They iteratively perform actions, observe outcomes, and adjust accordingly until they achieve the desired result.
  • Continuous Learning: Through feedback loops and techniques such as Retrieval-Augmented Generation (RAG), agents access proprietary data sources, refine their understanding, and continuously improve their performance, accuracy, and relevance.

By combining these capabilities—autonomous decision-making, iterative reasoning, integration of external tools, and continuous improvement—Agentic AI effectively bridges LLM-based reasoning with real-world execution and adaptation.

from Nvidia

What is smolagents?

Smolagents is a lightweight Python library designed to simplify building powerful AI agents. With a minimalistic approach, its core logic fits within roughly 1,000 lines of code, providing minimal abstractions and greater direct control for developers. Smolagents is positioned as the successor to transformers.agents, which will eventually be deprecated. You can know more details on github!

amolagents

Key Features and Key Mechanism

✨ Simplicity

  • Smolagents implements powerful AI agent logic in about 1,000 lines of code, keeping abstractions minimal for greater developer flexibility (see agents.py).

🧑‍💻 First-Class Code Agent Support

  • Smolagents’ CodeAgent directly outputs agent actions as Python code snippets rather than JSON or text, improving efficiency and performance. It securely executes code within sandboxed environments (E2B, Docker) and maintains support for traditional JSON/text-based agents.

🤗 Hub Integrations

  • Smolagents allows easy sharing and loading of reusable Python-based tools via Hugging Face Hub, streamlining collaboration and tool reuse.

🌐 Model-Agnostic

  • Smolagents supports virtually any Large Language Model (LLM)—local transformers or ollama models, Hugging Face-hosted models, and external providers like OpenAI or Anthropic via LiteLLM.

👁️ Modality-Agnostic

  • Agents created with Smolagents can seamlessly handle diverse input modalities, including text, images, videos, and audio.

🛠️ Tool-Agnostic

  • Smolagents flexibly integrates tools from various ecosystems, such as LangChain, Anthropic’s MCP, or Hugging Face Hub Spaces.
how smolagents woorks

How to Build an Agent using smolagents with Novita AI API?

Novita AI is an AI cloud platform that offers developers an easy way to deploy AI models using our simple API, while also providing the affordable and reliable GPU cloud for building and scaling.

Smolagents supports various Large Language Models (LLMs), including Novita AI! Next we will use deepseek r1 turbo as an example to show the power of smolaents and Novita AI!

Significantly, Novita AI launches a Turbo version with 3x throughput and a limited-time 60% discount!

novita ai no1

An Example

Input:

import os
from smolagents import OpenAIServerModel, CodeAgent, DuckDuckGoSearchTool

model = OpenAIServerModel(
    model_id="deepseek/deepseek-r1-turbo",
    api_base="https://api.novita.ai/v3/openai",
    api_key="Your API Key" # Switch to the API key for the server you're targeting.
)

agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)

agent.run("Please plan a weekend trip from Shanghai to Beijing, including transportation options, itinerary arrangements and a list of must-haves")

Output:

transport = web_search(query="Shanghai to Beijing transportation weekend trip 2024")                                                                                                                                                                                                                                                           
  print("Transportation options:", transport)                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                 
  attractions = web_search(query="Beijing 2-day itinerary top attractions 2024")                                                                                                                                                                                                                                                                 
  print("Attraction recommendations:", attractions)                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                 
  details = web_search(query="Beijing travel must-haves 2024")                                                                                                                                                                                                                                                                                   
  print("Essential items and tips:", details)                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                 
  weekend_plan = {                                                                                                                                                                                                                                                                                                                               
      "Transportation": {                                                                                                                                                                                                                                                                                                                        
          "Recommended Option": "Friday evening G12 train (18:00-22:30) from Shanghai Hongqiao to Beijing South",                                                                                                                                                                                                                                
          "Alternative": "Saturday morning flight (07:00-09:00+transit time)"                                                                                                                                                                                                                                                                    
      },                                                                                                                                                                                                                                                                                                                                         
      "Itinerary": {                                                                                                                                                                                                                                                                                                                             
          "Day 1 (Saturday)": [                                                                                                                                                                                                                                                                                                                  
              "08:30 - Tiananmen Square (free entry)",                                                                                                                                                                                                                                                                                           
              "10:00 - Forbidden City (booked ticket, 3-4hr tour)",                                                                                                                                                                                                                                                                              
              "14:00 - Temple of Heaven",                                                                                                                                                                                                                                                                                                        
              "Evening: Houhai Lake dinner + hutongs exploration"                                                                                                                                                                                                                                                                                
          ],                                                                                                                                                                                                                                                                                                                                     
          "Day 2 (Sunday)": [                                                                                                                                                                                                                                                                                                                    
              "07:00 - Depart for Mutianyu Great Wall (book shuttle/taxi)",                                                                                                                                                                                                                                                                      
              "09:00-12:00 - Great Wall visit (cable car recommended)",                                                                                                                                                                                                                                                                          
              "14:00 - Summer Palace",                                                                                                                                                                                                                                                                                                           
              "18:00 - Return to city, take G27 train (19:00-23:18) back to Shanghai"                                                                                                                                                                                                                                                            
          ]                                                                                                                                                                                                                                                                                                                                      
      },                                                                                                                                                                                                                                                                                                                                         
      "Must-Haves": [                                                                                                                                                                                                                                                                                                                            
          "Pre-booked Forbidden City ticket (¥60)",                                                                                                                                                                                                                                                                                              
          "Comfortable walking shoes",                                                                                                                                                                                                                                                                                                           
          "Layered clothing (check weather forecast)",                                                                                                                                                                                                                                                                                           
          "Portable WiFi/power bank",                                                                                                                                                                                                                                                                                                            
          "WeChat Pay/Alipay balance",                                                                                                                                                                                                                                                                                                           
          "ID/passport for train ticket collection"                                                                                                                                                                                                                                                                                              
      ]                                                                                                                                                                                                                                                                                                                                          
  }                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                 
  final_answer(weekend_plan)                                       

Final Answer

Final answer: {'Transportation': {'Recommended Option': 'Friday evening G12 train (18:00-22:30) from Shanghai Hongqiao to Beijing South', 'Alternative': 'Saturday morning flight (07:00-09:00+transit time)'}, 'Itinerary': {'Day 1 (Saturday)': ['08:30 - Tiananmen Square (free entry)', '10:00 - Forbidden City (booked ticket, 3-4hr tour)', '14:00 - Temple of Heaven', 'Evening: Houhai Lake dinner + hutongs exploration'], 'Day 2 (Sunday)': ['07:00 - Depart for Mutianyu Great Wall (book shuttle/taxi)', '09:00-12:00 - Great Wall visit (cable car recommended)', '14:00 - Summer Palace', '18:00 - Return to city, take G27 train (19:00-23:18) back to Shanghai']},         
'Must-Haves': ['Pre-booked Forbidden City ticket (¥60)', 'Comfortable walking shoes', 'Layered clothing (check weather forecast)', 'Portable WiFi/power bank', 'WeChat Pay/Alipay balance', 'ID/passport for train ticket collection']}

Comparing Model Performance in smolagents

smolagents llm leaderboard
You can see more detail on Huggig Face

Agentic AI represents a major advancement in artificial intelligence, empowering autonomous problem-solving and task execution. The Smolagents library provides a lightweight yet powerful framework designed specifically for building intelligent agents, emphasizing direct code-based actions and compatibility with a wide variety of Large Language Models (LLMs). As open-source models continue to improve rapidly, Smolagents offers developers an accessible and versatile toolkit to explore and implement the exciting potential of agentic AI across diverse domains.

Frequently Asked Questions

What is the key difference between agentic AI and generative AI?

Generative AI focuses on creating new content like text and images, while agentic AI focuses on making decisions and performing autonomous tasks to achieve goals.

Is executing code in smolagents secure?

smolagents provides options for secure code execution, including a sandboxed environment using E2B or Docker, which removes the risk to your local system.

Where can I find more information about smolagents?

You can find full documentation, tutorials, and examples on the smolagents GitHub repository and the Hugging Face Space dedicated to the library.

Novita AI is the All-in-one cloud platform that empowers your AI ambitions. Integrated APIs, serverless, GPU Instance — the cost-effective tools you need. Eliminate infrastructure, start free, and make your AI vision a reality.

Recommend Reading


Discover more from Novita

Subscribe to get the latest posts sent to your email.

Leave a Comment

Scroll to Top

Discover more from Novita

Subscribe now to keep reading and get access to the full archive.

Continue reading