How to run smolagents agent.push_to_hub and agent.from_hub locally on vscode?

i am taking smolagents course
the materials provided run in google colab notebook…
though, i want to try to run the materials locally as well using vscode…

i want to ask, how to run the following locally on vscode?
a) agent.from_hub(‘sergiopaniego/AlfredAgent’, trust_remote_code=True)"
b) agent.push_to_hub(‘AScythe/AlfredAgent’)

1 Like

If you have installed Python 3.10 or later and run the following command, it should work normally.

For example, if you want to use TransformersModel, you will need to install PyTorch and Transformers in advance, but if you just want to use smolagents, I think it should work with just the libraries below…probably.

pip install huggingface_hub smolagents
1 Like

thanks for the response
A) for agent.push_to_hub…
i have several cases that i tried, first one is by running:

  1. i run agent.push_to_hub(‘AScythe/AlfredAgent’), and got this error:
    Traceback (most recent call last):
    File “E:\Code\AI_Agents\smol_agents1.py”, line 164, in
    agent.push_to_hub(“AScythe/display_image_tool”, token=huggingface_api_key)
    ^^^^^^^^^^^^^^^^^
    AttributeError: ‘CodeAgent’ object has no attribute ‘push_to_hub’

  2. i tried to push a single tool by running:
    class SuperheroPartyThemeTool(Tool):
    name = “superhero_party_theme_generator”
    description = “”"
    This tool suggests creative superhero-themed party ideas based on a category.
    It returns a unique party theme idea.“”"

    inputs = {
    “category”: {
    “type”: “string”,
    “description”: “The type of superhero party (e.g., ‘classic heroes’, ‘villain masquerade’, ‘futuristic Gotham’).”,
    }
    }

    output_type = “string”

    def forward(self, category: str):
    themes = {
    “classic heroes”: “Justice League Gala: Guests come dressed as their favorite DC heroes with themed cocktails like ‘The Kryptonite Punch’.”,
    “villain masquerade”: “Gotham Rogues’ Ball: A mysterious masquerade where guests dress as classic Batman villains.”,
    “futuristic Gotham”: “Neo-Gotham Night: A cyberpunk-style party inspired by Batman Beyond, with neon decorations and futuristic gadgets.”
    }

     return themes.get(category.lower(), "Themed party idea not found. Try 'classic heroes', 'villain masquerade', or 'futuristic Gotham'.")
    

party_theme_tool = SuperheroPartyThemeTool()

party_theme_tool.push_to_hub(“AScythe/display_image_tool”, token=huggingface_api_key)
and i got this error:
UnicodeEncodeError: ‘charmap’ codec can’t encode character ‘\U0001f440’ in position 39: character maps to

whatever i do, it seems like i cant push agents/tools to hub in vs code… may i kindly ask if you have sample code that you can run in your vscode?

1 Like

It seems that the library or Python itself is acting strangely…

If restarting VSCode doesn’t fix the problem, it seems like you should suspect the Python environment in VSCode itself.
https://www.datacamp.com/tutorial/setting-up-vscode-python