Skip to content

Commit 2d80b2c

Browse files
mjnitz02akshoop
andauthored
[BUZZOK-25627][BUZZOK-25637] Add Python 3.11 Generative AI Agents drop in environment (#1403)
* Python 3.11 Generative AI Agents Environment * Update logic * Tweaksg * Update * Black * Update ids * Add drop in test * Update test * Remove call * Update environment with streamlines * Update readme * Remove tests * Update codeowners * Update codeowners * Apply suggestions from code review Co-authored-by: Alex Shoop <[email protected]> * Add run_agent.py * Lint * Add pylint skip --------- Co-authored-by: Alex Shoop <[email protected]>
1 parent b64c1a7 commit 2d80b2c

24 files changed

+1394
-3
lines changed

DRCODEOWNERS

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
/model_templates/triton_onnx_unstructured @datarobot/tracking-agent @datarobot/custom-models
3434
/public_dropin_environments/java_codegen @datarobot/custom-models
3535
/public_dropin_environments/python311_genai @datarobot/buzok @datarobot/codegen
36-
/public_dropin_environments/python312_apps @datarobot/custom-models @datarobot/applications
37-
/public_dropin_environments/python39_streamlit @datarobot/custom-models @datarobot/applications
36+
/public_dropin_environments/python311_genai_agents @datarobot/buzok @datarobot/codegen
3837
/public_dropin_environments/python3_keras @datarobot/custom-models @datarobot/core-modeling
3938
/public_dropin_environments/python3_onnx @datarobot/custom-models
4039
/public_dropin_environments/python3_pmml @datarobot/custom-models @datarobot/core-modeling
@@ -44,7 +43,6 @@
4443
/public_dropin_environments/r_lang @datarobot/custom-models @datarobot/core-modeling
4544
/public_dropin_environments_sandbox @datarobot/custom-models
4645
/public_dropin_gpu_environments @datarobot/tracking-agent @datarobot/custom-models
47-
/public_dropin_gpu_environments/python311_genai @datarobot/buzok @datarobot/codegen
4846
/public_dropin_nim_environments @datarobot/tracking-agent @datarobot/custom-models
4947
/public_dropin_notebook_environments @datarobot/custom-models @datarobot/cfx
5048
/task_templates @datarobot/core-modeling
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Copyright 2025 DataRobot, Inc. and its affiliates.
2+
# All rights reserved.
3+
# DataRobot, Inc. Confidential.
4+
# This is unpublished proprietary source code of DataRobot, Inc.
5+
# and its affiliates.
6+
# The copyright notice above does not evidence any actual or intended
7+
# publication of such source code.
8+
9+
ARG WORKDIR=/etc/system/kernel
10+
ARG AGENTDIR=/etc/system/kernel/agent
11+
ARG VENV_PATH=${WORKDIR}/.venv
12+
13+
ARG UNAME=notebooks
14+
ARG UID=10101
15+
ARG GID=10101
16+
17+
FROM datarobotdev/mirror_chainguard_datarobot.com_python-fips:3.11-dev AS base
18+
19+
ARG UNAME
20+
ARG UID
21+
ARG GID
22+
ARG WORKDIR
23+
ARG AGENTDIR
24+
ARG VENV_PATH
25+
26+
USER root
27+
28+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
29+
RUN apk add --no-cache graphviz openblas openssh-server gzip zip unzip curl \
30+
openjdk-11 vim nano procps tzdata poppler-utils
31+
RUN apk add rust sqlite
32+
33+
ENV PYTHONUNBUFFERED=1 \
34+
PYTHONDONTWRITEBYTECODE=1 \
35+
VENV_PATH=${VENV_PATH} \
36+
PIP_NO_CACHE_DIR=1 \
37+
NOTEBOOKS_KERNEL="python"
38+
39+
ENV PATH="$VENV_PATH/bin:$PATH" \
40+
PYTHONPATH="/home/notebooks/.ipython/extensions:/home/notebooks/storage"
41+
42+
RUN python3 -m venv ${VENV_PATH} && pip3 install -U pip setuptools
43+
WORKDIR ${WORKDIR}
44+
45+
COPY ./agent/agent.py ./agent/cgroup_watchers.py ${AGENTDIR}/
46+
COPY ./jupyter_kernel_gateway_config.py ./start_server.sh ${WORKDIR}/
47+
COPY ./ipython_config.py /etc/ipython/
48+
COPY ./extensions /etc/ipython/extensions
49+
50+
# Adding SSHD requirements
51+
COPY ./sshd_config /etc/ssh/
52+
RUN cp -a /etc/ssh /etc/ssh.cache && rm -rf /var/lib/apt/lists/*
53+
RUN mkdir /etc/authorized_keys
54+
55+
# Custom user to run the image from
56+
RUN addgroup -g "$GID" "$UNAME" && \
57+
adduser -D -u "$UID" -G "$UNAME" -s /bin/bash "$UNAME"
58+
59+
# Prompt customizations
60+
COPY ./setup-prompt.sh /etc/profile.d/setup-prompt.sh
61+
62+
# additional setup scripts
63+
COPY ./setup-ssh.sh ./common-user-limits.sh ./setup-venv.sh ${WORKDIR}/
64+
65+
# Adding SSHD requirements
66+
RUN chown -R $UNAME:$UNAME ${WORKDIR} ${VENV_PATH} /home/notebooks /etc/ssh /etc/authorized_keys \
67+
# sshd prep
68+
&& touch /etc/profile.d/notebooks-load-env.sh \
69+
&& chown -R $UNAME:$UNAME /etc/profile.d/notebooks-load-env.sh \
70+
# Limit max processes
71+
&& touch /etc/profile.d/bash-profile-load.sh \
72+
&& chown -R $UNAME:$UNAME /etc/profile.d/bash-profile-load.sh
73+
74+
USER $UNAME
75+
76+
# Jupyter Gateway port
77+
EXPOSE 8888
78+
# sshd port
79+
EXPOSE 22
80+
81+
FROM base AS builder
82+
# this stage has only bare minimal of dependencies installed to optimize build time for the local development
83+
84+
ARG WORKDIR
85+
ARG VENV_PATH
86+
87+
COPY ./run_agent.py ${WORKDIR}/
88+
COPY ./requirements.txt ${WORKDIR}/
89+
COPY ./requirements-genai.txt ${WORKDIR}/
90+
COPY ./agent/requirements-agent.txt ${WORKDIR}/
91+
RUN python3 -m ensurepip --upgrade
92+
RUN python3 -m pip install --upgrade pip setuptools
93+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements.txt && rm ${WORKDIR}/requirements.txt
94+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements-agent.txt && rm ${WORKDIR}/requirements-agent.txt
95+
96+
# Generative AI Agents
97+
RUN python3 -m pip uninstall -y urllib3
98+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements-genai.txt && rm ${WORKDIR}/requirements-genai.txt
99+
RUN python3 -m pip uninstall -y litellm
100+
RUN python3 -m pip install --no-cache-dir --no-warn-conflicts git+https://github.com/datarobot-forks/litellm@mattn/add-datarobot-support-to-litellm
101+
102+
RUN rm ${VENV_PATH}/share/jupyter/kernels/python3/kernel.json && chmod a+x ${WORKDIR}/start_server.sh
103+
COPY ./kernel.json ${VENV_PATH}/share/jupyter/kernels/python3/
104+
105+
# Monitoring agent port
106+
EXPOSE 8889
107+
108+
FROM base AS kernel
109+
# this stage is what actually going to be run as kernel image and it's clean from all build junks
110+
111+
ARG UNAME
112+
ARG WORKDIR
113+
ARG GIT_COMMIT
114+
115+
LABEL com.datarobot.repo-name="notebooks"
116+
LABEL com.datarobot.repo-sha=$GIT_COMMIT
117+
118+
RUN chown -R $UNAME:$UNAME ${WORKDIR} /home/notebooks
119+
120+
COPY --from=builder --chown=$UNAME $WORKDIR $WORKDIR
121+
122+
# This is required for custom models to work with this image
123+
COPY ./start_server_drum.sh /opt/code/start_server.sh
124+
ENV HOME=/opt CODE_DIR=/opt/code ADDRESS=0.0.0.0:8080
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Copyright 2025 DataRobot, Inc. and its affiliates.
2+
# All rights reserved.
3+
# DataRobot, Inc. Confidential.
4+
# This is unpublished proprietary source code of DataRobot, Inc.
5+
# and its affiliates.
6+
# The copyright notice above does not evidence any actual or intended
7+
# publication of such source code.
8+
9+
ARG WORKDIR=/etc/system/kernel
10+
ARG AGENTDIR=/etc/system/kernel/agent
11+
ARG VENV_PATH=${WORKDIR}/.venv
12+
13+
ARG UNAME=notebooks
14+
ARG UID=10101
15+
ARG GID=10101
16+
17+
# This reproduces a open source variant of https://images.chainguard.dev/directory/image/python
18+
FROM cgr.dev/chainguard/wolfi-base AS chainguard_python_dev
19+
20+
ARG PYTHON_VERSION=3.11
21+
SHELL ["/bin/sh", "-o", "pipefail", "-c"]
22+
RUN echo "[Python $PYTHON_VERSION]"
23+
24+
ENV PATH="${PATH}:/sbin"
25+
RUN apk update && apk upgrade
26+
# Wolfi python image
27+
RUN apk add --no-cache ca-certificates-bundle gdbm glibc glibc-locale-posix \
28+
ld-linux libbz2-1 libcrypto3 libexpat1 libffi libgcc libssl3 libstdc++ \
29+
mpdecimal ncurses ncurses-terminfo readline sqlite-libs \
30+
wolfi-baselayout xz zlib
31+
# Wolfi python dev image
32+
RUN apk add --no-cache apk-tools bash binutils build-base busybox cyrus-sasl \
33+
gcc git glibc-dev gmp heimdal-libs isl keyutils-libs \
34+
krb5-conf krb5-libs libatomic libbrotlicommon1 libbrotlidec1 \
35+
libcom_err libcrypt1 libcurl-openssl4 libgo libgomp libidn2 \
36+
libldap libnghttp2-14 libpcre2-8-0 libpsl libquadmath libstdc++-dev \
37+
libunistring libverto libxcrypt libxcrypt-dev libzstd1 \
38+
linux-headers make mpc mpfr nss-db nss-hesiod \
39+
openssf-compiler-options pkgconf posix-cc-wrappers wget
40+
# Python
41+
RUN apk add --no-cache \
42+
python-$PYTHON_VERSION \
43+
python-$PYTHON_VERSION-base \
44+
py$PYTHON_VERSION-pip \
45+
py3-pip-wheel
46+
# Python dev
47+
RUN apk add python-$PYTHON_VERSION-dev \
48+
python-$PYTHON_VERSION-base-dev \
49+
py$PYTHON_VERSION-pip-base \
50+
py$PYTHON_VERSION-setuptools
51+
52+
FROM chainguard_python_dev AS base
53+
54+
ARG UNAME
55+
ARG UID
56+
ARG GID
57+
ARG WORKDIR
58+
ARG AGENTDIR
59+
ARG VENV_PATH
60+
61+
USER root
62+
63+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
64+
RUN apk add --no-cache graphviz openblas openssh-server gzip zip unzip curl \
65+
openjdk-11 vim nano procps tzdata poppler-utils
66+
RUN apk add rust sqlite
67+
68+
ENV PYTHONUNBUFFERED=1 \
69+
PYTHONDONTWRITEBYTECODE=1 \
70+
VENV_PATH=${VENV_PATH} \
71+
PIP_NO_CACHE_DIR=1 \
72+
NOTEBOOKS_KERNEL="python"
73+
74+
ENV PATH="$VENV_PATH/bin:$PATH" \
75+
PYTHONPATH="/home/notebooks/.ipython/extensions:/home/notebooks/storage"
76+
77+
RUN python3 -m venv ${VENV_PATH} && pip3 install -U pip setuptools
78+
WORKDIR ${WORKDIR}
79+
80+
COPY ./agent/agent.py ./agent/cgroup_watchers.py ${AGENTDIR}/
81+
COPY ./jupyter_kernel_gateway_config.py ./start_server.sh ${WORKDIR}/
82+
COPY ./ipython_config.py /etc/ipython/
83+
COPY ./extensions /etc/ipython/extensions
84+
85+
# Adding SSHD requirements
86+
COPY ./sshd_config /etc/ssh/
87+
RUN cp -a /etc/ssh /etc/ssh.cache && rm -rf /var/lib/apt/lists/*
88+
RUN mkdir /etc/authorized_keys
89+
90+
# Custom user to run the image from
91+
RUN addgroup -g "$GID" "$UNAME" && \
92+
adduser -D -u "$UID" -G "$UNAME" -s /bin/bash "$UNAME"
93+
94+
# Prompt customizations
95+
COPY ./setup-prompt.sh /etc/profile.d/setup-prompt.sh
96+
97+
# additional setup scripts
98+
COPY ./setup-ssh.sh ./common-user-limits.sh ./setup-venv.sh ${WORKDIR}/
99+
100+
# Adding SSHD requirements
101+
RUN chown -R $UNAME:$UNAME ${WORKDIR} ${VENV_PATH} /home/notebooks /etc/ssh /etc/authorized_keys \
102+
# sshd prep
103+
&& touch /etc/profile.d/notebooks-load-env.sh \
104+
&& chown -R $UNAME:$UNAME /etc/profile.d/notebooks-load-env.sh \
105+
# Limit max processes
106+
&& touch /etc/profile.d/bash-profile-load.sh \
107+
&& chown -R $UNAME:$UNAME /etc/profile.d/bash-profile-load.sh
108+
109+
USER $UNAME
110+
111+
# Jupyter Gateway port
112+
EXPOSE 8888
113+
# sshd port
114+
EXPOSE 22
115+
116+
FROM base AS builder
117+
# this stage has only bare minimal of dependencies installed to optimize build time for the local development
118+
119+
ARG WORKDIR
120+
ARG VENV_PATH
121+
122+
COPY ./run_agent.py ${WORKDIR}/
123+
COPY ./requirements.txt ${WORKDIR}/
124+
COPY ./requirements-genai.txt ${WORKDIR}/
125+
COPY ./agent/requirements-agent.txt ${WORKDIR}/
126+
RUN python3 -m ensurepip --upgrade
127+
RUN python3 -m pip install --upgrade pip setuptools
128+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements.txt && rm ${WORKDIR}/requirements.txt
129+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements-agent.txt && rm ${WORKDIR}/requirements-agent.txt
130+
131+
# Generative AI Agents
132+
RUN python3 -m pip uninstall -y urllib3
133+
RUN python3 -m pip install --no-cache-dir -r ${WORKDIR}/requirements-genai.txt && rm ${WORKDIR}/requirements-genai.txt
134+
RUN python3 -m pip uninstall -y litellm
135+
RUN python3 -m pip install --no-cache-dir --no-warn-conflicts git+https://github.com/datarobot-forks/litellm@mattn/add-datarobot-support-to-litellm
136+
137+
RUN rm ${VENV_PATH}/share/jupyter/kernels/python3/kernel.json && chmod a+x ${WORKDIR}/start_server.sh
138+
COPY ./kernel.json ${VENV_PATH}/share/jupyter/kernels/python3/
139+
140+
# Monitoring agent port
141+
EXPOSE 8889
142+
143+
FROM base AS kernel
144+
# this stage is what actually going to be run as kernel image and it's clean from all build junks
145+
146+
ARG UNAME
147+
ARG WORKDIR
148+
ARG GIT_COMMIT
149+
150+
LABEL com.datarobot.repo-name="notebooks"
151+
LABEL com.datarobot.repo-sha=$GIT_COMMIT
152+
153+
RUN chown -R $UNAME:$UNAME ${WORKDIR} /home/notebooks
154+
155+
COPY --from=builder --chown=$UNAME $WORKDIR $WORKDIR
156+
157+
# This is required for custom models to work with this image
158+
COPY ./start_server_drum.sh /opt/code/start_server.sh
159+
ENV HOME=/opt CODE_DIR=/opt/code ADDRESS=0.0.0.0:8080
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Python 3 GenAI Agents Drop-In Template Environment
2+
3+
This template environment can be used to create GenAI-powered custom models and includes common dependencies for
4+
workflows using CrewAI, LangGraph, Llama-Index and other agentic workflows.
5+
6+
Additionally, this environment is fully compatible with `Codespaces` and `Notebooks` in the DataRobot platform.
7+
8+
## Supported Libraries
9+
10+
This environment is built for python 3 and has support for the following libraries.
11+
For specific version information and the complete list of included packages, see [requirements](requirements.txt).
12+
13+
- crewai
14+
- langgraph
15+
- langchain
16+
- llama-index
17+
- openai
18+
- numpy
19+
- pandas
20+
21+
## Instructions
22+
23+
1. From the terminal, run `tar -czvf py_dropin.tar.gz -C /path/to/public_dropin_environments/python311_genai_agents/ .`
24+
2. Using either the API or from the UI create a new Custom Environment with the tarball created
25+
in step 1.
26+
27+
_The Dockerfile.local should be used when customizing the Dockerfile or building locally._
28+
29+
### Creating models for this environment
30+
31+
To use this environment, your custom model archive will typically contain a `custom.py` file containing the necessary hooks, as well as other files needed for your workflow. You can implement the hook functions such as `load_model` and `score_unstructured`, as documented [here](../../custom_model_runner/README.md)
32+
33+
Within your `custom.py` code, by importing the necessary dependencies found in this environment, you can implement your Python code under the related custom hook functions, to build your GenAI workflows.
34+
35+
If you need additional dependencies, you can add those packages in your `requirements.txt` file that you include within your custom model archive and DataRobot will make them available to your custom Python code after you build the environment.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This folder contains dependencies required to use this custom environment for DataRobot Notebooks.
2+
Please do not modify or delete this folder from your Docker context.

0 commit comments

Comments
 (0)