Skip to content

Commit 2e68a06

Browse files
authored
Merge branch 'main' into guillaume/new-missing-token-user-message
2 parents ec78dc1 + 98dfb7e commit 2e68a06

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

workflowai/core/client/_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class CreateAgentResponse(BaseModel):
167167
id: str
168168
schema_id: int
169169
uid: int = 0
170+
tenant_uid: int = 0
170171

171172

172173
class ModelMetadata(BaseModel):

workflowai/core/client/_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class AgentInterface(_BaseObject, Generic[AgentInputContra, AgentOutput], Protoc
5757
@property
5858
def agent_uid(self) -> int: ...
5959

60+
@property
61+
def tenant_uid(self) -> int: ...
62+
6063
async def run(
6164
self,
6265
agent_input: AgentInputContra,

workflowai/core/client/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ async def register(self):
270270
)
271271
self.schema_id = res.schema_id
272272
self.agent_uid = res.uid
273+
self.tenant_uid = res.tenant_uid
273274
return res.schema_id
274275

275276
@classmethod

workflowai/core/client/agent_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ async def test_auto_register(self, httpx_mock: HTTPXMock, agent_no_schema: Agent
232232
"id": "123",
233233
"schema_id": 2,
234234
"uid": 123,
235+
"tenant_uid": 1234,
235236
},
236237
)
237238
run_response = fixtures_json("task_run.json")
@@ -243,7 +244,7 @@ async def test_auto_register(self, httpx_mock: HTTPXMock, agent_no_schema: Agent
243244
out = await agent_no_schema.run(HelloTaskInput(name="Alice"))
244245
assert out.id == "8f635b73-f403-47ee-bff9-18320616c6cc"
245246
assert agent_no_schema.agent_uid == 123
246-
247+
assert agent_no_schema.tenant_uid == 1234
247248
run_response["id"] = "8f635b73-f403-47ee-bff9-18320616c6cc"
248249
# Try and run again
249250
httpx_mock.add_response(

workflowai/core/domain/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def format_output(self) -> str:
110110
# Format the output string
111111
output: list[str] = []
112112
# In case of partial validation, it is possible that the output is an empty model
113-
if dumped_output := self.output.model_dump():
113+
if dumped_output := self.output.model_dump(mode="json"):
114+
# Use model_dump_json which handles datetime serialization correctly
114115
output += [
115116
"\nOutput:",
116117
"=" * 50,

workflowai/core/domain/run_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timezone
12
from unittest.mock import Mock, patch
23

34
import pytest
@@ -17,6 +18,11 @@ class _TestOutput(BaseModel):
1718
message: str
1819

1920

21+
class _TestOutputWithDatetime(BaseModel):
22+
timestamp: datetime
23+
message: str
24+
25+
2026
@pytest.fixture
2127
def mock_agent() -> Mock:
2228
mock = Mock(spec=_AgentBase)
@@ -169,6 +175,29 @@ def test_format_output_tool_call_requests(self):
169175
URL: https://workflowai.hello/_/agents/agent-id/runs/run-id"""
170176
)
171177

178+
def test_format_output_with_datetime(self):
179+
"""Test that datetimes in the output model are correctly serialized to ISO strings."""
180+
test_dt = datetime(2024, 1, 1, 12, 30, 0, tzinfo=timezone.utc)
181+
run = Run[_TestOutputWithDatetime](
182+
id="run-dt-id",
183+
agent_id="agent-dt-id",
184+
schema_id=2,
185+
output=_TestOutputWithDatetime(timestamp=test_dt, message="datetime test"),
186+
duration_seconds=0.5,
187+
cost_usd=0.0001,
188+
)
189+
190+
expected_json_part = '{\n "timestamp": "2024-01-01T12:30:00Z",\n "message": "datetime test"\n}'
191+
expected = f"""\nOutput:
192+
==================================================
193+
{expected_json_part}
194+
==================================================
195+
Cost: $ 0.00010
196+
Latency: 0.50s
197+
URL: https://workflowai.hello/_/agents/agent-dt-id/runs/run-dt-id"""
198+
199+
assert run.format_output() == expected
200+
172201

173202
class TestRunURL:
174203
# The @patch decorator from unittest.mock temporarily replaces the value of an attribute

0 commit comments

Comments
 (0)