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], [api_key])

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 identifier or endpoint URL to use for inference. See the SmolAgents InferenceClientModel documentation for valid values and usage.https://api.mistral.ai/v1/chat/completions
api_keystringNoThe API key for the LLM provider. Get a free API key from Mistral AI.Microsoft login token used for demo if not provided.

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.

Demo

If either api_key or model_id is not provided, both will default to Boardflare demo values (model_id: https://llm.boardflare.com, api_key: your Microsoft login token if available). This only works for users logged in with a Microsoft account and provides limited free demo usage. You may obtain a free api_key for Mistral AI with your Microsoft account which offers more generous free usage and supports CORS.

Limitations

  • If you have another function in your workbook that has used Requests before you run this function, you may encounter the following error: ValueError: Requested 'requests>=2.32.3', but requests==2.31.0 is already installed. Close and reopen Excel, and only use this function in that workbook. We are working on a fix for this.
  • 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 as it only uses the hello tool.
  • The function requires an internet connection to access the AI model.
  • Model availability and output may vary depending on the provider or API changes.

Examples

Personalized Greeting (Mistral AI)

Request a greeting for a client named Mike using Mistral AI:

=SMOLAGENTS_HELLO("Get a greeting for Mike", "https://api.mistral.ai/v1/chat/completions", "your_mistral_api_key")

Demo Mode (Boardflare)

If you do not provide an API key, the function will attempt to use the Boardflare demo endpoint (rate-limited):

=SMOLAGENTS_HELLO("Get a greeting for Bob")

Source Code

from smolagents import CodeAgent, InferenceClientModel, tool def smolagents_hello(prompt, model_id = "https://api.mistral.ai/v1/chat/completions", api_key = None): """ 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 Mistral AI endpoint ('https://api.mistral.ai/v1/chat/completions'). api_key (str, optional): The API key for the LLM provider. [Get a free API key from Mistral AI](https://console.mistral.ai/). 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." # Set api_key to idToken from globals() if not provided, for demo login compatibility if api_key is None and "idToken" in globals(): api_key = globals()["idToken"] model_id = "https://llm.boardflare.com" # See https://huggingface.co/docs/smolagents/main/en/reference/models#smolagents.InferenceClientModel for instructions on how to set up your own model. model = InferenceClientModel( model_id=model_id, api_key=api_key ) # 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