Skip to Content

SMOLAGENTS_HELLO

Overview

This function uses the SmolAgents library to run a simple code agent that can generate personalized greetings or respond to instructions using an LLM model. It is designed for use in Excel, allowing users to interact with AI agents directly from their spreadsheets.

Usage

To use the SMOLAGENTS_HELLO function in Excel, enter it as a formula in a cell, specifying your prompt and any optional arguments as needed:

=SMOLAGENTS_HELLO(prompt, [model_id], [token])

Replace each parameter with your desired value. The function returns a text response generated by the agent.

Parameters

ParameterTypeRequiredDescriptionDefault
promptstringYesThe instruction or request for the agent (e.g., “Get a greeting for Mike”).
model_idstringNoThe model endpoint URL to use (e.g., ‘https://llm.boardflare.com’).https://llm.boardflare.com
tokenstringNoThe API token for the LLM provider.cV4a59t1wjYGs…

Return Value

Return ValueTypeDescription
ResponsestringThe text response generated by the agent, or an error message if something fails.

Tools

The agent is configured with a single embedded tool: the hello function. This function takes a name as input and returns a personalized greeting. All agent responses are generated by invoking this hello tool, so the agent’s capabilities are limited to greeting tasks.

Limitations

  • The function requires the SmolAgents package and an internet connection.
  • Model availability and output may vary depending on the provider or API changes.
  • Only string prompts are accepted; invalid or empty prompts return an error message.
  • The function is limited to simple greeting tasks in its current form.
  • Sensitive or confidential data should not be sent to external AI services.

Benefits

Can this be done natively in Excel? Excel does not natively support AI-powered agents or natural language generation. Manual greeting generation or text analysis is time-consuming and lacks automation.

Why use this Python function?

  • Automates personalized greetings and simple agent tasks in Excel.
  • Saves time and improves consistency in communication.
  • Demonstrates integration of LLM-powered agents with Excel workflows.

Examples

Personalized Greeting

Request a greeting for a client named Mike:

=SMOLAGENTS_HELLO("Get a greeting for Mike")

Custom Model and Token

Use a custom model endpoint and token:

=SMOLAGENTS_HELLO("Get a greeting for Alice", "https://your-model-endpoint.com", "your_api_token")

Source Code

from smolagents import CodeAgent, InferenceClientModel, tool def smolagents_hello(prompt, model_id = "https://llm.boardflare.com", token = "cV4a59t1wjYGs...."): """ Uses a code agent from smolagents to run a simple tool (hello) using an LLM model. Args: prompt (str): The instruction or request for the agent (e.g., "Get a greeting for Mike") that uses the hello tool. model_id (str, optional): The model_id to use. Defaults to 'https://llm.boardflare.com' to make this work in a demo, but this is heavily rate-limited, an not for production use. token (str, optional): The API token for the LLM provider. Returns: str: The agent's response as a string, or an error message if something fails. """ if not isinstance(prompt, str) or not prompt.strip(): return "Invalid prompt. Please provide a non-empty string." # See https://huggingface.co/docs/smolagents/main/en/reference/models#smolagents.InferenceClientModel for instuctions on how to set up your own model. model = InferenceClientModel( model_id=model_id, token=token ) # Define a simple tool that returns a greeting @tool def hello(name: str) -> str: """ Returns a greeting. Args: name: The name of the person that you want a greeting for. """ return f"Hello {name}!" try: agent = CodeAgent(tools=[hello], model=model, add_base_tools=False) result = agent.run(prompt) if isinstance(result, str): return result return str(result) except Exception as e: return f"Agent error: {e}"
Last updated on