Skip to content

Commit 8946a09

Browse files
authored
Merge pull request #1012 from julep-ai/x/sessions-updated-at-precision
fix(agents-api): Fix sessions `updated_at` precision issue
2 parents 24340ec + edfcdf2 commit 8946a09

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

agents-api/agents_api/activities/execute_system.py

+36-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
HybridDocSearchRequest,
1717
SystemDef,
1818
TextOnlyDocSearchRequest,
19+
UpdateSessionRequest,
1920
VectorDocSearchRequest,
2021
)
21-
from ..common.protocol.tasks import StepContext
22+
from ..common.protocol.tasks import ExecutionInput, StepContext
2223
from ..common.storage_handler import auto_blob_store, load_from_blob_store_if_remote
2324
from ..env import testing
2425
from ..models.developer import get_developer
@@ -40,6 +41,9 @@ async def execute_system(
4041
if set(arguments.keys()) == {"bucket", "key"}:
4142
arguments = await load_from_blob_store_if_remote(arguments)
4243

44+
if not isinstance(context.execution_input, ExecutionInput):
45+
raise TypeError("Expected ExecutionInput type for context.execution_input")
46+
4347
arguments["developer_id"] = context.execution_input.developer_id
4448

4549
# Unbox all the arguments
@@ -106,10 +110,11 @@ async def execute_system(
106110
await bg_runner()
107111
return res
108112

113+
# Handle create operations
109114
if system.operation == "create" and system.resource == "session":
110115
developer_id = arguments.pop("developer_id")
111116
session_id = arguments.pop("session_id", None)
112-
data = CreateSessionRequest(**arguments)
117+
create_session_request = CreateSessionRequest(**arguments)
113118

114119
# In case sessions.create becomes asynchronous in the future
115120
if asyncio.iscoroutinefunction(handler):
@@ -118,7 +123,35 @@ async def execute_system(
118123
# Run the synchronous function in another process
119124
loop = asyncio.get_running_loop()
120125
return await loop.run_in_executor(
121-
process_pool_executor, partial(handler, developer_id, session_id, data)
126+
process_pool_executor,
127+
partial(
128+
handler,
129+
developer_id=developer_id,
130+
session_id=session_id,
131+
data=create_session_request,
132+
),
133+
)
134+
135+
# Handle update operations
136+
if system.operation == "update" and system.resource == "session":
137+
developer_id = arguments.pop("developer_id")
138+
session_id = arguments.pop("session_id")
139+
update_session_request = UpdateSessionRequest(**arguments)
140+
141+
# In case sessions.update becomes asynchronous in the future
142+
if asyncio.iscoroutinefunction(handler):
143+
return await handler()
144+
145+
# Run the synchronous function in another process
146+
loop = asyncio.get_running_loop()
147+
return await loop.run_in_executor(
148+
process_pool_executor,
149+
partial(
150+
handler,
151+
developer_id=developer_id,
152+
session_id=session_id,
153+
data=update_session_request,
154+
),
122155
)
123156

124157
# Handle regular operations

agents-api/agents_api/models/chat/prepare_chat_context.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"session": make_session(
3838
agents=[a["id"] for a in d["agents"]],
3939
users=[u["id"] for u in d["users"]],
40+
updated_at=d["session"].pop("updated_at") / (1000000.0),
4041
**d["session"],
4142
),
4243
"toolsets": [

agents-api/agents_api/models/session/get_session.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727
TypeError: partialclass(HTTPException, status_code=400),
2828
}
2929
)
30-
@wrap_in_class(make_session, one=True)
30+
@wrap_in_class(
31+
make_session,
32+
one=True,
33+
transform=lambda d: {
34+
"updated_at": d.pop("updated_at") / (1000000.0),
35+
**d,
36+
},
37+
)
3138
@cozo_query
3239
@beartype
3340
def get_session(

agents-api/agents_api/models/session/prepare_session_data.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
one=True,
3333
transform=lambda d: {
3434
"session": make_session(
35+
updated_at=d["session"].pop("updated_at") / (1000000.0),
3536
**d["session"],
3637
agents=[a["id"] for a in d["agents"]],
3738
users=[u["id"] for u in d["users"]],

agents-api/agents_api/models/session/update_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
one=True,
4646
transform=lambda d: {
4747
"id": d["session_id"],
48-
"updated_at": d.pop("updated_at")[0],
48+
"updated_at": d.pop("updated_at")[0] / (1000000.0),
4949
"jobs": [],
5050
**d,
5151
},

0 commit comments

Comments
 (0)