Skip to content

CG-17302: Add job_url property to Agent class #1036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions src/codegen/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
# Current job
self.current_job = None

@property
def web_url(self) -> Optional[str]:
"""Get the URL for the current job.

Returns:
str: The web URL for the current job, or None if no job has been run.
"""
if self.current_job:
return self.current_job.web_url
return None

def run(self, prompt: str) -> AgentTask:
"""Run an agent with the given prompt.

Expand All @@ -78,7 +89,7 @@
# Convert API response to dict for Job initialization

job = AgentTask(agent_run_response, self.api_client, self.org_id)
self.current_job = job

Check failure on line 92 in src/codegen/agents/agent.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "AgentTask", variable has type "None") [assignment]
return job

def get_status(self) -> Optional[dict[str, Any]]:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/codegen/agents/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ def test_init_with_custom_base_url(self, mock_api_client):
agent = Agent(token="test-token", org_id=42, base_url=custom_url)
mock_config.assert_called_once_with(host=custom_url, access_token="test-token")

def test_web_url_with_no_job(self, agent):
"""Test web_url property when no job has been run"""
assert agent.web_url is None

def test_web_url_with_job(self, agent):
"""Test web_url property returns current job's web_url"""
# Setup mock job
mock_job = MagicMock(spec=AgentTask)
mock_job.web_url = "https://example.com/run/456"

agent.current_job = mock_job

# Check web_url
assert agent.web_url == "https://example.com/run/456"

def test_run(self, agent, mock_agents_api):
"""Test run method creates and returns job"""
# Setup mock API response
Expand Down Expand Up @@ -250,6 +265,9 @@ def test_full_workflow(self, mock_response, mock_updated_response):
assert job.status == "running"
assert job.result is None

# Verify web_url property
assert agent.web_url == "https://example.com/run/987"

# Check status
status = agent.get_status()

Expand Down
Loading