Skip to content

fix: support Google Colab secrets for HF_TOKEN loading#678

Merged
sergiopaniego merged 2 commits into
huggingface:mainfrom
octo-patch:fix/issue-612-colab-token-loading
Apr 27, 2026
Merged

fix: support Google Colab secrets for HF_TOKEN loading#678
sergiopaniego merged 2 commits into
huggingface:mainfrom
octo-patch:fix/issue-612-colab-token-loading

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #612

Problem

The Dummy Agent Library notebook code uses os.environ.get("HF_TOKEN") to read the token, which silently returns None in Google Colab. In Colab, secrets are stored in a separate keystore and must be accessed via google.colab.userdata.get(), not os.environ. This causes subsequent API calls to fail — but since the token assignment doesn't raise an error, users have no way to know what went wrong.

Solution

Updated the token-loading snippet in dummy-agent-library.mdx to:

  1. Try google.colab.userdata.get('HF_TOKEN') first (Colab environment)
  2. Fall back to os.environ.get("HF_TOKEN") in all other environments (local, Jupyter, etc.)
  3. Explicitly pass token=HF_TOKEN to InferenceClient so the token is actually used

Testing

Documentation-only change to the code snippet shown in the course page. Logic is straightforward environment detection with a graceful fallback.

Comment thread units/en/unit1/dummy-agent-library.mdx Outdated
@pcuenca pcuenca requested a review from sergiopaniego April 23, 2026 07:32
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown
Collaborator

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Copy Markdown
Member

@sergiopaniego sergiopaniego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the code parts of the course, we use https://huggingface.co/agents-course/notebooks/ as source. I've pushed the changes there

@sergiopaniego
Copy link
Copy Markdown
Member

Thanks!!

@sergiopaniego sergiopaniego merged commit de076ef into huggingface:main Apr 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HANDS-ON BUG] Dummy Agent Library Notebook code does not work

4 participants