How-to: Modify the CrewAI template¶
This tutorial explains how to take a simple agentic workflow, created locally, and use the DataRobot Agent Templates repository to accelerate the implementation of this agent in the DataRobot framework. For a more complex agentic workflow implementing DataRobot deployed global tools, see Data Registry global tools with CrewAI agents.
Clone the datarobot-agent-templates repository¶
To start building an agentic workflow, clone the datarobot-agent-templates public repository. This repository provides ready-to-use templates for building and deploying AI agents with multi-agent frameworks. These templates streamline the process of setting up your own agents with minimal configuration requirements.
To begin, clone the DataRobot Agent Templates repository using the command line/terminal in your development environment and the command below:
git clone --branch 11.3.5 --depth 1 https://github.com/datarobot-community/datarobot-agent-templates.git
cd datarobot-agent-templates
datarobot-agent-templates version
This walkthrough uses version 11.3.5 of the datarobot-agent-templates repository. Ensure that the workspace used for this walkthrough is on that version. Newer versions may not be compatible with the code provided below.
GitHub clone URL
For more information on cloning a GitHub repository, see the GitHub documentation.
Bring custom agent code into a DataRobot agent template¶
When integrating a local agentic workflow into the DataRobot Agentic AI Platform, the DataRobot Agent Templates repository accelerates the local development process by providing boilerplate code, testing functionality, and deployment pipelines. If a template exists for the agent you created outside the DataRobot Agentic AI Platform, use the existing template. DataRobot agentic workflow templates are provided for CrewAI, LangGraph, and Llama-Index. If a template doesn't exist for the framework you're using, use the Generic Base template.
For this example, a large language model (LLM) was asked to produce "a CrewAI agent that produces marketing copy based on a prompt." The resulting output is well suited to integrate with the CrewAI template. The CrewAI agent that was output consisted of a .env file and a python script (marketing_crew.py):
# .env file
OPENAI_API_KEY="sk-your-openai-api-key-here"
SERPER_API_KEY="your-serper-api-key-here"
# marketing_crew.py
import os
from dotenv import load_dotenv
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
# Load environment variables from .env file
load_dotenv()
# --- 1. Tool Setup ---
# Initialize the search tool. This allows agents to perform web searches.
# It uses the SERPER_API_KEY from your .env file.
search_tool = SerperDevTool()
# --- 2. Agent Definitions ---
# Each agent has a specific role, goal, and backstory. This helps the LLM
# to adopt a particular persona and focus on its specific task.
# Agent 1: Market Researcher
researcher = Agent(
role='Senior Market Researcher',
goal='To find and analyze the target audience and marketing angles for a given product',
backstory="""You are a seasoned market researcher with a knack for uncovering consumer insights.
You excel at identifying demographics, psychographics, and the key pain points of a target audience.
Your analysis forms the foundation of any successful marketing campaign.""",
verbose=True, # Enables detailed logging of the agent's thought process
allow_delegation=False,
tools=[search_tool] # Assign the search tool to this agent
)
# Agent 2: Marketing Copywriter
copywriter = Agent(
role='Expert Marketing Copywriter',
goal='To write compelling and persuasive marketing copy based on market research',
backstory="""You are a world-class copywriter, known for your ability to weave words that sell.
You take research and transform it into captivating headlines, engaging social media posts,
and persuasive product descriptions. Your copy is clear, concise, and converts.""",
verbose=True,
allow_delegation=False
)
# Agent 3: Review and Editing Specialist
editor = Agent(
role='Chief Editor and Marketing Strategist',
goal='To review and refine marketing copy for clarity, tone, brand alignment, and effectiveness',
backstory="""You are a meticulous editor with a deep understanding of marketing strategy.
You have a keen eye for detail and ensure that all copy is not only grammatically perfect
but also aligns with the brand's voice and strategic goals. You provide the final polish.""",
verbose=True,
allow_delegation=False
)
# --- 3. Task Definitions ---
# Tasks are the specific assignments for the agents.
# The 'context' parameter is crucial as it passes the output of one task to the next.
# Task 1: Research the product
research_task = Task(
description="""Analyze the provided product: '{product_description}'.
Identify the primary target audience, their key pain points, and desires.
Research competitors and identify unique selling propositions (USPs).
The final output should be a concise report with actionable insights.""",
expected_output="""A report containing:
1. Target Audience Profile (demographics, interests, online behavior).
2. Key Pain Points and Desires of the audience.
3. A list of 3-5 Unique Selling Propositions (USPs) for the product.
4. Competitor analysis summary.""",
agent=researcher # Assign this task to the researcher agent
)
# Task 2: Write the marketing copy
copywriting_task = Task(
description="""Using the market research report, write three distinct pieces of marketing copy for the product: '{product_description}'.
The copy should be tailored to the identified target audience.
The pieces are:
1. A catchy Facebook ad post (approx. 50-80 words).
2. An engaging email subject line and a short preview text.
3. A persuasive product description for an e-commerce website (approx. 100-150 words).""",
expected_output="""A document with three sections:
1. Facebook Ad Copy.
2. Email Subject Line and Preview.
3. E-commerce Product Description.""",
agent=copywriter
)
# Task 3: Review and refine the copy
review_task = Task(
description="""Review the marketing copy provided. Check for grammatical errors, clarity, and brand voice alignment.
Ensure the copy is persuasive and directly addresses the target audience's pain points identified in the research.
Provide a final, polished version of all three copy pieces with constructive feedback.""",
expected_output="""The final, production-ready marketing copy for all three formats,
along with a brief note on any significant changes made and why.""",
agent=editor
)
# --- 4. Crew Assembly ---
# The Crew object brings the agents and tasks together.
# The process determines how the tasks are executed (e.g., sequentially).
marketing_crew = Crew(
agents=[researcher, copywriter, editor],
tasks=[research_task, copywriting_task, review_task],
process=Process.sequential, # Tasks will be executed one after another
verbose=2 # Verbose logging level (0, 1, or 2)
)
# --- 5. Execution ---
# The kickoff method starts the crew's work.
# We provide the initial input as a dictionary.
product_prompt = {
'product_description': 'A new, eco-friendly, smart coffee mug that keeps your drink at the perfect temperature for 3 hours. It is controlled by a mobile app and made from recycled materials.'
}
result = marketing_crew.kickoff(inputs=product_prompt)
print("\n\n########################")
print("## Here is the final result:")
print("########################\n")
print(result)
Set up the environment¶
Before integrating the code above into a template, set up the CrewAI template to bootstrap the implementation. In the datarobot-agent-templates repository directory, open the terminal and use the command below to copy and rename the provided template environment file (.env.template). In this file, define the necessary environment variables.
cp .env.template .env
Locate and open the new .env file. Define the DATAROBOT_API_TOKEN and DATAROBOT_ENDPOINT environment variables in the file. Then, provide any string to define a PULUMI_CONFIG_PASSPHRASE.
DataRobot credentials in codespaces
If you are using a DataRobot codespace, remove the DATAROBOT_API_TOKEN and DATAROBOT_ENDPOINT environment variables from the file, as they already exist in the codespace environment.
These values are loaded into the agent.py file using dotenv (implemented in the Taskfile) to read the key-value pairs from the .env file.
Run the CrewAI quickstart¶
Next, use task start to run quickstart.py, selecting the CrewAI template.
task start
To select the CrewAI template press 1 and then press Enter to confirm your selection.
task start
task: [start] uv run quickstart.py
***** * **** * *
* * *** ***** *** * * *** **** *** *****
* * * * * * * **** * * * * * * *
***** *** * * *** * * * *** **** *** *
--------------------------------------------------------
Quickstart for DataRobot AI Agents
--------------------------------------------------------
Checking environment setup for required pre-requisites...
All pre-requisites are installed.
You will now select an agentic framework to use for this project.
For more information on the different agentic frameworks please go to:
https://github.com/datarobot-community/datarobot-agent-templates/blob/main/docs/getting-started.md
Please select an agentic framework to use:
1. agent_crewai
2. agent_generic_base
3. agent_langgraph
4. agent_llamaindex
5. agent_nat
Enter your choice (1-5): 1
Next, press Y and then press Enter to install prerequisites and set up environments for the selected agent:
Would you like to setup the uv python environments and install pre-requisites now?
(y/n): y
Running these commands configures the environment for the agent_crewai template, removes all unnecessary files, and prepares the virtualenv to install the additional libraries required to run the selected agent template.
You can refresh the installed environment at any time by running:
task install
Optionally, before customizing the agent template, run the agent without modification to test the code:
task agent:cli START_DEV=1 -- execute --user_prompt 'Hi, how are you?'
Now you can customize your agent code in the agent_crewai/custom_model directory. In this walkthrough, the environment remains unchanged.
View all task commands
Before running task start, to view available tasks for the project, run the task command as shown below:
❯ task
task: Available tasks for this project:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* install: Install dependencies for all agent components and infra (aliases: req, install-all)
* start: ‼️ Quickstart for DataRobot Agent Templates ‼️
After running task start and selecting a framework, to view available tasks for the project, run the task command as shown below:
❯ task
task: Available tasks for this project:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* install: 🛠️ Install all dependencies for agent and infra
* agent:install: 🛠️ [agent_crewai] Install agent uv dependencies (aliases: agent:req)
* agent:add-dependency: 🛠️ [agent_crewai] Add provided packages as a new dependency to an agent
* agent:cli: 🖥️ [agent_crewai] Run the CLI with provided arguments
* agent:dev: 🔨 [agent_crewai] Run the development server
* agent:dev-stop: 🛑 [agent_crewai] Stop the development server
* agent:chainlit: 🛝 Run the Chainlit playground
* agent:create-docker-context: 🐳 [agent_crewai] Create the template for a local docker_context image
* agent:build-docker-context: 🐳 [agent_crewai] Build the Docker image
* infra:install: 🛠️ [infra] Install infra uv dependencies
* infra:build: 🔵 Deploy only playground testing resources with pulumi
* infra:deploy: 🟢 Deploy all resources with pulumi
* infra:refresh: ⚪️ Refresh and sync local pulumi state
* infra:destroy: 🔴 Teardown all deployed resources with pulumi
❯ task --list-all
task: Available tasks for this project:
* build:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* deploy:
* destroy:
* install: 🛠️ Install all dependencies for agent and infra
* agent:add-dependency: 🛠️ [agent_crewai] Add provided packages as a new dependency to an agent
* agent:build-docker-context: 🐳 [agent_crewai] Build the Docker image
* agent:chainlit: 🛝 Run the Chainlit playground
* agent:cli: 🖥️ [agent_crewai] Run the CLI with provided arguments
* agent:create-docker-context: 🐳 [agent_crewai] Create the template for a local docker_context image
* agent:dev: 🔨 [agent_crewai] Run the development server
* agent:dev-stop: 🛑 [agent_crewai] Stop the development server
* agent:install: 🛠️ [agent_crewai] Install agent uv dependencies (aliases: agent:req)
* agent:lint:
* agent:lint-check:
* agent:test:
* agent:test-coverage:
* agent:update:
* infra:build: 🔵 Deploy only playground testing resources with pulumi
* infra:deploy: 🟢 Deploy all resources with pulumi
* infra:destroy: 🔴 Teardown all deployed resources with pulumi
* infra:info:
* infra:init:
* infra:install: 🛠️ [infra] Install infra uv dependencies
* infra:install-pulumi-plugin:
* infra:lint:
* infra:lint-check:
* infra:pulumi:
* infra:refresh: ⚪️ Refresh and sync local pulumi state
* infra:select:
* infra:select-env-stack:
* infra:test:
* infra:test-coverage:
In addition, to view all available agent CLI commands, run task agent:cli.
Integrate the custom agent code¶
The custom agent code generated locally, outside the DataRobot Agentic AI Platform, can be integrated into the agent_crewai template with minimal modification. To implement the agent example above, modify the .env file and the agent.py file. All other files remain unmodified.
Modify the .env file¶
The first file generated for the agent developed locally was a .env file. The required credentials identified were OPENAI_API_KEY and SERPER_API_KEY. The OPENAI_API_KEY is intended for the agent's base LLM; however, it isn't required for the agent in DataRobot. The SERPER_API_KEY is required to use CrewAI's built-in Google Serper Search tool. This tool requires a free account for API access.
To use CrewAI's built-in Google Serper Search tool, add the SERPER_API_KEY to the .env file at the root of the datarobot-agent-templates directory (where the DATAROBOT_API_TOKEN and DATAROBOT_ENDPOINT were defined). The agent code will automatically load this key from runtime parameters when deployed, or from the environment file during local development.
| .env file | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Modify the agent.py file¶
The first file generated for the agent developed locally was a marketing_crew.py file. The code in this file must be integrated into the agent.py file, mainly in the MyAgent class. The only changes outside the MyAgent class are to add the Process class to the crewai library import and to add the SerperDevTool class from the crewai_tools library. Copy the contents of the code block below and replace the contents of the agent_crewai/custom_model/agent.py file. Use git diff to identify the exact changes to the original template-created agent.py file.
Copy code from this walkthrough
This walkthrough requires copying large code blocks to modify the existing template. To copy the full contents of a code snippet, click Copy to clipboard in the upper-right corner of the snippet.
import json
import os
import re
from typing import Any, Generator, Optional, Union
from urllib.parse import urljoin, urlparse
from crewai import LLM, Agent, Crew, Task, Process
from crewai_tools import SerperDevTool
from crewai_event_listener import CrewAIEventListener
from openai.types.chat import CompletionCreateParams
from ragas import MultiTurnSample
from ragas.messages import AIMessage, HumanMessage, ToolMessage
class MyAgent:
"""MyAgent is a custom marketing crew that uses CrewAI to research, write, and edit marketing content.
It utilizes DataRobot's LLM Gateway or a specific deployment for language model interactions.
This example illustrates 3 agents that handle marketing tasks: market research, copywriting, and editing.
"""
def __init__(
self,
api_key: Optional[str] = None,
api_base: Optional[str] = None,
model: Optional[str] = None,
verbose: Optional[Union[bool, str]] = True,
timeout: Optional[int] = 90,
**kwargs: Any,
):
"""Initializes the MyAgent class with API key, base URL, model, and verbosity settings.
Args:
api_key: Optional[str]: API key for authentication with DataRobot services.
Defaults to None, in which case it will use the DATAROBOT_API_TOKEN environment variable.
api_base: Optional[str]: Base URL for the DataRobot API.
Defaults to None, in which case it will use the DATAROBOT_ENDPOINT environment variable.
model: Optional[str]: The LLM model to use.
Defaults to None.
verbose: Optional[Union[bool, str]]: Whether to enable verbose logging.
Accepts boolean or string values ("true"/"false"). Defaults to True.
timeout: Optional[int]: How long to wait for the agent to respond.
Defaults to 90 seconds.
**kwargs: Any: Additional keyword arguments passed to the agent.
Contains any parameters received in the CompletionCreateParams.
Returns:
None
"""
self.api_key = api_key or os.environ.get("DATAROBOT_API_TOKEN")
self.api_base = (
api_base
or os.environ.get("DATAROBOT_ENDPOINT")
or "https://api.datarobot.com"
)
self.model = model
self.timeout = timeout
if isinstance(verbose, str):
self.verbose = verbose.lower() == "true"
elif isinstance(verbose, bool):
self.verbose = verbose
self.event_listener = CrewAIEventListener()
# Load SERPER_API_KEY from runtime parameters if available
try:
from datarobot_drum import RuntimeParameters
serper_key = RuntimeParameters.get("SERPER_API_KEY")
if serper_key and serper_key != "SET_VIA_PULUMI_OR_MANUALLY":
os.environ["SERPER_API_KEY"] = serper_key
except (ValueError, ImportError):
pass # Runtime parameters not available in local development
# Initialize the search tool
self.search_tool = SerperDevTool()
@property
def llm(self) -> LLM:
"""Returns a CrewAI LLM instance configured to use DataRobot's LLM Gateway or a specific deployment.
For help configuring different LLM backends see:
https://github.com/datarobot-community/datarobot-agent-templates/blob/main/docs/developing-agents-llm-providers.md
"""
api_base = urlparse(self.api_base)
if os.environ.get("LLM_DEPLOYMENT_ID"):
path = api_base.path
if "/api/v2/deployments" not in path and "api/v2/genai" not in path:
# Ensure the API base ends with /api/v2/ for deployments
if not path.endswith("/"):
path += "/"
if not path.endswith("api/v2/"):
path = urljoin(path, "api/v2/")
api_base = api_base._replace(path=path)
api_base_str = api_base.geturl()
deployment_id = os.environ.get("LLM_DEPLOYMENT_ID")
return LLM(
model="openai/gpt-4o-mini",
api_base=f"{api_base_str}deployments/{deployment_id}/",
api_key=self.api_key,
timeout=self.timeout,
)
else:
# Use LLM Gateway
api_base_str = api_base.geturl()
if api_base_str.endswith("api/v2/"):
api_base_str = api_base_str[:-7] # Remove 'api/v2/'
elif api_base_str.endswith("api/v2"):
api_base_str = api_base_str[:-6] # Remove 'api/v2'
return LLM(
model="datarobot/azure/gpt-4o-mini",
api_base=api_base_str,
api_key=self.api_key,
timeout=self.timeout,
)
@property
def agent_researcher(self) -> Agent:
"""Market Researcher Agent - finds and analyzes target audience and marketing angles."""
return Agent(
role='Senior Market Researcher',
goal='To find and analyze the target audience and marketing angles for a given product',
backstory="""You are a seasoned market researcher with a knack for uncovering consumer insights.
You excel at identifying demographics, psychographics, and the key pain points of a target audience.
Your analysis forms the foundation of any successful marketing campaign.""",
verbose=self.verbose,
allow_delegation=False,
tools=[self.search_tool],
llm=self.llm
)
@property
def agent_copywriter(self) -> Agent:
"""Marketing Copywriter Agent - writes compelling and persuasive marketing copy."""
return Agent(
role='Expert Marketing Copywriter',
goal='To write compelling and persuasive marketing copy based on market research',
backstory="""You are a world-class copywriter, known for your ability to weave words that sell.
You take research and transform it into captivating headlines, engaging social media posts,
and persuasive product descriptions. Your copy is clear, concise, and converts.""",
verbose=self.verbose,
allow_delegation=False,
llm=self.llm
)
@property
def agent_editor(self) -> Agent:
"""Review and Editing Specialist Agent - reviews and refines marketing copy."""
return Agent(
role='Chief Editor and Marketing Strategist',
goal='To review and refine marketing copy for clarity, tone, brand alignment, and effectiveness',
backstory="""You are a meticulous editor with a deep understanding of marketing strategy.
You have a keen eye for detail and ensure that all copy is not only grammatically perfect
but also aligns with the brand's voice and strategic goals. You provide the final polish.""",
verbose=self.verbose,
allow_delegation=False,
llm=self.llm
)
@property
def task_research(self) -> Task:
"""Research task - analyzes the product and identifies target audience and USPs."""
return Task(
description="""Analyze the provided product: '{product_description}'.
Identify the primary target audience, their key pain points, and desires.
Research competitors and identify unique selling propositions (USPs).
The final output should be a concise report with actionable insights.""",
expected_output="""A report containing:
1. Target Audience Profile (demographics, interests, online behavior).
2. Key Pain Points and Desires of the audience.
3. A list of 3-5 Unique Selling Propositions (USPs) for the product.
4. Competitor analysis summary.""",
agent=self.agent_researcher
)
@property
def task_copywriting(self) -> Task:
"""Copywriting task - writes three distinct pieces of marketing copy."""
return Task(
description="""Using the market research report, write three distinct pieces of marketing copy for the product: '{product_description}'.
The copy should be tailored to the identified target audience.
The pieces are:
1. A catchy Facebook ad post (approx. 50-80 words).
2. An engaging email subject line and a short preview text.
3. A persuasive product description for an e-commerce website (approx. 100-150 words).""",
expected_output="""A document with three sections:
1. Facebook Ad Copy.
2. Email Subject Line and Preview.
3. E-commerce Product Description.""",
agent=self.agent_copywriter,
context=[self.task_research]
)
@property
def task_review(self) -> Task:
"""Review task - reviews and refines the marketing copy."""
return Task(
description="""Review the marketing copy provided. Check for grammatical errors, clarity, and brand voice alignment.
Ensure the copy is persuasive and directly addresses the target audience's pain points identified in the research.
Provide a final, polished version of all three copy pieces with constructive feedback.""",
expected_output="""The final, production-ready marketing copy for all three formats,
along with a brief note on any significant changes made and why.""",
agent=self.agent_editor,
context=[self.task_copywriting]
)
def crew(self) -> Crew:
"""Creates the marketing crew with all agents and tasks."""
return Crew(
agents=[self.agent_researcher, self.agent_copywriter, self.agent_editor],
tasks=[self.task_research, self.task_copywriting, self.task_review],
process=Process.sequential,
verbose=self.verbose
)
async def invoke(
self, completion_create_params: CompletionCreateParams
) -> Union[
Generator[tuple[str, Any | None, dict[str, int]], None, None],
tuple[str, Any | None, dict[str, int]],
]:
"""Run the marketing crew with the provided completion parameters.
[THIS METHOD IS REQUIRED FOR THE AGENT TO WORK WITH DRUM SERVER]
Args:
completion_create_params: The completion request parameters including input product description and settings.
Returns:
Union[
Generator[tuple[str, Any | None, dict[str, int]], None, None],
tuple[str, Any | None, dict[str, int]],
]: For streaming requests, returns a generator yielding tuples of (response_text, pipeline_interactions, usage_metrics).
For non-streaming requests, returns a single tuple of (response_text, pipeline_interactions, usage_metrics).
"""
# Retrieve the starting user prompt from the CompletionCreateParams
user_messages = [
msg
for msg in completion_create_params["messages"]
# You can use other roles as needed (e.g. "system", "assistant")
if msg.get("role") == "user"
]
user_prompt: Any = user_messages[0] if user_messages else {}
user_prompt_content = user_prompt.get("content", "")
# Handle both string and dict inputs
if isinstance(user_prompt_content, str):
try:
inputs = json.loads(user_prompt_content)
if isinstance(inputs, dict) and "product_description" not in inputs:
# If it's a dict but doesn't have product_description, use the first value
if inputs:
inputs = {"product_description": list(inputs.values())[0]}
else:
inputs = {"product_description": ""}
elif not isinstance(inputs, dict):
inputs = {"product_description": inputs}
except json.JSONDecodeError:
inputs = {"product_description": user_prompt_content}
else:
inputs = {"product_description": str(user_prompt_content)}
# Print commands may need flush=True to ensure they are displayed in real-time.
print("Running marketing crew with inputs:", inputs, flush=True)
# Run the crew with the inputs
crew_output = self.crew().kickoff(inputs=inputs)
# Extract the response text from the crew output
response_text = str(crew_output.raw)
# Create a list of events from the event listener
events = self.event_listener.messages
if len(events) > 0:
last_message = events[-1].content
if last_message != response_text:
events.append(AIMessage(content=response_text))
else:
events = None
pipeline_interactions = self.create_pipeline_interactions_from_events(events)
usage_metrics = {
"completion_tokens": crew_output.token_usage.completion_tokens,
"prompt_tokens": crew_output.token_usage.prompt_tokens,
"total_tokens": crew_output.token_usage.total_tokens,
}
return response_text, pipeline_interactions, usage_metrics
@staticmethod
def create_pipeline_interactions_from_events(
events: list[Union[HumanMessage, AIMessage, ToolMessage]],
) -> MultiTurnSample | None:
"""Convert a list of events into a MultiTurnSample.
Creates the pipeline interactions for moderations and evaluation
(e.g. Task Adherence, Agent Goal Accuracy, Tool Call Accuracy)
"""
if not events:
return None
return MultiTurnSample(user_input=events)
Modify the model-metadata.yaml file¶
While this step isn't required to use this agent locally, it's important to modify the existing model-metadata.yaml file for use in an agentic playground or in production. The SERPER_API_KEY should be stored using credentials management in DataRobot.
| model-metadata.yaml | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 | |
Access request headers in your agent¶
When your agent is deployed and receives requests, you can access HTTP headers passed from the client. This is useful for authentication, tracking metadata, or implementing custom business logic based on request context.
Feature considerations
- Only headers prefixed with
X-Untrusted-*are passed through to your agent. - Headers are case-sensitive when accessing from the dictionary.
- Always check for
Noneor provide default values when accessing optional headers.
Headers with the X-Untrusted-* prefix are made available through the chat() function's **kwargs parameter in the custom.py file. Here's how to extract and use them:
from datarobot_genai.core.chat import initialize_authorization_context
def chat(
completion_create_params: CompletionCreateParams
| CompletionCreateParamsNonStreaming
| CompletionCreateParamsStreaming,
model: str,
**kwargs,
) -> Union[CustomModelChatResponse, Iterator[CustomModelStreamingResponse]]:
# Extract all headers from kwargs
headers = kwargs.get("headers", {})
# Access specific X-Untrusted-* headers
authorization_header = headers.get("X-Untrusted-Authorization")
request_id = headers.get("X-Untrusted-Request-ID")
# Use headers in your agent logic
if authorization_header:
# Pass to downstream services or tools
print(f"Processing request with auth: {authorization_header}")
# Continue with normal agent execution
initialize_authorization_context(completion_create_params, **kwargs)
agent = MyAgent(**completion_create_params)
# ...
Common use cases
- External authentication: Pass
X-Untrusted-Authorizationheaders to external APIs or tools. - Request tracking: Use
X-Untrusted-Request-IDfor logging and debugging. - Conditional logic: Adjust agent behavior based on
X-Untrusted-Region,X-Untrusted-User-Type, or other custom headers.
For more information, see the accessing request headers section in the troubleshooting guide.
Test the modified agentic workflow¶
After making all necessary modifications and additions to the agentic workflow custom model in the agent_crewai/custom_model directory, test the workflow with the following command.
task agent:cli START_DEV=1 -- execute --user_prompt "A revolutionary AI-powered fitness tracker that monitors your health"
Troubleshooting
If you encounter issues while testing an agentic workflow, it can be helpful to update agent environments and dependencies. To do this, use the task install (or task setup), task agent:install, and task agent:update commands. For more information on these commands and others, use the task command.
If you see a connection error when testing, ensure you're using START_DEV=1 in the command, or start the dev server separately with task agent:dev in a different terminal window.
Next steps¶
After successfully testing the updated agentic workflow for marketing copy generation, send the workflow to Workshop to connect it to an agentic playground or deploy the workflow.