GitHub - huggingface/ml-intern: ๐ค ml-intern: an open-source ML engineer that reads papers, trains models, and ships ML models
Key Points
- 1ML Intern is an autonomous agent developed to research, write, and deploy machine learning code, leveraging deep access to the Hugging Face ecosystem's docs, papers, datasets, and cloud compute.
- 2It operates via an agentic loop, utilizing a ToolRouter for accessing diverse resources like HF repos and sandbox environments, and includes a Doom Loop Detector to manage iterative processes effectively.
- 3The agent supports flexible usage through CLI, accommodating various LLM models (local and cloud-based), and automatically uploads session traces to private Hugging Face datasets for review and sharing.
The ML Intern project is an autonomous machine learning (ML) agent designed to research, write, and ship high-quality ML-related code by leveraging the Hugging Face (HF) ecosystem, including deep access to documentation, papers, datasets, and cloud compute.
Its core methodology revolves around an iterative agentic loop, orchestrated by a central submission_loop process. This loop receives operations (e.g., user input) and routes them to handlers like run_agent(). The run_agent() function initiates the Agentic Loop, which operates for a maximum of 300 iterations, aiming to achieve the user's objective.
Within this Agentic Loop, the agent follows a structured process:
- LLM Call: It calls an LLM (via
litellm.acompletion()) with the current context, which includes message history and tool specifications. - Tool Call Parsing: The LLM's response is parsed for any
tool_calls[]. If no tool calls are suggested, the loop concludes. - Approval Check: Before executing sensitive operations (e.g., jobs, sandbox creation, destructive filesystem actions), the agent performs an approval check, potentially requiring user confirmation.
- Tool Execution: For each approved tool call, the
ToolRouterexecutes the specified tool. TheToolRouterserves as a gateway to various functionalities, including searching HF documentation and research papers, interacting with HF repositories, datasets, jobs, and papers, performing GitHub code searches, and utilizing local or HF Space sandbox tools. It also integrates planning capabilities and MCP server tools. - Context Update: The results of tool execution are added back into the
ContextManager.
The ContextManager is a critical component that maintains the agent's state. It manages the message history as a list of litellm.Message objects, employs auto-compaction mechanisms to prevent context window overflow (triggered around 170k tokens), and facilitates the upload of session traces to a private Hugging Face dataset for debugging and review.
A Doom Loop Detector is integrated into the agentic loop to identify and prevent repetitive or unproductive tool patterns. Upon detection, it injects corrective prompts into the LLM's context to guide the agent towards a more effective path.
For tool execution, the ML Intern offers two runtime environments:
- Local Runtime: By default, the CLI allows the agent to execute
bashcommands and performread,write, andeditoperations directly on the local filesystem where it is run. - Sandbox Runtime: Opting for
--sandbox-toolsallows the agent to create or utilize HF Space sandboxes, providing remote GPU-acceleraccelerated environments for testing code or larger compute tasks. This mode requires anHF_TOKEN.
Session traces are automatically uploaded to a user's private Hugging Face dataset (defaulting to {your-hf-username}/ml-intern-sessions) in Claude Code JSONL format, which can be viewed via the HF Agent Trace Viewer. Users can control the visibility of these datasets or opt out of trace sharing.
The agent supports various LLMs, configurable via command-line options, including models from Anthropic, OpenAI, and local models (Ollama, vLLM, LM Studio, Llama.cpp) through OpenAI-compatible HTTP endpoints managed by LiteLLM. It also features one-way notification gateways, such as Slack integration, to send out-of-band status updates for events like approval_required, error, and turn_complete.
Developers can extend the agent's capabilities by adding new built-in tools within agent/core/tools.py or by configuring additional MCP (Multi-platform Control Plane) servers in the agent's configuration files.