- Home
- Services
- IVY
- Portfolio
- Blogs
- About Us
- Contact Us
- Sun-Tue (9:00 am-7.00 pm)
- infoaploxn@gmail.com
- +91 656 786 53
The emergence of AI agents presents a transformative opportunity for enhancing travel guidance. These intelligent systems, powered by large language models (LLMs), possess the capability to dynamically address user needs by observing their environment, formulating plans, and executing those plans through the use of various tools 1. Unlike traditional, static approaches to travel information, AI agents offer a level of adaptability that is particularly well-suited to the complexities of real-world travel scenarios 2. In the context of travel guidance, these agents can automate a wide array of tasks, ranging from the initial retrieval of information to the intricate planning of entire itineraries, all while taking into account individual user preferences 4. This inherent dynamism allows for the creation of personalized and adaptive travel experiences, moving beyond the limitations of pre-existing, fixed information sources 1. The increasing sophistication of user travel queries, which often involve numerous constraints and specific desires 3, further underscores the necessity for the flexible problem-solving capabilities that AI agents can provide.
Hugging Face’s Smolagents library offers a streamlined approach to constructing such intelligent agents. This lightweight framework is specifically designed to enable developers to build powerful AI agents with a minimal amount of code 1. The core logic of the library is intentionally concise, residing within approximately a thousand lines of code 10. A central concept within Smolagents is that of "Code Agents," where the actions undertaken by the agent are expressed as snippets of Python code. This method of action representation offers advantages in terms of composability and overall flexibility when compared to other frameworks that rely on JSON or natural language formats 1. Key features of Smolagents include its broad compatibility with various LLMs, including those hosted on the Hugging Face Hub, as well as models from OpenAI and Anthropic through LiteLLM integration 1. The library also facilitates the easy creation of custom tools, allowing developers to extend the agent’s capabilities to specific domains, and it integrates seamlessly with the Hugging Face Hub for the purpose of sharing and loading these tools 1. Furthermore, Smolagents prioritizes security by supporting the execution of code within sandboxed environments like E2B and Docker 8. The emphasis on Code Agents within Smolagents leverages the extensive training that LLMs have undergone on programming languages. This focus potentially leads to more effective and accurate agent behavior as the LLM can directly generate and understand actions expressed in a format it has been extensively trained on 2.
To begin working with Smolagents, the development environment needs to be properly set up. The library can be easily installed using the Python package manager, pip, with the command pip install smolagents 1. Accessing certain advanced models on the Hugging Face Hub or utilizing the services of paid LLM providers like OpenAI and Anthropic often requires users to obtain API tokens 1. These tokens serve as authentication credentials and can typically be created through the user’s account settings on the respective platforms.
At the core of Smolagents are three fundamental concepts: models, tools, and agents. Models refer to the large language models that serve as the "brain" of the agent, responsible for its reasoning and decision-making processes. Smolagents exhibits model-agnosticism, supporting a variety of LLMs through different model classes. For instance, HfApiModel provides an interface to models on the Hugging Face Hub, while LiteLLMModel enables access to a wide range of models from various providers 11. Tools are the mechanisms through which an agent interacts with the external world. They are essentially functions that the agent can call to perform specific tasks. A tool requires a defined name, a clear description of its function, specifications for its input and output types, and a forward method containing its core logic 1. For simpler tools, the @tool decorator can be used to streamline their definition 8. Smolagents comes equipped with several built-in tools, such as the DuckDuckGoSearchTool, which allows the agent to perform web searches 1. Finally, agents are the central entities that bring together models and tools to accomplish specific objectives. Smolagents offers different types of agents, notably the CodeAgent, which writes and executes Python code to achieve its goals, and the ToolCallingAgent, which expresses its actions as JSON-like structures 8. The default agent type in Smolagents is the CodeAgent.
A Model refers to the large language model powering the agent. For example, you might use HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct") as your model.
A Tool is a function the agent can use to interact with the world—this could be something like DuckDuckGoSearchTool()
for web searches, or a custom function decorated with @tool
.
A CodeAgent is an agent designed to write and execute Python code. You’d typically initialize it with a list of tools and a model, like CodeAgent(tools=[...], model=...)
.
A ToolCallingAgent is a type of agent that doesn’t directly execute tools but instead outputs actions as JSON-like blobs. You can set it up similarly with ToolCallingAgent(tools=[...], model=...)
.
The initial step in creating a travel guide agent involves building a fundamental capability: answering simple travel-related questions. This can be achieved by equipping an agent with the ability to search the web for information. The CodeAgent in Smolagents, when combined with the built-in DuckDuckGoSearchTool, provides a straightforward way to implement this.
The following Python code demonstrates the creation of such a basic travel information agent:
Python from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel model = HfApiModel() # Uses a default free model agent = CodeAgent(tools=, model=model) query = "What are the top attractions in London?" response = agent.run(query) print(response)
In this example, we first import the necessary classes from the smolagents library: CodeAgent, DuckDuckGoSearchTool, and HfApiModel. We then initialize an HfApiModel without specifying a particular model ID, which means it will utilize a default, freely available model from the Hugging Face Hub. Next, we instantiate a CodeAgent. The crucial part here is the tools argument, which is a list containing a single element: an instance of DuckDuckGoSearchTool. This provides our agent with the ability to perform web searches using the DuckDuckGo search engine. We also pass the initialized model to the CodeAgent. After setting up the agent, we define a travel-related question as a string and store it in the query variable. Finally, we use the run() method of our agent object, passing the query as an argument. This initiates the agent’s process of using the DuckDuckGoSearchTool to find an answer to the question. The result of this process, which will be the agent’s response, is stored in the response variable and then printed to the console. This basic implementation allows the agent to answer a variety of simple travel-related questions, such as "Find the best time to visit Paris," "What is the currency used in Japan?" or "Tell me about the Eiffel Tower." Even with this fundamental setup, Smolagents enables the rapid creation of functional agents capable of retrieving information from the vast resources available on the web 10. The inclusion of a pre-configured tool like DuckDuckGoSearchTool simplifies the process of granting the agent a valuable capability without requiring the user to define it from scratch.
To create a more specialized and useful travel guide agent, it becomes necessary to extend its capabilities beyond general web searching. This can be achieved by creating custom tools that perform specific travel-related functionalities. Examples of such functionalities include fetching current weather information for a given location and estimating the travel time between two points. Smolagents makes it easy to define these custom tools using the @tool decorator.
Below are conceptual code examples illustrating how to create custom weather and travel time tools:
travel time tools: Python from smolagents import tool import requests import json @tool def get_weather(location: str) -> str: """ Fetches the current weather for a given location using a weather API. Args: location: The city and country for which to fetch the weather. Returns: A string describing the current weather conditions. """ apikey = "YOURWEATHERAPIKEY" # Replace with your actual API key base_url = "http://api.openweathermap.org/data/2.5/weather?" completeurl = baseurl + "appid=" + api_key + "&q=" + location + "&units=metric" response = requests.get(complete_url) data = json.loads(response.text) if data["cod"] != "404": main_data = data["main"] temperature = main_data["temp"] humidity = main_data["humidity"] weather_description = data["weather"]["description"] return f"The current weather in {location} is {weather_description} with a temperature of {temperature}°C and humidity of {humidity}%." else: return "Weather information not found for the specified location." Python from smolagents import tool import googlemaps # Requires googlemaps package and API key @tool def gettravelduration(startlocation: str, endlocation: str, mode: str = "driving") -> str: """ Estimates the travel time between two locations using Google Maps API. Args: start_location: The starting point of the journey. end_location: The destination of the journey. mode: The mode of transportation (driving, walking, bicycling, transit). Defaults to ’driving’. Returns: A string describing the estimated travel duration. """ gmaps = googlemaps.Client(key="YOURGOOGLEMAPSAPIKEY") # Replace with your actual API key directionsresult = gmaps.directions(startlocation, end_location, mode=mode) if directions_result: duration = directions_result["legs"]["duration"]["text"] return f"The estimated travel time between {startlocation} and {endlocation} by {mode} is {duration}." else: return "Could not estimate travel time for the given locations and mode."
These code snippets demonstrate the creation of two custom tools, getweather and gettravelduration, using the @tool decorator. Each tool is defined as a Python function with a clear docstring that explains its purpose, the arguments it accepts, and the type of information it returns 1. This docstring serves as essential documentation for the agent, guiding it on how to properly use each tool. The getweather tool, in this conceptual example, interacts with a weather API (like OpenWeatherMap) to retrieve current weather conditions based on a provided location. Similarly, the gettravelduration tool utilizes the Google Maps API to estimate the travel time between two specified locations, considering a chosen mode of transportation. It’s important to note that using these external APIs would require the user to obtain the necessary API keys from the respective service providers.
To integrate these custom tools into our travel guide agent, we can include them in the list of tools provided when initializing a CodeAgent:
Python model = HfApiModel() tools = agent = CodeAgent(tools=tools, model=model) query = "What’s the weather like in Paris and how long would it take to travel from Paris to Rome by train?" response = agent.run(query) print(response)
In this enhanced setup, the agent now has access to three tools: the DuckDuckGoSearchTool for general web searches, the getweather tool for retrieving weather information, and the gettravel_duration tool for estimating travel times. When the agent receives a user query, such as "What’s the weather like in Paris and how long would it take to travel from Paris to Rome by train?", it can now intelligently choose to utilize the most appropriate tool(s) to address the different parts of the request. The ability to create custom tools allows for a significant extension of the agent’s capabilities, enabling it to address very specific domain needs within travel guidance and provide more tailored and useful information compared to relying solely on generic web search results 8.
To further elevate the sophistication of our travel guide agent, we can aim to create an agent capable of generating a basic one-day travel itinerary for a given city, taking into account user preferences. This requires the agent to not only access information but also to perform a sequence of actions based on that information, demonstrating a basic form of multi-step reasoning 1.
We can introduce a new custom tool to facilitate this:
Python from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool Assuming getweather and gettravel_duration tools are defined as in Level 2 @tool def search_attractions(city: str, interests: str) -> str: """ Searches for popular attractions in a given city based on user interests. Args: city: The city to search for attractions in. interests: Keywords describing the user’s interests (e.g., museums, parks, historical sites). Returns: A string containing a list of relevant attractions. """ # Implementation using DuckDuckGoSearchTool or a dedicated API search_query = f"top {interests} in {city}" searchresults = DuckDuckGoSearchTool().run(searchquery) return search_results model = HfApiModel() tools = agent = CodeAgent(tools=tools, model=model) user_prompt = "Plan a one-day sightseeing trip in London for someone interested in historical sites. Start at 9 AM." response = agent.run(user_prompt) print(response)
In this more advanced setup, we define an additional custom tool called searchattractions. This tool takes the name of a city and a description of the user’s interests as input. It then performs a search (potentially using the DuckDuckGoSearchTool internally or by interacting with a dedicated Points of Interest API) to find relevant attractions in the specified city that align with the user’s interests. The agent now has a collection of tools that allows it to search for general information, check the weather, estimate travel times, and find specific attractions based on user preferences. When the agent receives a user prompt like "Plan a one-day sightseeing trip in London for someone interested in historical sites. Start at 9 AM," it needs to execute a series of steps. First, it identifies the key pieces of information from the prompt: the city (London) and the interests (historical sites). Then, it can use the searchattractions tool to get a list of relevant places to visit. For a selection of these top attractions, it might utilize the gettravelduration tool to estimate the travel time between them. Additionally, it could use the getweather tool to consider the weather conditions for the day of the planned trip. Based on the information gathered from these tools, the agent can then proceed to generate a basic itinerary. This itinerary would involve suggesting an order in which to visit the attractions, along with estimated timings for each visit, taking into account the specified starting time of 9 AM 3. Constructing such an itinerary requires the agent to orchestrate the use of multiple tools and perform a basic level of reasoning to create a logical sequence of actions, representing a significant increase in complexity compared to the previous levels.
Beyond the basic and enhanced travel guide agents, Smolagents offers several advanced features and possibilities for future development. One such feature is the ToolCallingAgent, which functions similarly to the CodeAgent but instead of writing and executing Python code, it outputs its actions in the form of JSON-like blobs. This type of agent might be preferable in scenarios where executing arbitrary code is restricted for security reasons or when the agent needs to interact with other systems that expect structured JSON input for tool calls.
For more intricate travel guide applications, effectively managing the agent’s memory becomes crucial. Agents inherently maintain a history of their interactions 23. For applications aiming to provide personalized recommendations or handle complex, multi-turn conversations, the ability to manage this memory—for instance, by summarizing past interactions or storing user preferences—is essential 8. Smolagents provides tools to inspect and even dynamically modify the agent’s memory, allowing for more sophisticated control over the agent’s behavior based on past experiences 25.
Given that the CodeAgent in Smolagents has the capability to execute Python code, security considerations are paramount, especially in applications that might handle user-provided inputs or data from external sources. To address this, Smolagents offers options for secure code execution through the use of sandboxed environments like E2B or Docker 8. These environments create an isolated space for the code to run, preventing any potential harm to the local system. This is a critical feature for ensuring the safety and reliability of travel agent applications that leverage the power of code execution.
Looking towards future enhancements, integrating Smolagents with specialized external travel APIs would significantly expand the capabilities of a travel guide agent. Access to real-time data such as flight schedules, hotel availability, and transportation updates would allow the agent to provide much more comprehensive and up-to-date travel planning assistance 3. This would involve creating custom tools specifically designed to interact with these APIs.
Finally, for highly complex travel planning tasks, a multi-agent system could be employed. In such a system, multiple specialized agents could work collaboratively to create a comprehensive travel plan 8. For example, one agent could focus on finding the best flight options, another on securing accommodation, and a third on suggesting activities at the destination. Smolagents supports the creation of multi-agent systems through the ManagedAgent class, allowing for the orchestration of different agents to achieve a common goal 4.
This tutorial has demonstrated the potential of Hugging Face’s Smolagents library for building intelligent travel guide agents with increasing levels of complexity. Starting with a basic agent capable of answering simple questions using web search, we progressed to an enhanced agent with custom tools for weather information and travel time estimation, and finally to a more advanced agent capable of generating a basic one-day travel itinerary. Smolagents’ emphasis on simplicity, its support for Code Agents, and its seamless integration with the Hugging Face ecosystem make it a powerful yet accessible framework for developing sophisticated AI-powered travel assistance tools. For those interested in further exploring the capabilities of Smolagents and the broader field of AI agents, resources such as the official Smolagents documentation, the library’s GitHub repository, and community forums offer valuable avenues for continued learning and experimentation 1.
1. Hugging Face’s Smolagents: A Guide With Examples - DataCamp, accessed March 20, 2025, https://www.datacamp.com/tutorial/smolagents
2. Hugging Face Smolagents is a Simple Library to Build LLM-Powered Agents - InfoQ, accessed March 20, 2025, https://www.infoq.com/news/2025/01/hugging-face-smolagents-agents/
3. blog/smolagents.md at main · huggingface/blog - GitHub, accessed March 20, 2025, https://github.com/huggingface/blog/blob/main/smolagents.md
4. SmolAgents by Hugging Face: Enhancing Human Workflows in 2025 - Medium, accessed March 20, 2025, https://medium.com/@nandinilreddy/huggingface-smol-agents-ee8ef83ea9eb
5. Building Custom Tools for AI Agents Using smolagents - Analytics Vidhya, accessed March 20, 2025, https://www.analyticsvidhya.com/blog/2025/03/custom-tools-for-ai-agents/
6. smolagents: Build your own Agents with Hugging Face Now!!! - Kaggle, accessed March 20, 2025, https://www.kaggle.com/discussions/general/555122
7. Introducing smolagents: simple agents that write actions in code. - Hugging Face, accessed March 20, 2025, https://huggingface.co/blog/smolagents
8. Exploring SmolAgents: Building Intelligent Agents with Hugging Face - Medium, accessed March 20, 2025, https://medium.com/@danushidk507/exploring-smolagents-building-intelligent-agents-with-hugging-face-983969ec99a9
9. smolagents - Hugging Face, accessed March 20, 2025, https://huggingface.co/docs/smolagents/index
10. Smolagents : Huggingface AI Agent Framework, accessed March 20, 2025, https://smolagents.org/
11. smolagents: a barebones library for agents. Agents write python code to call tools and orchestrate other agents. - GitHub, accessed March 20, 2025, https://github.com/huggingface/smolagents
12. smolagents/README.md at main - GitHub, accessed March 20, 2025, https://github.com/huggingface/smolagents/blob/main/README.md
13. Let’s Create Our First Agent Using smolagents - Hugging Face Agents Course, accessed March 20, 2025, https://huggingface.co/learn/agents-course/unit1/tutorial
14. Exploring the smolagents Library: A Deep Dive into MultiStepAgent, CodeAgent, and ToolCallingAgent | by Isaac Kargar | Feb, 2025, accessed March 20, 2025, https://kargarisaac.medium.com/exploring-the-smolagents-library-a-deep-dive-into-multistepagent-codeagent-and-toolcallingagent-03482a6ea18c
15. Introduction to Agents - Hugging Face, accessed March 20, 2025, https://huggingface.co/docs/smolagents/conceptualguides/introagents
16. SmolAgents by Hugging Face: Build AI Agents in Less than 30 Lines - Analytics Vidhya, accessed March 20, 2025, https://www.analyticsvidhya.com/blog/2025/01/smolagents/
17. SmolAgents from HuggingFace - Cobus Greyling - Medium, accessed March 20, 2025, https://cobusgreyling.medium.com/smolagents-7a4bf7712814
18. How to Build Agentic RAG With SmolAgents? - Analytics Vidhya, accessed March 20, 2025, https://www.analyticsvidhya.com/blog/2025/01/agentic-rag-with-smolagents/
19. Orchestrate a multi-agent system - Hugging Face, accessed March 20, 2025, https://huggingface.co/docs/smolagents/examples/multiagents
20. Harnessing HuggingFace’s SmolAgent for Smart Web Automation | by Sumit Soman, accessed March 20, 2025, https://medium.com/@sumit.somanchd/harnessing-huggingfaces-smolagent-for-smart-web-automation-e53e5204cd4f
21. Choosing the right agentic AI framework: SmolAgents, PydanticAI, and LlamaIndex AgentWorkflows - QED42, accessed March 20, 2025, https://www.qed42.com/insights/choosing-the-right-agentic-ai-framework-smolagents-pydanticai-and-llamaindex-agentworkflows
22. Unpacking SmolAgents: A Beginner-Friendly Guide to Agentic Systems - Cohorte Projects, accessed March 20, 2025, https://www.cohorte.co/blog/unpacking-smolagents-a-beginner-friendly-guide-to-agentic-systems
23. [Feature] Agent memory/history consolidation after a number of interactions #901 - GitHub, accessed March 20, 2025, https://github.com/huggingface/smolagents/issues/901
24. Building good agents - Hugging Face, accessed March 20, 2025, https://huggingface.co/docs/smolagents/tutorials/buildinggoodagents
25. Manage your agent’s memory - Hugging Face, accessed March 20, 2025, https://huggingface.co/docs/smolagents/main/en/tutorials/memory
26. AI This Week: Hugging Face’s Smolagents Unveiled and What to Expect at CES 2025, accessed March 20, 2025, https://trewknowledge.com/2025/01/03/ai-this-week-exploring-hugging-faces-smolagents-and-anticipating-ces-2025-innovations/
27. Building Powerful AI Agents with Hugging Face’s smolagents | by Pruthviraj Chavan, accessed March 20, 2025, https://medium.com/@pruthviraj0430/building-powerful-ai-agents-with-hugging-faces-smolagents-65f7d3f229cb
28. smolagents/docs/source/en/examples/multiagents.mdx at main - GitHub, accessed March 20, 2025, https://github.com/huggingface/smolagents/blob/main/docs/source/en/examples/multiagents.mdx
Imagine reducing your operational costs by up to $100,000 annually without compromising on the technology you rely on. Through our partnerships with leading cloud and technology providers like AWS (Amazon Web Services), Google Cloud Platform (GCP), Microsoft Azure, and Nvidia Inception, we can help you secure up to $25,000 in credits over two years (subject to approval).
These credits can cover essential server fees and offer additional perks, such as:
By leveraging these credits, you can significantly optimize your operational expenses. Whether you're a startup or a growing business, the savings from these partnerships ranging from $5,000 to $100,000 annually can make a huge difference in scaling your business efficiently.
The approval process requires company registration and meeting specific requirements, but we provide full support to guide you through every step. Start saving on your cloud infrastructure today and unlock the full potential of your business.