Skip to content

Commit c0b16c0

Browse files
authored
Merge pull request #63 from WorkflowAI/feature/display-run-url
feat(run): add run URL to format_output
2 parents 63680ae + 067e26d commit c0b16c0

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

workflowai/core/domain/run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def format_output(self) -> str:
9090
1. The output as a nicely formatted JSON object
9191
2. The cost with $ prefix (if available)
9292
3. The latency with 2 decimal places and 's' suffix (if available)
93+
4. The run URL for viewing in the web UI
9394
9495
Example:
9596
Output:
@@ -100,6 +101,7 @@ def format_output(self) -> str:
100101
==================================================
101102
Cost: $ 0.001
102103
Latency: 1.23s
104+
URL: https://workflowai.com/_/agents/agent-1/runs/test-id
103105
"""
104106
# Format the output string
105107
output = [
@@ -115,6 +117,9 @@ def format_output(self) -> str:
115117
if self.duration_seconds is not None:
116118
output.append(f"Latency: {self.duration_seconds:.2f}s")
117119

120+
# Always add the run URL
121+
output.append(f"URL: {self.run_url}")
122+
118123
return "\n".join(output)
119124

120125
def __str__(self) -> str:

workflowai/core/domain/run_test.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class _TestOutput(BaseModel):
1515
@pytest.fixture
1616
def run1() -> Run[_TestOutput]:
1717
return Run[_TestOutput](
18-
id="test-id",
19-
agent_id="agent-1",
18+
id="run-id",
19+
agent_id="agent-id",
2020
schema_id=1,
2121
output=_TestOutput(message="test output"),
2222
duration_seconds=1.0,
@@ -51,10 +51,12 @@ def test_different_agents(self, run1: Run[_TestOutput], run2: Run[_TestOutput]):
5151
# 1. The output as a JSON object
5252
# 2. The cost with $ prefix and correct precision
5353
# 3. The latency with 2 decimal places and 's' suffix
54-
def test_format_output() -> None:
54+
# 4. The run URL
55+
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
56+
def test_format_output_full():
5557
run = Run[_TestOutput](
56-
id="test-id",
57-
agent_id="agent-1",
58+
id="run-id",
59+
agent_id="agent-id",
5860
schema_id=1,
5961
output=_TestOutput(message="hello"),
6062
duration_seconds=1.23,
@@ -68,15 +70,17 @@ def test_format_output() -> None:
6870
}
6971
==================================================
7072
Cost: $ 0.00100
71-
Latency: 1.23s"""
73+
Latency: 1.23s
74+
URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
7275

7376
assert run.format_output() == expected
7477

7578

76-
def test_format_output_very_low_cost() -> None:
79+
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
80+
def test_format_output_very_low_cost():
7781
run = Run[_TestOutput](
78-
id="test-id",
79-
agent_id="agent-1",
82+
id="run-id",
83+
agent_id="agent-id",
8084
schema_id=1,
8185
output=_TestOutput(message="hello"),
8286
duration_seconds=1.23,
@@ -90,18 +94,21 @@ def test_format_output_very_low_cost() -> None:
9094
}
9195
==================================================
9296
Cost: $ 0.00005
93-
Latency: 1.23s"""
97+
Latency: 1.23s
98+
URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
9499

95100
assert run.format_output() == expected
96101

97102

98103
# Test that format_output works correctly when cost and latency are not provided:
99104
# 1. The output is still formatted as a JSON object
100105
# 2. No cost or latency lines are included in the output
101-
def test_format_output_no_cost_latency() -> None:
106+
# 3. The run URL is still included
107+
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
108+
def test_format_output_no_cost_latency():
102109
run = Run[_TestOutput](
103-
id="test-id",
104-
agent_id="agent-1",
110+
id="run-id",
111+
agent_id="agent-id",
105112
schema_id=1,
106113
output=_TestOutput(message="hello"),
107114
)
@@ -111,12 +118,13 @@ def test_format_output_no_cost_latency() -> None:
111118
{
112119
"message": "hello"
113120
}
114-
=================================================="""
121+
==================================================
122+
URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
115123

116124
assert run.format_output() == expected
117125

118126

119127
class TestRunURL:
120128
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
121129
def test_run_url(self, run1: Run[_TestOutput]):
122-
assert run1.run_url == "https://workflowai.hello/_/agents/agent-1/runs/test-id"
130+
assert run1.run_url == "https://workflowai.hello/_/agents/agent-id/runs/run-id"

0 commit comments

Comments
 (0)