How can I inject sensitive runtime parameters like a user ID directly into my custom tool calls—so the model never has to know or reveal them — also, without rebuilding or reconfiguring the agent for every single request?
I looked at other posts but they either seem closed or outdated.
Thanks ahead of time!
# crewai==0.134.0
import os
from pydantic import BaseModel, Field
from crewai import Agent, Crew, Task, Process
from crewai.tools import BaseTool
# ── 1. A super-simple DB lookup tool
class _Input(BaseModel):
user_id: str = Field(..., description="INTERNAL user id – must stay private")
class AddressLookupTool(BaseTool):
name = "Address Lookup Tool"
description = "Returns the shipping address that matches user_id"
args_schema = _Input
def _run(self, user_id: str) -> str: #
# obviously stubbed:
return f"[dummy address for {user_id}]"
lookup_tool = AddressLookupTool(result_as_answer=True)
# ── 2. Agent that owns the tool
db_agent = Agent(
role="DB specialist",
goal="Fetch private customer data without leaking PII",
backstory="Knows how to query the CRM directly.",
tools=[lookup_tool],
llm="gpt-4o-mini",
allow_delegation=False,
)
# ── 3. Task that should inject the hidden param
address_task = Task(
description="Retrieve the customer’s shipping address.",
expected_output="Just the street address – no other data.",
agent=db_agent,
tools=[lookup_tool],
)
# ── 4. Crew & kickoff
crew = Crew(
agents=[db_agent],
tasks=[address_task],
process=Process.sequential,
verbose=True,
)
result = crew.kickoff(inputs={"user_id": "u-8732adf"})
print("FINAL RESULT:", result.raw)