Public
Star ๅๅฒ่ถๅฟ
ๆฐๆฎๆฅๆบ: GitHub API ยท ็ๆ่ช Stargazers.cn
README.md
ML Intern
An ML intern that autonomously researches, writes, and ships good quality ML releated code using the Hugging Face ecosystem โ with deep access to docs, papers, datasets, and cloud compute.
Quick Start
Installation
git clone git@github.com:huggingface/ml-intern.git cd ml-intern uv sync uv tool install -e .
That's it. Now ml-intern works from any directory:
ml-intern
Create a .env file in the project root (or export these in your shell):
ANTHROPIC_API_KEY=<your-anthropic-api-key> # if using anthropic models HF_TOKEN=<your-hugging-face-token> GITHUB_TOKEN=<github-personal-access-token>
If no HF_TOKEN is set, the CLI will prompt you to paste one on first launch. To get a GITHUB_TOKEN follow the tutorial here.
Usage
Interactive mode (start a chat session):
ml-intern
Headless mode (single prompt, auto-approve):
ml-intern "fine-tune llama on my dataset"
Options:
ml-intern --model anthropic/claude-opus-4-6 "your prompt" ml-intern --max-iterations 100 "your prompt" ml-intern --no-stream "your prompt"
Architecture
Component Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ User/CLI โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโ
โ Operations โ Events
โ (user_input, exec_approval, โ
submission_queue interrupt, compact, ...) event_queue
โ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ submission_loop (agent_loop.py) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ 1. Receive Operation from queue โ โ โ
โ โ 2. Route to handler (run_agent/compact/...) โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ Handlers.run_agent() โ โโโโค
โ โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โ โ Agentic Loop (max 300 iterations) โ โ โ โ
โ โ โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ โ Session โ โ โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ
โ โ โ โ โ ContextManager โ โ โ โ โ โ
โ โ โ โ โ โข Message history โ โ โ โ โ โ
โ โ โ โ โ (litellm.Message[]) โ โ โ โ โ โ
โ โ โ โ โ โข Auto-compaction (170k) โ โ โ โ โ โ
โ โ โ โ โ โข Session upload to HF โ โ โ โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ
โ โ โ โ โ โ โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ
โ โ โ โ โ ToolRouter โ โ โ โ โ โ
โ โ โ โ โ โโ HF docs & research โ โ โ โ โ โ
โ โ โ โ โ โโ HF repos, datasets, โ โ โ โ โ โ
โ โ โ โ โ โ jobs, papers โ โ โ โ โ โ
โ โ โ โ โ โโ GitHub code search โ โ โ โ โ โ
โ โ โ โ โ โโ Sandbox & local tools โ โ โ โ โ โ
โ โ โ โ โ โโ Planning โ โ โ โ โ โ
โ โ โ โ โ โโ MCP server tools โ โ โ โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ โ Doom Loop Detector โ โ โ โ โ
โ โ โ โ โข Detects repeated tool patterns โ โ โ โ โ
โ โ โ โ โข Injects corrective prompts โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ โ โ โ โ
โ โ โ Loop: โ โ โ โ
โ โ โ 1. LLM call (litellm.acompletion) โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ 2. Parse tool_calls[] โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ 3. Approval check โ โ โ โ
โ โ โ (jobs, sandbox, destructive ops) โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ 4. Execute via ToolRouter โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ 5. Add results to ContextManager โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ 6. Repeat if tool_calls exist โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโ
Agentic Loop Flow
User Message
โ
[Add to ContextManager]
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Iteration Loop (max 300) โ
โ โ
โ Get messages + tool specs โ
โ โ โ
โ litellm.acompletion() โ
โ โ โ
โ Has tool_calls? โโNoโโ> Done โ
โ โ โ
โ Yes โ
โ โ โ
โ Add assistant msg (with tool_calls) โ
โ โ โ
โ Doom loop check โ
โ โ โ
โ For each tool_call: โ
โ โข Needs approval? โโYesโโ> Wait for โ
โ โ user confirm โ
โ No โ
โ โ โ
โ โข ToolRouter.execute_tool() โ
โ โข Add result to ContextManager โ
โ โ โ
โ Continue loop โโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Events
The agent emits the following events via event_queue:
processing- Starting to process user inputready- Agent is ready for inputassistant_chunk- Streaming token chunkassistant_message- Complete LLM response textassistant_stream_end- Token stream finishedtool_call- Tool being called with argumentstool_output- Tool execution resulttool_log- Informational tool log messagetool_state_change- Tool execution state transitionapproval_required- Requesting user approval for sensitive operationsturn_complete- Agent finished processingerror- Error occurred during processinginterrupted- Agent was interruptedcompacted- Context was compactedundo_complete- Undo operation completedshutdown- Agent shutting down
Development
Adding Built-in Tools
Edit agent/core/tools.py:
def create_builtin_tools() -> list[ToolSpec]: return [ ToolSpec( name="your_tool", description="What your tool does", parameters={ "type": "object", "properties": { "param": {"type": "string", "description": "Parameter description"} }, "required": ["param"] }, handler=your_async_handler ), # ... existing tools ]
Adding MCP Servers
Edit configs/main_agent_config.json:
{ "model_name": "anthropic/claude-sonnet-4-5-20250929", "mcpServers": { "your-server-name": { "transport": "http", "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer ${YOUR_TOKEN}" } } } }
Note: Environment variables like ${YOUR_TOKEN} are auto-substituted from .env.
ๅ ณไบ About
๐ค ml-intern: an open-source ML engineer that reads papers, trains models, and ships ML models
่ฏญ่จ Languages
Python70.2%
TypeScript29.5%
Dockerfile0.1%
HTML0.1%
JavaScript0.1%
Shell0.1%
ๆไบคๆดป่ทๅบฆ Commit Activity
ไปฃ็ ๆไบค็ญๅๅพ
่ฟๅป 52 ๅจ็ๅผๅๆดป่ทๅบฆ370
Total Commitsๅณฐๅผ: 66ๆฌก/ๅจ
LessMore