Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
add migration script
Sarah Wooders25c3f83d78fb
diff --git a/scripts/migrate_0.3.18.py b/scripts/migrate_0.3.18.pynew file mode 100644index 000000000..5ac681ab9--- /dev/null+++ b/scripts/migrate_0.3.18.py@@ -0,0 +1,84 @@+import os+import uuid++from sqlalchemy import MetaData, Table, create_engine++from memgpt import create_client+from memgpt.config import MemGPTConfig+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig+from memgpt.metadata import MetadataStore+from memgpt.presets.presets import add_default_tools+from memgpt.prompts import gpt_system++# Replace this with your actual database connection URL+config = MemGPTConfig.load()+if config.recall_storage_type == "sqlite":+ DATABASE_URL = "sqlite:///" + os.path.join(config.recall_storage_path, "sqlite.db")+else:+ DATABASE_URL = config.recall_storage_uri+print(DATABASE_URL)+engine = create_engine(DATABASE_URL)+metadata = MetaData()++# defaults+system_prompt = gpt_system.get_system_text("memgpt_chat")++# Reflect the existing table+table = Table("agents", metadata, autoload_with=engine)+++# get all agent rows+agent_states = []+with engine.connect() as conn:+ agents = conn.execute(table.select()).fetchall()+ for agent in agents:+ # print(agent)+ id = uuid.UUID(agent[0])+ user_id = uuid.UUID(agent[1])+ name = agent[2]+ persona = agent[3]+ human = agent[4]+ system = agent[5]+ preset = agent[6]+ created_at = agent[7]+ llm_config = LLMConfig(**agent[8])+ embedding_config = EmbeddingConfig(**agent[9])+ state = agent[10]+ tools = agent[11]++ state["memory"] = {"human": human, "persona": persona}++ agent_state = AgentState(+ id=id,+ user_id=user_id,+ name=name,+ system=system,+ created_at=created_at,+ llm_config=llm_config,+ embedding_config=embedding_config,+ state=state,+ tools=tools,+ _metadata={"human": "migrated", "persona": "migrated"},+ )++ agent_states.append(agent_state)++# remove agents table+agents_model = Table("agents", metadata, autoload_with=engine)+agents_model.drop(engine)++# re-create tables and add default tools+ms = MetadataStore(config)+add_default_tools(None, ms)++for agent in agent_states:+ ms.create_agent(agent)+ print(f"Agent {agent.name} migrated successfully!")++# add another agent to create core memory tool+client = create_client()+dummy_agent = client.create_agent(name="dummy_agent")+tools = client.list_tools()+assert "core_memory_append" in [tool.name for tool in tools]++print("Migration completed successfully!")