Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/jules_agent_sdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class Session:
name: str = ""
id: str = ""
title: str = ""
automation_mode: Optional[str] = None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better type safety and maintainability, consider defining an Enum for automation_mode. This prevents typos and makes it clear what values are supported by the API. If AUTO_CREATE_PR is the only mode for now, you can start with that.

For example:

from enum import Enum

class AutomationMode(str, Enum):
    """Automation mode for a session."""
    AUTO_CREATE_PR = "AUTO_CREATE_PR"

# Then in the Session class:
...
    automation_mode: Optional[AutomationMode] = None
...

# In from_dict:
...
automation_mode_str = data.get("automationMode")
automation_mode = AutomationMode(automation_mode_str) if automation_mode_str else None
...

# In to_dict:
...
if self.automation_mode:
    result["automationMode"] = self.automation_mode.value
...

You would also need to update the sessions.create method signature to accept Optional[AutomationMode] and pass its value.

require_plan_approval: bool = False
create_time: str = ""
update_time: str = ""
Expand Down Expand Up @@ -228,6 +229,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "Session":
prompt=data.get("prompt", ""),
source_context=source_context,
title=data.get("title", ""),
automation_mode=data.get("automationMode"),
require_plan_approval=data.get("requirePlanApproval", False),
create_time=data.get("createTime", ""),
update_time=data.get("updateTime", ""),
Expand All @@ -246,6 +248,8 @@ def to_dict(self) -> Dict[str, Any]:
result["name"] = self.name
if self.title:
result["title"] = self.title
if self.automation_mode:
result["automationMode"] = self.automation_mode
if self.require_plan_approval:
result["requirePlanApproval"] = self.require_plan_approval
if self.outputs:
Expand Down
5 changes: 5 additions & 0 deletions src/jules_agent_sdk/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create(
starting_branch: Optional[str] = None,
title: Optional[str] = None,
require_plan_approval: bool = False,
automation_mode: Optional[str] = None,
) -> Session:
"""Create a new session.

Expand All @@ -39,6 +40,7 @@ def create(
starting_branch: Optional starting branch for GitHub repos
title: Optional session title
require_plan_approval: If True, plans require explicit approval
automation_mode: Optional automation mode (e.g., "AUTO_CREATE_PR")

Returns:
Created Session object
Expand Down Expand Up @@ -66,6 +68,9 @@ def create(
if require_plan_approval:
data["requirePlanApproval"] = require_plan_approval

if automation_mode:
data["automationMode"] = automation_mode

response = self.client.post("sessions", json=data)
return Session.from_dict(response)

Expand Down
28 changes: 28 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ def test_sessions_create(self, mock_request):
assert session.prompt == "Fix bug"
mock_request.assert_called_once()

@patch("jules_agent_sdk.base.BaseClient._request")
def test_sessions_create_with_automation_mode(self, mock_request):
"""Test session creation with automation mode."""
mock_request.return_value = {
"name": "sessions/test456",
"id": "test456",
"prompt": "Auto PR feature",
"sourceContext": {"source": "sources/repo2"},
"state": "QUEUED",
"automationMode": "AUTO_CREATE_PR",
}

client = JulesClient(api_key="test-api-key")
session = client.sessions.create(
prompt="Auto PR feature",
source="sources/repo2",
automation_mode="AUTO_CREATE_PR",
)

assert session.id == "test456"
assert session.automation_mode == "AUTO_CREATE_PR"

# Verify that automationMode was included in the request data
mock_request.assert_called_once()
_name, _args, kwargs = mock_request.mock_calls[0]
assert "json" in kwargs
assert kwargs["json"]["automationMode"] == "AUTO_CREATE_PR"

@patch("jules_agent_sdk.base.BaseClient._request")
def test_sessions_get(self, mock_request):
"""Test getting a session."""
Expand Down