diff --git a/agents-api/agents_api/activities/types.py b/agents-api/agents_api/activities/types.py index 4fa1d4d46..37fd8015d 100644 --- a/agents-api/agents_api/activities/types.py +++ b/agents-api/agents_api/activities/types.py @@ -25,12 +25,10 @@ class ChatML(BaseModel): token_count: Optional[int] = None -class BaseTask(BaseModel): - ... +class BaseTask(BaseModel): ... -class BaseTaskArgs(BaseModel): - ... +class BaseTaskArgs(BaseModel): ... class AddPrinciplesTaskArgs(BaseTaskArgs): diff --git a/agents-api/agents_api/clients/worker/types.py b/agents-api/agents_api/clients/worker/types.py index 16fa8404b..86bf564dd 100644 --- a/agents-api/agents_api/clients/worker/types.py +++ b/agents-api/agents_api/clients/worker/types.py @@ -25,12 +25,10 @@ class ChatML(BaseModel): token_count: Optional[int] = None -class BaseTask(BaseModel): - ... +class BaseTask(BaseModel): ... -class BaseTaskArgs(BaseModel): - ... +class BaseTaskArgs(BaseModel): ... class MemoryManagementTaskArgs(BaseTaskArgs): diff --git a/agents-api/agents_api/models/agent/patch_agent.py b/agents-api/agents_api/models/agent/patch_agent.py index 2efa914b6..f296bbf8a 100644 --- a/agents-api/agents_api/models/agent/patch_agent.py +++ b/agents-api/agents_api/models/agent/patch_agent.py @@ -26,6 +26,7 @@ def patch_agent_query( """ # Construct the query for updating agent information in the database. # Agent update query + metadata = update_data.pop("metadata", {}) agent_update_cols, agent_update_vals = cozo_process_mutate_data( { **{k: v for k, v in update_data.items() if v is not None}, @@ -38,10 +39,18 @@ def patch_agent_query( agent_update_query = f""" {{ # update the agent - ?[{agent_update_cols}] <- $agent_update_vals + input[{agent_update_cols}] <- $agent_update_vals + + ?[{agent_update_cols}, metadata] := + input[{agent_update_cols}], + *agents {{ + agent_id: to_uuid($agent_id), + metadata: md, + }}, + metadata = concat(md, $metadata) :update agents {{ - {agent_update_cols} + {agent_update_cols}, metadata, }} :returning }} @@ -78,5 +87,10 @@ def patch_agent_query( return client.run( combined_query, - {"agent_update_vals": agent_update_vals, "settings_vals": settings_vals}, + { + "agent_update_vals": agent_update_vals, + "settings_vals": settings_vals, + "metadata": metadata, + "agent_id": str(agent_id), + }, ) diff --git a/agents-api/agents_api/models/user/patch_user.py b/agents-api/agents_api/models/user/patch_user.py index 58de0b5ce..681be820a 100644 --- a/agents-api/agents_api/models/user/patch_user.py +++ b/agents-api/agents_api/models/user/patch_user.py @@ -24,6 +24,7 @@ def patch_user_query(developer_id: UUID, user_id: UUID, **update_data) -> pd.DataFrame: # Prepare data for mutation by filtering out None values and adding system-generated fields. + metadata = update_data.pop("metadata", {}) user_update_cols, user_update_vals = cozo_process_mutate_data( { **{k: v for k, v in update_data.items() if v is not None}, @@ -36,12 +37,27 @@ def patch_user_query(developer_id: UUID, user_id: UUID, **update_data) -> pd.Dat # Construct the datalog query for updating user information. query = f""" # update the user - ?[{user_update_cols}] <- $user_update_vals + input[{user_update_cols}] <- $user_update_vals + + ?[{user_update_cols}, metadata] := + input[{user_update_cols}], + *users {{ + user_id: to_uuid($user_id), + metadata: md, + }}, + metadata = concat(md, $metadata) :update users {{ - {user_update_cols} + {user_update_cols}, metadata }} :returning """ - return client.run(query, {"user_update_vals": user_update_vals}) + return client.run( + query, + { + "user_update_vals": user_update_vals, + "metadata": metadata, + "user_id": str(user_id), + }, + )