88 Run ,
99 _AgentBase , # pyright: ignore [reportPrivateUsage]
1010)
11+ from workflowai .core .domain .tool_call import ToolCallRequest
1112from workflowai .core .domain .version import Version
1213from workflowai .core .domain .version_properties import VersionProperties
1314
@@ -59,23 +60,29 @@ def test_different_agents(self, run1: Run[_TestOutput], run2: Run[_TestOutput]):
5960 assert run1 == run2
6061
6162
62- # Test that format_output correctly formats:
63- # 1. The output as a JSON object
64- # 2. The cost with $ prefix and correct precision
65- # 3. The latency with 2 decimal places and 's' suffix
66- # 4. The run URL
67- @patch ("workflowai.env.WORKFLOWAI_APP_URL" , "https://workflowai.hello" )
68- def test_format_output_full ():
69- run = Run [_TestOutput ](
70- id = "run-id" ,
71- agent_id = "agent-id" ,
72- schema_id = 1 ,
73- output = _TestOutput (message = "hello" ),
74- duration_seconds = 1.23 ,
75- cost_usd = 0.001 ,
76- )
77-
78- expected = """\n Output:
63+ class TestRunFormatOutput :
64+ @pytest .fixture (autouse = True )
65+ def mock_app_url (self ):
66+ with patch ("workflowai.env.WORKFLOWAI_APP_URL" , "https://workflowai.hello" ) as mock :
67+ yield mock
68+
69+ # Test that format_output correctly formats:
70+ # 1. The output as a JSON object
71+ # 2. The cost with $ prefix and correct precision
72+ # 3. The latency with 2 decimal places and 's' suffix
73+ # 4. The run URL
74+
75+ def test_format_output_full (self ):
76+ run = Run [_TestOutput ](
77+ id = "run-id" ,
78+ agent_id = "agent-id" ,
79+ schema_id = 1 ,
80+ output = _TestOutput (message = "hello" ),
81+ duration_seconds = 1.23 ,
82+ cost_usd = 0.001 ,
83+ )
84+
85+ expected = """\n Output:
7986==================================================
8087{
8188 "message": "hello"
@@ -85,21 +92,19 @@ def test_format_output_full():
8592Latency: 1.23s
8693URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
8794
88- assert run .format_output () == expected
95+ assert run .format_output () == expected
8996
97+ def test_format_output_very_low_cost (self ):
98+ run = Run [_TestOutput ](
99+ id = "run-id" ,
100+ agent_id = "agent-id" ,
101+ schema_id = 1 ,
102+ output = _TestOutput (message = "hello" ),
103+ duration_seconds = 1.23 ,
104+ cost_usd = 4.97625e-05 ,
105+ )
90106
91- @patch ("workflowai.env.WORKFLOWAI_APP_URL" , "https://workflowai.hello" )
92- def test_format_output_very_low_cost ():
93- run = Run [_TestOutput ](
94- id = "run-id" ,
95- agent_id = "agent-id" ,
96- schema_id = 1 ,
97- output = _TestOutput (message = "hello" ),
98- duration_seconds = 1.23 ,
99- cost_usd = 4.97625e-05 ,
100- )
101-
102- expected = """\n Output:
107+ expected = """\n Output:
103108==================================================
104109{
105110 "message": "hello"
@@ -109,31 +114,60 @@ def test_format_output_very_low_cost():
109114Latency: 1.23s
110115URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
111116
112- assert run .format_output () == expected
113-
114-
115- # Test that format_output works correctly when cost and latency are not provided:
116- # 1. The output is still formatted as a JSON object
117- # 2. No cost or latency lines are included in the output
118- # 3. The run URL is still included
119- @patch ("workflowai.env.WORKFLOWAI_APP_URL" , "https://workflowai.hello" )
120- def test_format_output_no_cost_latency ():
121- run = Run [_TestOutput ](
122- id = "run-id" ,
123- agent_id = "agent-id" ,
124- schema_id = 1 ,
125- output = _TestOutput (message = "hello" ),
126- )
127-
128- expected = """\n Output:
117+ assert run .format_output () == expected
118+
119+ # Test that format_output works correctly when cost and latency are not provided:
120+ # 1. The output is still formatted as a JSON object
121+ # 2. No cost or latency lines are included in the output
122+ # 3. The run URL is still included
123+ def test_format_output_no_cost_latency (self ):
124+ run = Run [_TestOutput ](
125+ id = "run-id" ,
126+ agent_id = "agent-id" ,
127+ schema_id = 1 ,
128+ output = _TestOutput (message = "hello" ),
129+ )
130+
131+ expected = """\n Output:
129132==================================================
130133{
131134 "message": "hello"
132135}
133136==================================================
134137URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
135138
136- assert run .format_output () == expected
139+ assert run .format_output () == expected
140+
141+ def test_format_output_tool_call_requests (self ):
142+ run = Run [_TestOutput ](
143+ id = "run-id" ,
144+ agent_id = "agent-id" ,
145+ schema_id = 1 ,
146+ output = _TestOutput .model_construct (),
147+ tool_call_requests = [
148+ ToolCallRequest (
149+ id = "tool-call-id" ,
150+ name = "tool-call-name" ,
151+ input = {"key" : "value" },
152+ ),
153+ ],
154+ )
155+ assert (
156+ run .format_output ()
157+ == """\n Tool Call Requests:
158+ ==================================================
159+ [
160+ {
161+ "id": "tool-call-id",
162+ "name": "tool-call-name",
163+ "input": {
164+ "key": "value"
165+ }
166+ }
167+ ]
168+ ==================================================
169+ URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
170+ )
137171
138172
139173class TestRunURL :
0 commit comments