Skip to content

[tiny-agents] Handle env variables in tiny-agents (Python client) #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented May 28, 2025

This PR adds support for the inputs configuration defined by VSCode (see docs).

We do not support all the VSCode feature but follow their convention. In practice:

  • input.id and input.description must be set => used to prompt user
  • intput.type / input.password => not used
  • user are prompted for the required values. If user leaves blank, we load the value from the user's environment variable by default (they are warned about it).

image

Example

Here is an example (library-pr-reviewer/agent.json):

{
  "model": "Qwen/Qwen2.5-72B-Instruct",
  "provider": "nebius",
  "inputs": [
    {
      "type": "promptString",
      "id": "github-read-pat",
      "description": "Github Personal Access Token (read-only)",
      "password": true
    }
  ],
  "servers": [
    {
      "type": "stdio",
      "config": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "-e",
          "GITHUB_PERSONAL_ACCESS_TOKEN",
          "-e",
          "GITHUB_TOOLSETS=repos,issues,pull_requests",
          "ghcr.io/github/github-mcp-server"
        ],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github-read-pat}"
        }
      }
    },
    {
      "type": "stdio",
      "config": {
        "command": "npx",
        "args": [
          "@playwright/mcp@latest"
        ]
      }
    }
  ]
}
➜  tiny-agents run wauplin/library-pr-reviewer
Some initial inputs are required by the agent. Please provide a value or leave empty to load 
from env.
 • github-read-pat: Github Personal Access Token (read-only). (default: load from 
GITHUB_PERSONAL_ACCESS_TOKEN). »  
Value successfully loaded from 'GITHUB_PERSONAL_ACCESS_TOKEN'

GitHub MCP Server running on stdio
Agent loaded with 65 tools:
 • add_issue_comment
 • add_pull_request_review_comment_to_pending_review
 (...)

@Wauplin Wauplin requested review from hanouticelina and Copilot May 28, 2025 14:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds an interactive prompt to forward local environment variables when agent.json sets them to null.

  • Introduces logic in the CLI to detect null env vars, prompt the user, and inject local values on consent
  • Imports os to access the host environment
  • Changes two break statements to return for early exit when exit_event is set
Comments suppressed due to low confidence (3)

src/huggingface_hub/inference/_mcp/cli.py:72

  • Consider adding tests for both user consent and denial paths when forwarding environment variables, to ensure this interactive flow behaves as expected.
# Handle env variable injection if required

src/huggingface_hub/inference/_mcp/cli.py:133

  • Replacing break with return will exit the entire function instead of just the loop. Confirm this early return won’t skip necessary cleanup or downstream logic.
return

src/huggingface_hub/inference/_mcp/cli.py:153

  • This return mirrors the change above in a nested loop; ensure that prematurely exiting here doesn’t interfere with any remaining streaming or cleanup steps.
return

@HuggingFaceDocBuilderDev

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.

@Wauplin Wauplin requested review from evalstate and Copilot May 28, 2025 15:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for forwarding user-provided or environment‐derived inputs into the agent’s server configurations.

  • Introduces an inputs processing step before the main agent loop, prompting the user and injecting values into server envs.
  • Adjusts loop exit behavior by replacing inner break calls with return.
Comments suppressed due to low confidence (1)

src/huggingface_hub/inference/_mcp/cli.py:74

  • There are no tests covering the new inputs prompting and env-injection logic; consider adding unit tests or integration tests to verify the user prompt flow and environment variable fallback behavior.
if len(inputs) > 0:

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks for adding this

@Wauplin Wauplin changed the title [tiny-agents] forward local env variables [tiny-agents] Handle env variables in tiny-agents (Python client) May 28, 2025
@Wauplin
Copy link
Contributor Author

Wauplin commented May 28, 2025

Thanks! Merging it now :) (still possible to iterate later)

@Wauplin Wauplin merged commit 2aafd15 into main May 28, 2025
26 checks passed
@Wauplin Wauplin deleted the forward-env-variables branch May 28, 2025 17:09
hanouticelina pushed a commit that referenced this pull request May 30, 2025
)

* [tiny-agents] forward local env variables

* Approximately follow VSCode convention

* Update src/huggingface_hub/inference/_mcp/cli.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
key
for server in servers
for key, value in server.get("config", {}).get("env", {}).items()
if value == env_special_value
Copy link
Member

Choose a reason for hiding this comment

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

potentially, you should also check config.headers: for HTTP or SSE servers it's expected most keys will end up in headers.

see related doc PR from me here: microsoft/vscode-docs#8437

Copy link
Member

Choose a reason for hiding this comment

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

(but not prio at all)

Copy link
Member

Choose a reason for hiding this comment

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

i've pushed something on your JS PR actually:
huggingface/huggingface.js@d154e3e

(see the comments there..)

Wauplin added a commit to huggingface/huggingface.js that referenced this pull request Jun 3, 2025
This PR adds support for the inputs configuration defined by VSCode (see
[docs](https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server-to-your-workspace)).

PR adapted from huggingface/huggingface_hub#3129
using Cursor. Made some minor adjustments manually.

### How to test

```
pnpm run cli run wauplin/library-pr-reviewer
```


![image](https://github.com/user-attachments/assets/f58be215-2575-4593-9ff2-5f85a6950649)

---------

Co-authored-by: Julien Chaumond <julien@huggingface.co>
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.

4 participants