Integrations/smolagents
AI Agent

Create spreadsheets & documents with smolagents

In Hugging Face smolagents, decorate a function with @tool and your code agent can create shareable spreadsheets as part of its reasoning. The agent writes and runs code that calls your tool, then returns the link.

smolagents (Python)
import requests
from smolagents import tool, CodeAgent, InferenceClientModel

@tool
def create_spreadsheet(title: str, rows: list) -> str:
    """Create a shareable spreadsheet. First row is the header. Returns a URL.

    Args:
        title: The spreadsheet title.
        rows: A list of rows, each a list of cell values.
    """
    r = requests.post("https://openofficeai.com/api/v1/sheets",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={"title": title, "sheets": [{"rows": rows}]})
    return r.json()["url"]

agent = CodeAgent(tools=[create_spreadsheet], model=InferenceClientModel())

How to create a spreadsheet with smolagents

  1. 1Decorate a function with @tool and document its args (smolagents requires arg docs).
  2. 2POST to /api/v1/sheets inside the tool and return the url.
  3. 3Pass the tool to a CodeAgent or ToolCallingAgent.
  4. 4Run the agent; it calls the tool and returns the link.

Why use OpenOfficeAI with smolagents

Frequently asked questions

Why does smolagents need argument docstrings?

smolagents parses the Args section of your docstring to describe each parameter to the model. Document title and rows clearly so the agent supplies well-formed data.

CodeAgent or ToolCallingAgent?

CodeAgent writes Python to orchestrate tools (flexible); ToolCallingAgent uses structured tool calls. Both work — pick CodeAgent if you want the agent to combine the tool with other logic.

Can it create documents?

Yes. Add another @tool that posts to /api/v1/docs with a content array, and the agent can generate written documents too.

Start creating documents with smolagents

Free tier includes 500 API calls per month — no card required.

Related integrations