Skip to content

Commit

Permalink
fix: make runtime error warnings.warn instead
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker committed Nov 22, 2024
1 parent 43e3961 commit f1a8a44
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions letta/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import secrets
import warnings
from typing import List, Optional

from sqlalchemy import JSON, Column, DateTime, Index, String, TypeDecorator
Expand Down Expand Up @@ -353,8 +354,14 @@ def create_agent(self, agent: AgentState):
raise ValueError(f"Agent with name {agent.name} already exists")
fields = vars(agent)
fields["memory"] = agent.memory.to_dict()
del fields["_internal_memory"]
del fields["tags"]
if "_internal_memory" in fields:
del fields["_internal_memory"]
else:
warnings.warn(f"Agent {agent.id} has no _internal_memory field")
if "tags" in fields:
del fields["tags"]
else:
warnings.warn(f"Agent {agent.id} has no tags field")
session.add(AgentModel(**fields))
session.commit()

Expand All @@ -364,8 +371,14 @@ def update_agent(self, agent: AgentState):
fields = vars(agent)
if isinstance(agent.memory, Memory): # TODO: this is nasty but this whole class will soon be removed so whatever
fields["memory"] = agent.memory.to_dict()
del fields["_internal_memory"]
del fields["tags"]
if "_internal_memory" in fields:
del fields["_internal_memory"]
else:
warnings.warn(f"Agent {agent.id} has no _internal_memory field")
if "tags" in fields:
del fields["tags"]
else:
warnings.warn(f"Agent {agent.id} has no tags field")
session.query(AgentModel).filter(AgentModel.id == agent.id).update(fields)
session.commit()

Expand Down

0 comments on commit f1a8a44

Please sign in to comment.