Skip to content
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
5 changes: 5 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ agent_app_name:
{% elif not agent_app_name.isidentifier() %}ERROR: Agent app name must be a valid Python identifier (letters, numbers, underscores only, cannot start with number)
{% endif %}
agent_development_port:
type: int
default: 8842
validator: "{% if agent_development_port < 1 or agent_development_port > 65536%}Must be in the range 1-65536{% endif %}"

use_low_code_interface:
type: bool
help: "Do you want to use low-code yaml configuration interface for your agent?"
Expand Down
2 changes: 1 addition & 1 deletion template/.datarobot/cli/{{agent_app_name}}.yaml.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root:
- env: {{agent_app_name|upper}}_ENDPOINT
type: string
default: "http://localhost:8842"
default: "http://localhost:{{ agent_development_port }}"
optional: true
help: "The local endpoint to access the agent. Should have a unique port."
- env: DATAROBOT_DEFAULT_EXECUTION_ENVIRONMENT
Expand Down
6 changes: 3 additions & 3 deletions template/{{agent_app_name}}/Taskfile.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ tasks:

# Wait for server to be ready
echo "⏳ Waiting for dev server to be ready..."
AGENT_ENDPOINT="http://localhost:8842"
_{{ agent_app_name | upper }}_ENDPOINT="http://localhost:{{ agent_development_port }}"
if [ -n "${{ agent_app_name | upper }}_ENDPOINT" ]; then
AGENT_ENDPOINT="${{ agent_app_name | upper }}_ENDPOINT"
_{{ agent_app_name | upper }}_ENDPOINT="${{ agent_app_name | upper }}_ENDPOINT"
fi
i=0
while [ $i -lt 30 ]; do
if curl --silent --fail --max-time 2 "$AGENT_ENDPOINT/" >/dev/null 2>&1; then
if curl --silent --fail --max-time 2 "$_{{ agent_app_name | upper }}_ENDPOINT/" >/dev/null 2>&1; then
echo "✅ Dev server is ready!"
break
fi
Expand Down
2 changes: 1 addition & 1 deletion template/{{agent_app_name}}/custom_model/config.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Config(DataRobotAppFrameworkBaseSettings):
external_mcp_url: str | None = None

agent_endpoint: str = Field(
default="http://localhost:8842", validation_alias="{{agent_app_name|upper}}_ENDPOINT"
default="http://localhost:{{ agent_development_port }}", validation_alias="{{agent_app_name|upper}}_ENDPOINT"
)

@property
Expand Down
4 changes: 2 additions & 2 deletions template/{{agent_app_name}}/lit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
client = AsyncOpenAI(base_url=config.agent_endpoint, api_key="empty")


@cl.on_chat_start # type: ignore[misc]
@cl.on_chat_start # type: ignore[untyped-decorator]
def start_chat() -> None:
cl.user_session.set(
"message_history",
[],
)


@cl.on_message # type: ignore[misc]
@cl.on_message # type: ignore[untyped-decorator]
async def on_message(message: cl.Message) -> None:
message_history = cl.user_session.get("message_history")
message_history.append({"role": "user", "content": message.content})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class TestMyAgentMCPIntegration:
assert len(writer.tools) == 1 # 1 MCP tool
assert len(editor.tools) == 1 # 1 MCP tool

@patch("datarobot_genai.crewai.base.mcp_tools_context")
@patch("datarobot_genai.crewai.base.mcp_tools_context", autospec=True)
def test_agent_works_without_mcp_tools(
self, mock_mcp_tools_context, crewai_common_mocks
):
Expand Down Expand Up @@ -232,7 +232,7 @@ class TestMyAgentMCPIntegration:

assert access_count["count"] >= 3

@patch("datarobot_genai.crewai.base.mcp_tools_context")
@patch("datarobot_genai.crewai.base.mcp_tools_context", autospec=True)
def test_mcp_tool_execution_makes_request_to_server(
self, mock_mcp_tools_context, crewai_common_mocks
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def langgraph_common_mocks():
mock_execution_graph.astream.side_effect = _create_mock_astream()

with (
patch("datarobot_genai.langgraph.agent.mcp_tools_context") as mock_mcp_context,
patch(
"datarobot_genai.langgraph.agent.mcp_tools_context",
autospec=True,
) as mock_mcp_context,
patch.object(
MyAgent,
"workflow",
Expand Down Expand Up @@ -120,7 +123,8 @@ class TestMyAgentLangGraphMCPIntegration:
except (StopIteration, AttributeError, TypeError, ValueError):
pass

mock_context.assert_called_once_with(authorization_context={})
mock_context.assert_called_once()
assert mock_context.call_args.kwargs.get("authorization_context") == {}
assert agent.mcp_tools == mock_tools

def test_agent_loads_mcp_tools_from_datarobot_deployment_in_invoke(
Expand Down Expand Up @@ -155,7 +159,8 @@ class TestMyAgentLangGraphMCPIntegration:
except (StopIteration, AttributeError, TypeError, ValueError):
pass

mock_context.assert_called_once_with(authorization_context={})
mock_context.assert_called_once()
assert mock_context.call_args.kwargs.get("authorization_context") == {}
assert agent.mcp_tools == mock_tools

def test_agent_works_without_mcp_tools(self, langgraph_common_mocks):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ class TestMyAgentMCPIntegration:
# Expected when workflow is mocked
pass

# Verify load_mcp_tools was called with correct parameters
mock_load_mcp_tools.assert_called_once_with(authorization_context={})
# Verify load_mcp_tools was called and provided authorization_context
mock_load_mcp_tools.assert_called_once()
assert (
mock_load_mcp_tools.call_args.kwargs.get("authorization_context") == {}
)

# Verify set_mcp_tools was called with the tools from MCP server
assert agent.mcp_tools == mock_tools
Expand Down Expand Up @@ -164,8 +167,11 @@ class TestMyAgentMCPIntegration:
# Expected when workflow is mocked
pass

# Verify load_mcp_tools was called with correct parameters
mock_load_mcp_tools.assert_called_once_with(authorization_context={})
# Verify load_mcp_tools was called and provided authorization_context
mock_load_mcp_tools.assert_called_once()
assert (
mock_load_mcp_tools.call_args.kwargs.get("authorization_context") == {}
)

# Verify set_mcp_tools was called with the tools from MCP server
assert agent.mcp_tools == mock_tools
Expand Down
Loading