From 55c9b487a39edf0ad6f8a51d0d4e4aac08cea6d6 Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 17 Dec 2025 10:00:46 -0700 Subject: [PATCH 1/4] updating create endpoint with new params --- dimo/api/conversations.py | 52 ++++++++----- tests/test_conversations.py | 148 ++++++++++++++++++++++++++---------- 2 files changed, 141 insertions(+), 59 deletions(-) diff --git a/dimo/api/conversations.py b/dimo/api/conversations.py index 1f0ec59..8212d6f 100644 --- a/dimo/api/conversations.py +++ b/dimo/api/conversations.py @@ -44,25 +44,32 @@ def health_check(self) -> Dict: def create_agent( self, developer_jwt: str, - user: str, - vehicle_ids: Optional[List[int]] = None, + agent_type: str, + variables: Dict[str, str], + secrets: Optional[Dict[str, str]] = None, + personality: Optional[str] = None, ) -> Dict: """ - Create a new conversational agent for a user with optional vehicle access. + Create a new conversational agent with the specified configuration. Args: developer_jwt (str): Developer JWT token for authentication - user (str): Wallet address (0x...) or email identifying the user - vehicle_ids (list[int], optional): List of vehicle token IDs this agent can access. - - None (default): Unrestricted access, ownership validated at runtime - - []: Empty list means no vehicle access (identity queries only) - - [872, 1234]: Explicit list of allowed vehicles + agent_type (str): The type of agent to create (e.g., "driver_agent_v1") + variables (dict[str, str]): Configuration variables for the agent. + Common variables include: + - "USER_WALLET": User's wallet address (e.g., "0x86b04f6d...") + - "VEHICLE_IDS": JSON array of vehicle token IDs (e.g., "[1, 2, 3]") + secrets (dict[str, str], optional): Sensitive data for the agent. + Common secrets include: + - "VEHICLE_JWT": JWT token for vehicle access + personality (str, optional): Personality preset for the agent + (e.g., "uncle_mechanic") Returns: - dict: Agent information including agentId, mode, user, vehicleIds, and createdAt + dict: Agent information including agentId and configuration details Behavior: - - One agent per user (idempotent creation) + - Creates a new agent with the specified type and configuration - Validates configuration and mode detection - Creates/reuses shared identity subagent - Creates per-vehicle telemetry subagents with token exchange @@ -73,21 +80,30 @@ def create_agent( >>> dev_jwt = "your_developer_jwt" >>> agent = dimo.conversations.create_agent( ... developer_jwt=dev_jwt, - ... user="0x1234567890abcdef1234567890abcdef12345678", - ... vehicle_ids=[872, 1234], + ... agent_type="driver_agent_v1", + ... variables={ + ... "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + ... "VEHICLE_IDS": "[1, 2, 3]" + ... }, + ... secrets={"VEHICLE_JWT": "eyJ..."}, + ... personality="uncle_mechanic", ... ) >>> print(agent['agentId']) """ check_type("developer_jwt", developer_jwt, str) - check_type("user", user, str) - check_optional_type("vehicle_ids", vehicle_ids, list) - # check_type("enable_websearch", enable_websearch, bool) + check_type("agent_type", agent_type, str) + check_type("variables", variables, dict) + check_optional_type("secrets", secrets, dict) + check_optional_type("personality", personality, str) body = { - "user": user, - "vehicleIds": vehicle_ids, - # "enableWebsearch": enable_websearch, + "type": agent_type, + "variables": variables, } + if secrets is not None: + body["secrets"] = secrets + if personality is not None: + body["personality"] = personality response = self._request( "POST", diff --git a/tests/test_conversations.py b/tests/test_conversations.py index 186a42c..63cdad4 100644 --- a/tests/test_conversations.py +++ b/tests/test_conversations.py @@ -47,25 +47,28 @@ class TestConversationsCreateAgent: """Test the create_agent endpoint.""" def test_create_agent_minimal(self, monkeypatch): - """Test creating an agent with minimal parameters.""" + """Test creating an agent with minimal required parameters.""" client = DIMO(env="Dev") # Mock the request method fake_request = MagicMock(return_value={ "agentId": "agent-abc123", - "user": "0x1234567890abcdef1234567890abcdef12345678", - "vehicleIds": None, - "mode": "unrestricted", + "type": "driver_agent_v1", "createdAt": "2024-01-01T00:00:00Z" }) monkeypatch.setattr(client, "request", fake_request) dev_jwt = "test_developer_jwt" - user = "0x1234567890abcdef1234567890abcdef12345678" + agent_type = "driver_agent_v1" + variables = { + "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + "VEHICLE_IDS": "[1, 2, 3]" + } result = client.conversations.create_agent( developer_jwt=dev_jwt, - user=user + agent_type=agent_type, + variables=variables ) # Verify the request was called correctly @@ -75,91 +78,150 @@ def test_create_agent_minimal(self, monkeypatch): assert args[0] == "POST" assert args[1] == "Conversations" assert args[2] == "/agents" - assert kwargs["data"]["user"] == user - assert kwargs["data"]["vehicleIds"] is None + assert kwargs["data"]["type"] == agent_type + assert kwargs["data"]["variables"] == variables + assert "secrets" not in kwargs["data"] + assert "personality" not in kwargs["data"] # Verify the response assert result["agentId"] == "agent-abc123" - assert result["user"] == user - assert result["mode"] == "unrestricted" + assert result["type"] == agent_type - def test_create_agent_with_vehicle_ids(self, monkeypatch): - """Test creating an agent with specific vehicle IDs.""" + def test_create_agent_with_secrets(self, monkeypatch): + """Test creating an agent with secrets.""" client = DIMO(env="Dev") fake_request = MagicMock(return_value={ "agentId": "agent-def456", - "user": "user@example.com", - "vehicleIds": [872, 1234], - "mode": "restricted", + "type": "driver_agent_v1", "createdAt": "2024-01-01T00:00:00Z" }) monkeypatch.setattr(client, "request", fake_request) dev_jwt = "test_developer_jwt" - user = "user@example.com" - vehicle_ids = [872, 1234] + agent_type = "driver_agent_v1" + variables = {"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[872, 1234]"} + secrets = {"VEHICLE_JWT": "eyJhbGciOiJIUzI1NiJ9..."} result = client.conversations.create_agent( developer_jwt=dev_jwt, - user=user, - vehicle_ids=vehicle_ids + agent_type=agent_type, + variables=variables, + secrets=secrets ) # Verify the request args, kwargs = fake_request.call_args - assert kwargs["data"]["vehicleIds"] == [872, 1234] + assert kwargs["data"]["type"] == agent_type + assert kwargs["data"]["variables"] == variables + assert kwargs["data"]["secrets"] == secrets # Verify the response - assert result["vehicleIds"] == vehicle_ids - assert result["mode"] == "restricted" + assert result["agentId"] == "agent-def456" - def test_create_agent_with_empty_vehicle_list(self, monkeypatch): - """Test creating an agent with empty vehicle list (identity only).""" + def test_create_agent_with_personality(self, monkeypatch): + """Test creating an agent with personality preset.""" client = DIMO(env="Dev") fake_request = MagicMock(return_value={ "agentId": "agent-ghi789", - "user": "0xabcdef", - "vehicleIds": [], - "mode": "identity_only", + "type": "driver_agent_v1", + "personality": "uncle_mechanic", "createdAt": "2024-01-01T00:00:00Z" }) monkeypatch.setattr(client, "request", fake_request) result = client.conversations.create_agent( developer_jwt="test_jwt", - user="0xabcdef", - vehicle_ids=[] + agent_type="driver_agent_v1", + variables={"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[]"}, + personality="uncle_mechanic" ) - assert result["vehicleIds"] == [] - assert result["mode"] == "identity_only" + # Verify the request + args, kwargs = fake_request.call_args + assert kwargs["data"]["personality"] == "uncle_mechanic" + + # Verify the response + assert result["personality"] == "uncle_mechanic" + + def test_create_agent_full_config(self, monkeypatch): + """Test creating an agent with all configuration options.""" + client = DIMO(env="Dev") + + fake_request = MagicMock(return_value={ + "agentId": "agent-full123", + "type": "driver_agent_v1", + "personality": "uncle_mechanic", + "createdAt": "2024-01-01T00:00:00Z" + }) + monkeypatch.setattr(client, "request", fake_request) + + result = client.conversations.create_agent( + developer_jwt="test_jwt", + agent_type="driver_agent_v1", + variables={ + "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + "VEHICLE_IDS": "[1, 2, 3]" + }, + secrets={"VEHICLE_JWT": "eyJ..."}, + personality="uncle_mechanic" + ) + + # Verify all fields are in request + args, kwargs = fake_request.call_args + assert kwargs["data"]["type"] == "driver_agent_v1" + assert kwargs["data"]["variables"]["USER_WALLET"] == "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605" + assert kwargs["data"]["variables"]["VEHICLE_IDS"] == "[1, 2, 3]" + assert kwargs["data"]["secrets"]["VEHICLE_JWT"] == "eyJ..." + assert kwargs["data"]["personality"] == "uncle_mechanic" def test_create_agent_invalid_types(self): """Test that type checking is enforced for parameters.""" client = DIMO(env="Dev") + valid_variables = {"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[]"} + # Test invalid developer_jwt type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt=123, # Should be string - user="0xabcdef" + agent_type="driver_agent_v1", + variables=valid_variables + ) + + # Test invalid agent_type type + with pytest.raises(DimoTypeError): + client.conversations.create_agent( + developer_jwt="test_jwt", + agent_type=123, # Should be string + variables=valid_variables + ) + + # Test invalid variables type + with pytest.raises(DimoTypeError): + client.conversations.create_agent( + developer_jwt="test_jwt", + agent_type="driver_agent_v1", + variables="not_a_dict" # Should be dict ) - # Test invalid user type + # Test invalid secrets type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - user=123 # Should be string + agent_type="driver_agent_v1", + variables=valid_variables, + secrets="not_a_dict" # Should be dict or None ) - # Test invalid vehicle_ids type + # Test invalid personality type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - user="0xabcdef", - vehicle_ids="not_a_list" # Should be list or None + agent_type="driver_agent_v1", + variables=valid_variables, + personality=123 # Should be string or None ) @@ -573,8 +635,7 @@ def fake_request(*args, **kwargs): if args[0] == "POST" and args[2] == "/agents": return { "agentId": "agent-test123", - "user": "0xuser", - "vehicleIds": [872], + "type": "driver_agent_v1", "createdAt": "2024-01-01T00:00:00Z" } elif args[0] == "POST" and "/message" in args[2]: @@ -592,8 +653,13 @@ def fake_request(*args, **kwargs): # 1. Create agent agent = client.conversations.create_agent( developer_jwt="test_jwt", - user="0xuser", - vehicle_ids=[872] + agent_type="driver_agent_v1", + variables={ + "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + "VEHICLE_IDS": "[872]" + }, + secrets={"VEHICLE_JWT": "eyJ..."}, + personality="uncle_mechanic" ) assert agent["agentId"] == "agent-test123" assert ("POST", "/agents") in calls_made From 4b53b6997288725b670175dcb0779ffc529d66e1 Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 17 Dec 2025 10:01:17 -0700 Subject: [PATCH 2/4] update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 756107d..74c22d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "dimo-python-sdk" -version = "1.7.0" +version = "1.7.1" authors = [ { name="Barrett Kowalsky", email="barrettkowalsky@gmail.com" }, ] From d4ba0d335e869607194be71f6ebd908fb4e80f7e Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 17 Dec 2025 11:00:57 -0700 Subject: [PATCH 3/4] swap api key, build body, set optional vehicle ids --- dimo/api/conversations.py | 52 ++++++++-------- tests/test_conversations.py | 118 +++++++++++++++++------------------- 2 files changed, 80 insertions(+), 90 deletions(-) diff --git a/dimo/api/conversations.py b/dimo/api/conversations.py index 8212d6f..c864a9c 100644 --- a/dimo/api/conversations.py +++ b/dimo/api/conversations.py @@ -44,26 +44,23 @@ def health_check(self) -> Dict: def create_agent( self, developer_jwt: str, + api_key: str, + user_wallet: str, agent_type: str, - variables: Dict[str, str], - secrets: Optional[Dict[str, str]] = None, - personality: Optional[str] = None, + vehicle_ids: Optional[str] = None, + personality: str = "uncle_mechanic", ) -> Dict: """ Create a new conversational agent with the specified configuration. Args: developer_jwt (str): Developer JWT token for authentication - agent_type (str): The type of agent to create (e.g., "driver_agent_v1") - variables (dict[str, str]): Configuration variables for the agent. - Common variables include: - - "USER_WALLET": User's wallet address (e.g., "0x86b04f6d...") - - "VEHICLE_IDS": JSON array of vehicle token IDs (e.g., "[1, 2, 3]") - secrets (dict[str, str], optional): Sensitive data for the agent. - Common secrets include: - - "VEHICLE_JWT": JWT token for vehicle access - personality (str, optional): Personality preset for the agent - (e.g., "uncle_mechanic") + api_key (str): DIMO API key for the agent to access vehicle data + user_wallet (str): User's wallet address (e.g., "0x2345...") + vehicle_ids (str, optional): JSON array string of vehicle token IDs (e.g., "[1, 2, 3]"). + If not provided, agent will have access to all vehicles owned by the user. + agent_type (str, optional): The type of agent to create. Defaults to "driver_agent_v1" + personality (str, optional): Personality preset for the agent. Defaults to "uncle_mechanic" Returns: dict: Agent information including agentId and configuration details @@ -80,30 +77,31 @@ def create_agent( >>> dev_jwt = "your_developer_jwt" >>> agent = dimo.conversations.create_agent( ... developer_jwt=dev_jwt, - ... agent_type="driver_agent_v1", - ... variables={ - ... "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", - ... "VEHICLE_IDS": "[1, 2, 3]" - ... }, - ... secrets={"VEHICLE_JWT": "eyJ..."}, - ... personality="uncle_mechanic", + ... api_key="0x1234567890abcdef...", + ... user_wallet="0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + ... vehicle_ids="[1, 2, 3]", ... ) >>> print(agent['agentId']) """ check_type("developer_jwt", developer_jwt, str) + check_type("api_key", api_key, str) + check_type("user_wallet", user_wallet, str) + check_optional_type("vehicle_ids", vehicle_ids, str) check_type("agent_type", agent_type, str) - check_type("variables", variables, dict) - check_optional_type("secrets", secrets, dict) - check_optional_type("personality", personality, str) + check_type("personality", personality, str) + # Build variables dict + variables = {"USER_WALLET": user_wallet} + if vehicle_ids is not None: + variables["VEHICLE_IDS"] = vehicle_ids + + # Build request body body = { + "personality": personality, + "secrets": {"DIMO_API_KEY": api_key}, "type": agent_type, "variables": variables, } - if secrets is not None: - body["secrets"] = secrets - if personality is not None: - body["personality"] = personality response = self._request( "POST", diff --git a/tests/test_conversations.py b/tests/test_conversations.py index 63cdad4..4d0dc07 100644 --- a/tests/test_conversations.py +++ b/tests/test_conversations.py @@ -47,28 +47,26 @@ class TestConversationsCreateAgent: """Test the create_agent endpoint.""" def test_create_agent_minimal(self, monkeypatch): - """Test creating an agent with minimal required parameters.""" + """Test creating an agent with minimal required parameters (no vehicle_ids).""" client = DIMO(env="Dev") # Mock the request method fake_request = MagicMock(return_value={ "agentId": "agent-abc123", "type": "driver_agent_v1", + "personality": "uncle_mechanic", "createdAt": "2024-01-01T00:00:00Z" }) monkeypatch.setattr(client, "request", fake_request) dev_jwt = "test_developer_jwt" - agent_type = "driver_agent_v1" - variables = { - "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", - "VEHICLE_IDS": "[1, 2, 3]" - } + api_key = "0x1234567890abcdef" + user_wallet = "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605" result = client.conversations.create_agent( developer_jwt=dev_jwt, - agent_type=agent_type, - variables=variables + api_key=api_key, + user_wallet=user_wallet ) # Verify the request was called correctly @@ -78,17 +76,18 @@ def test_create_agent_minimal(self, monkeypatch): assert args[0] == "POST" assert args[1] == "Conversations" assert args[2] == "/agents" - assert kwargs["data"]["type"] == agent_type - assert kwargs["data"]["variables"] == variables - assert "secrets" not in kwargs["data"] - assert "personality" not in kwargs["data"] + assert kwargs["data"]["type"] == "driver_agent_v1" + assert kwargs["data"]["personality"] == "uncle_mechanic" + assert kwargs["data"]["secrets"]["DIMO_API_KEY"] == api_key + assert kwargs["data"]["variables"]["USER_WALLET"] == user_wallet + assert "VEHICLE_IDS" not in kwargs["data"]["variables"] # Verify the response assert result["agentId"] == "agent-abc123" - assert result["type"] == agent_type + assert result["type"] == "driver_agent_v1" - def test_create_agent_with_secrets(self, monkeypatch): - """Test creating an agent with secrets.""" + def test_create_agent_with_vehicle_ids(self, monkeypatch): + """Test creating an agent with specific vehicle IDs.""" client = DIMO(env="Dev") fake_request = MagicMock(return_value={ @@ -99,51 +98,51 @@ def test_create_agent_with_secrets(self, monkeypatch): monkeypatch.setattr(client, "request", fake_request) dev_jwt = "test_developer_jwt" - agent_type = "driver_agent_v1" - variables = {"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[872, 1234]"} - secrets = {"VEHICLE_JWT": "eyJhbGciOiJIUzI1NiJ9..."} + api_key = "0xabcdef123456" + user_wallet = "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605" + vehicle_ids = "[872, 1234]" result = client.conversations.create_agent( developer_jwt=dev_jwt, - agent_type=agent_type, - variables=variables, - secrets=secrets + api_key=api_key, + user_wallet=user_wallet, + vehicle_ids=vehicle_ids ) # Verify the request args, kwargs = fake_request.call_args - assert kwargs["data"]["type"] == agent_type - assert kwargs["data"]["variables"] == variables - assert kwargs["data"]["secrets"] == secrets + assert kwargs["data"]["secrets"]["DIMO_API_KEY"] == api_key + assert kwargs["data"]["variables"]["USER_WALLET"] == user_wallet + assert kwargs["data"]["variables"]["VEHICLE_IDS"] == vehicle_ids # Verify the response assert result["agentId"] == "agent-def456" - def test_create_agent_with_personality(self, monkeypatch): - """Test creating an agent with personality preset.""" + def test_create_agent_with_custom_personality(self, monkeypatch): + """Test creating an agent with custom personality preset.""" client = DIMO(env="Dev") fake_request = MagicMock(return_value={ "agentId": "agent-ghi789", "type": "driver_agent_v1", - "personality": "uncle_mechanic", + "personality": "helpful_assistant", "createdAt": "2024-01-01T00:00:00Z" }) monkeypatch.setattr(client, "request", fake_request) result = client.conversations.create_agent( developer_jwt="test_jwt", - agent_type="driver_agent_v1", - variables={"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[]"}, - personality="uncle_mechanic" + api_key="0xapikey", + user_wallet="0xwallet", + personality="helpful_assistant" ) # Verify the request args, kwargs = fake_request.call_args - assert kwargs["data"]["personality"] == "uncle_mechanic" + assert kwargs["data"]["personality"] == "helpful_assistant" # Verify the response - assert result["personality"] == "uncle_mechanic" + assert result["personality"] == "helpful_assistant" def test_create_agent_full_config(self, monkeypatch): """Test creating an agent with all configuration options.""" @@ -159,69 +158,65 @@ def test_create_agent_full_config(self, monkeypatch): result = client.conversations.create_agent( developer_jwt="test_jwt", + api_key="0x1234567890abcdef", + user_wallet="0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + vehicle_ids="[1, 2, 3]", agent_type="driver_agent_v1", - variables={ - "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", - "VEHICLE_IDS": "[1, 2, 3]" - }, - secrets={"VEHICLE_JWT": "eyJ..."}, personality="uncle_mechanic" ) # Verify all fields are in request args, kwargs = fake_request.call_args assert kwargs["data"]["type"] == "driver_agent_v1" + assert kwargs["data"]["personality"] == "uncle_mechanic" + assert kwargs["data"]["secrets"]["DIMO_API_KEY"] == "0x1234567890abcdef" assert kwargs["data"]["variables"]["USER_WALLET"] == "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605" assert kwargs["data"]["variables"]["VEHICLE_IDS"] == "[1, 2, 3]" - assert kwargs["data"]["secrets"]["VEHICLE_JWT"] == "eyJ..." - assert kwargs["data"]["personality"] == "uncle_mechanic" def test_create_agent_invalid_types(self): """Test that type checking is enforced for parameters.""" client = DIMO(env="Dev") - valid_variables = {"USER_WALLET": "0xabcdef", "VEHICLE_IDS": "[]"} - # Test invalid developer_jwt type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt=123, # Should be string - agent_type="driver_agent_v1", - variables=valid_variables + api_key="0xapikey", + user_wallet="0xwallet" ) - # Test invalid agent_type type + # Test invalid api_key type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - agent_type=123, # Should be string - variables=valid_variables + api_key=123, # Should be string + user_wallet="0xwallet" ) - # Test invalid variables type + # Test invalid user_wallet type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - agent_type="driver_agent_v1", - variables="not_a_dict" # Should be dict + api_key="0xapikey", + user_wallet=123 # Should be string ) - # Test invalid secrets type + # Test invalid vehicle_ids type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - agent_type="driver_agent_v1", - variables=valid_variables, - secrets="not_a_dict" # Should be dict or None + api_key="0xapikey", + user_wallet="0xwallet", + vehicle_ids=123 # Should be string or None ) # Test invalid personality type with pytest.raises(DimoTypeError): client.conversations.create_agent( developer_jwt="test_jwt", - agent_type="driver_agent_v1", - variables=valid_variables, - personality=123 # Should be string or None + api_key="0xapikey", + user_wallet="0xwallet", + personality=123 # Should be string ) @@ -636,6 +631,7 @@ def fake_request(*args, **kwargs): return { "agentId": "agent-test123", "type": "driver_agent_v1", + "personality": "uncle_mechanic", "createdAt": "2024-01-01T00:00:00Z" } elif args[0] == "POST" and "/message" in args[2]: @@ -653,13 +649,9 @@ def fake_request(*args, **kwargs): # 1. Create agent agent = client.conversations.create_agent( developer_jwt="test_jwt", - agent_type="driver_agent_v1", - variables={ - "USER_WALLET": "0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", - "VEHICLE_IDS": "[872]" - }, - secrets={"VEHICLE_JWT": "eyJ..."}, - personality="uncle_mechanic" + api_key="0x1234567890abcdef", + user_wallet="0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + vehicle_ids="[872]" ) assert agent["agentId"] == "agent-test123" assert ("POST", "/agents") in calls_made From ec14ef13e31ac50fea90823ecebab6bcdb0df49a Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 17 Dec 2025 11:17:07 -0700 Subject: [PATCH 4/4] fix required agent_type, update readme --- README.md | 24 +++++++++++++++++++++++- dimo/api/conversations.py | 3 ++- tests/test_conversations.py | 26 ++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f8235d9..48cbdc5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,29 @@ pip install dimo-python-sdk ## Unit Testing -Coming Soon +The SDK includes comprehensive unit tests to ensure reliability and correctness. To run the tests: + +1. **Install dependencies:** + ```bash + pip install -r requirements.txt + ``` + +2. **Run all tests:** + ```bash + pytest + ``` + +3. **Run tests with verbose output:** + ```bash + pytest -v + ``` + +4. **Run specific test files:** + ```bash + pytest tests/test_conversations.py -v + ``` + +The test suite uses `pytest` and includes tests for all major SDK functionality including authentication, API endpoints, GraphQL queries, and error handling ## API Documentation diff --git a/dimo/api/conversations.py b/dimo/api/conversations.py index c864a9c..66fef6f 100644 --- a/dimo/api/conversations.py +++ b/dimo/api/conversations.py @@ -57,9 +57,9 @@ def create_agent( developer_jwt (str): Developer JWT token for authentication api_key (str): DIMO API key for the agent to access vehicle data user_wallet (str): User's wallet address (e.g., "0x2345...") + agent_type (str): The type of agent to create (e.g., "driver_agent_v1") vehicle_ids (str, optional): JSON array string of vehicle token IDs (e.g., "[1, 2, 3]"). If not provided, agent will have access to all vehicles owned by the user. - agent_type (str, optional): The type of agent to create. Defaults to "driver_agent_v1" personality (str, optional): Personality preset for the agent. Defaults to "uncle_mechanic" Returns: @@ -79,6 +79,7 @@ def create_agent( ... developer_jwt=dev_jwt, ... api_key="0x1234567890abcdef...", ... user_wallet="0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + ... agent_type="driver_agent_v1", ... vehicle_ids="[1, 2, 3]", ... ) >>> print(agent['agentId']) diff --git a/tests/test_conversations.py b/tests/test_conversations.py index 4d0dc07..0cafc31 100644 --- a/tests/test_conversations.py +++ b/tests/test_conversations.py @@ -66,7 +66,8 @@ def test_create_agent_minimal(self, monkeypatch): result = client.conversations.create_agent( developer_jwt=dev_jwt, api_key=api_key, - user_wallet=user_wallet + user_wallet=user_wallet, + agent_type="driver_agent_v1" ) # Verify the request was called correctly @@ -106,6 +107,7 @@ def test_create_agent_with_vehicle_ids(self, monkeypatch): developer_jwt=dev_jwt, api_key=api_key, user_wallet=user_wallet, + agent_type="driver_agent_v1", vehicle_ids=vehicle_ids ) @@ -134,6 +136,7 @@ def test_create_agent_with_custom_personality(self, monkeypatch): developer_jwt="test_jwt", api_key="0xapikey", user_wallet="0xwallet", + agent_type="driver_agent_v1", personality="helpful_assistant" ) @@ -182,7 +185,8 @@ def test_create_agent_invalid_types(self): client.conversations.create_agent( developer_jwt=123, # Should be string api_key="0xapikey", - user_wallet="0xwallet" + user_wallet="0xwallet", + agent_type="driver_agent_v1" ) # Test invalid api_key type @@ -190,7 +194,8 @@ def test_create_agent_invalid_types(self): client.conversations.create_agent( developer_jwt="test_jwt", api_key=123, # Should be string - user_wallet="0xwallet" + user_wallet="0xwallet", + agent_type="driver_agent_v1" ) # Test invalid user_wallet type @@ -198,7 +203,17 @@ def test_create_agent_invalid_types(self): client.conversations.create_agent( developer_jwt="test_jwt", api_key="0xapikey", - user_wallet=123 # Should be string + user_wallet=123, # Should be string + agent_type="driver_agent_v1" + ) + + # Test invalid agent_type type + with pytest.raises(DimoTypeError): + client.conversations.create_agent( + developer_jwt="test_jwt", + api_key="0xapikey", + user_wallet="0xwallet", + agent_type=123 # Should be string ) # Test invalid vehicle_ids type @@ -207,6 +222,7 @@ def test_create_agent_invalid_types(self): developer_jwt="test_jwt", api_key="0xapikey", user_wallet="0xwallet", + agent_type="driver_agent_v1", vehicle_ids=123 # Should be string or None ) @@ -216,6 +232,7 @@ def test_create_agent_invalid_types(self): developer_jwt="test_jwt", api_key="0xapikey", user_wallet="0xwallet", + agent_type="driver_agent_v1", personality=123 # Should be string ) @@ -651,6 +668,7 @@ def fake_request(*args, **kwargs): developer_jwt="test_jwt", api_key="0x1234567890abcdef", user_wallet="0x86b04f6d1D9E79aD7eB31cDEAF37442B00d64605", + agent_type="driver_agent_v1", vehicle_ids="[872]" ) assert agent["agentId"] == "agent-test123"