Skip to content

[BUZZOK-26844] Remove drum server from everywhere in genai_agents image, replace with drum inline predictor #1595

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
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "This template environment can be used to create GenAI-powered agents using CrewAI, LangGraph, or Llama-Index. Similar to other drop-in environments, you can either include a .pth artifact or any other code needed to deserialize your model, and optionally a custom.py file. You can also use this environment in codespaces.",
"programmingLanguage": "python",
"label": "",
"environmentVersionId": "6876b52bd0b01d0513661808",
"environmentVersionId": "6879340432d95c11903cb7bb",
"environmentVersionDescription": "",
"isPublic": true,
"isDownloadable": true,
Expand All @@ -15,8 +15,8 @@
"contextUrl": "https://github.com/datarobot/datarobot-user-models/tree/master/public_dropin_environments/python311_genai_agents",
"imageRepository": "env-python-genai-agents",
"tags": [
"v11.2.0-6876b52bd0b01d0513661808",
"6876b52bd0b01d0513661808",
"v11.2.0-6879340432d95c11903cb7bb",
"6879340432d95c11903cb7bb",
"v11.2.0-latest"
]
}
22 changes: 12 additions & 10 deletions public_dropin_environments/python311_genai_agents/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ crewai-tools>=0.48.0
datarobot-drum>=1.16.19
datarobot-moderations>=11.2.0
datarobot-mlops>=11.1.0
datarobot>=3.7.0
datarobot[auth]>=3.8.1
dotenv~=0.9.9
langchain-community~=0.3.23
langchain-mcp-adapters~=0.1.9
langchain~=0.3.23
langgraph~=0.4.10
langgraph-prebuilt~=0.2.3
Expand All @@ -39,18 +40,19 @@ llama-index-llms-langchain~=0.6.1
llama-index-llms-litellm~=0.4.1
llama-index-llms-openai~=0.3.38
llama-index~=0.12.33
mcp~=1.11.0
multidict~=6.5.0
onnxruntime~=1.22.0
openai~=1.76.2
opentelemetry-api~=1.33.0
opentelemetry-instrumentation-aiohttp-client~=0.54b0
opentelemetry-instrumentation-crewai~=0.40.5
opentelemetry-instrumentation-httpx~=0.54b0
opentelemetry-instrumentation-langchain~=0.40.5
opentelemetry-instrumentation-llamaindex~=0.40.5
opentelemetry-instrumentation-openai~=0.40.5
opentelemetry-instrumentation-requests~=0.54b0
opentelemetry-sdk~=1.33.0
opentelemetry-api>=1.33.0,<2.0.0
opentelemetry-instrumentation-aiohttp-client>=0.54b0
opentelemetry-instrumentation-crewai>=0.40.5
opentelemetry-instrumentation-httpx>=0.54b0
opentelemetry-instrumentation-langchain>=0.40.5
opentelemetry-instrumentation-llamaindex>=0.40.5
opentelemetry-instrumentation-openai>=0.40.5
opentelemetry-instrumentation-requests>=0.54b0
opentelemetry-sdk>=1.33.0
python-dotenv~=1.1.0
ragas @ git+https://github.com/explodinggradients/ragas@5d59549ad5ef511f621502c563bc55ac5aeb9188#subdirectory=ragas
requests~=2.32.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ crewai==0.140.0
crewai-tools==0.48.0
cryptography==44.0.3
dataclasses-json==0.6.7
datarobot==3.7.1
datarobot[auth]==3.8.2
datarobot-drum==1.16.19
datarobot-mlops==11.1.0
datarobot-moderations==11.2.0
Expand Down Expand Up @@ -169,6 +169,7 @@ langchain-cohere==0.3.5
langchain-community==0.3.23
langchain-core==0.3.59
langchain-experimental==0.3.4
langchain-mcp-adapters==0.1.9
langchain-nvidia-ai-endpoints==0.3.10
langchain-openai==0.2.14
langchain-text-splitters==0.3.8
Expand Down Expand Up @@ -208,6 +209,7 @@ markdown-it-py==3.0.0
markupsafe==3.0.2
marshmallow==3.26.1
matplotlib-inline==0.1.7
mcp==1.11.0
mdurl==0.1.2
mem0ai==0.1.98
memory-profiler==0.61.0
Expand Down Expand Up @@ -334,6 +336,7 @@ pytest-xdist==3.7.0
python-dateutil==2.9.0.post0
python-dotenv==1.1.0
python-json-logger==3.3.0
python-multipart==0.0.20
pytube==15.0.0
pytz==2024.2
pyvis==0.3.2
Expand Down Expand Up @@ -368,6 +371,7 @@ six==1.17.0
sniffio==1.3.1
soupsieve==2.7
sqlalchemy[asyncio]==2.0.40
sse-starlette==2.4.1
stack-data==0.6.3
starlette==0.46.2
strenum==0.4.15
Expand All @@ -393,7 +397,7 @@ twine==5.1.1
typer==0.15.3
types-python-dateutil==2.9.0.20241206
types-requests==2.32.0.20250328
typing-extensions==4.13.2
typing-extensions==4.14.1
typing-inspect==0.9.0
typing-inspection==0.4.0
tzdata==2025.2
Expand Down
73 changes: 4 additions & 69 deletions public_dropin_environments/python311_genai_agents/run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
from typing import Any, TextIO, cast
from urllib.parse import urlparse, urlunparse

import requests
from datarobot_drum.drum.enum import TargetType
from datarobot_drum.drum.root_predictors.drum_inline_utils import drum_inline_predictor
from datarobot_drum.drum.root_predictors.drum_server_utils import DrumServerRun
from openai import OpenAI
from openai.types.chat import ChatCompletion
from openai.types.chat.completion_create_params import (
CompletionCreateParamsBase,
)
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.propagate import inject
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.trace import Span, use_span
Expand Down Expand Up @@ -89,11 +85,6 @@ def argparse_args() -> argparse.Namespace:
default=None,
help="Custom attributes for tracing. Should be a JSON dictionary.",
)
parser.add_argument(
"--use_serverless",
action="store_true",
help="Use DRUM serverless predictor.",
)
args = parser.parse_args()
return args

Expand Down Expand Up @@ -203,55 +194,6 @@ def setup_otel(args: Any) -> Span:
return span


def execute_drum(
chat_completion: CompletionCreateParamsBase,
default_headers: dict[str, str],
custom_model_dir: Path,
) -> ChatCompletion:
root.info("Executing agent as [chat] endpoint. DRUM Executor.")
root.info("Starting DRUM server.")
with DrumServerRun(
target_type=TargetType.AGENTIC_WORKFLOW.value,
labels=None,
custom_model_dir=custom_model_dir,
with_error_server=True,
production=False,
verbose=True,
logging_level="info",
target_name="response",
wait_for_server_timeout=360,
port=get_open_port(),
stream_output=True,
max_workers=2, # this will force drum tracing to not use batchprocessor
) as drum_runner:
root.info("Verifying DRUM server")
response = requests.get(drum_runner.url_server_address)
if not response.ok:
root.error("Server failed to start")
try:
root.error(response.text)
finally:
raise RuntimeError("Server failed to start")

# inject OTEL headers into default_headers
inject(default_headers)

# Use a standard OpenAI client to call the DRUM server. This mirrors the behavior of a deployed agent.
# Using the `chat.completions.create` method ensures the parameters are OpenAI compatible.
root.info("Executing Agent")
client = OpenAI(
base_url=drum_runner.url_server_address,
api_key="not-required",
default_headers=default_headers,
max_retries=0,
)
completion = client.chat.completions.create(**chat_completion)

# Continue outside the context manager to ensure the server is stopped and logs
# are flushed before we write the output
return completion


def execute_drum_inline(
chat_completion: CompletionCreateParamsBase,
custom_model_dir: Path,
Expand Down Expand Up @@ -304,17 +246,10 @@ def run_agent_procedure(args: Any) -> None:
root.info(f"Trace id: {trace_id}")

root.info(f"Executing request in directory {args.custom_model_dir}")
if args.use_serverless:
result = execute_drum_inline(
chat_completion=chat_completion,
custom_model_dir=args.custom_model_dir,
)
else:
result = execute_drum(
chat_completion=chat_completion,
default_headers=default_headers,
custom_model_dir=args.custom_model_dir,
)
result = execute_drum_inline(
chat_completion=chat_completion,
custom_model_dir=args.custom_model_dir,
)
store_result(
result,
trace_id,
Expand Down