Skip to content

Commit

Permalink
Add dedicated memory (superagent-ai#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
homanp authored Sep 24, 2023
1 parent 5f3cd69 commit 459cf1d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions libs/superagent/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ DATABASE_MIGRATION_URL=
DATABASE_SHADOW_URL= # Mandatory for Neon DB
JWT_SECRET=
# Memory (mandatory)
MOTORHEAD_API_KEY=
MOTORHEAD_CLIENT_ID=
MEMORY_API_URL=https://memory.superagent.sh
# Vectorstores (mandatory if you plan on loading datasources)
PINECONE_ENVIRONMENT=
PINECONE_API_KEY=
Expand Down
9 changes: 5 additions & 4 deletions libs/superagent/app/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ async def _get_prompt(self, agent: Agent) -> SystemMessage:

async def _get_memory(self) -> MotorheadMemory:
memory = MotorheadMemory(
session_id=f"{self.agent_id}-{self.session_id}",
session_id=f"{self.agent_id}-{self.session_id}"
if self.session_id
else f"{self.agent_id}",
memory_key="chat_history",
client_id=config("MOTORHEAD_CLIENT_ID"),
api_key=config("MOTORHEAD_API_KEY"),
url=config("MEMORY_API_URL"),
return_messages=True,
output_key="output",
)
Expand All @@ -117,6 +118,7 @@ async def get_agent(self) -> Any:
llm = await self._get_llm(agent_llm=config.llms[0], model=config.llmModel)
prompt = await self._get_prompt(agent=config)
memory = await self._get_memory()

if len(tools) > 0:
agent = initialize_agent(
tools,
Expand Down Expand Up @@ -148,7 +150,6 @@ async def get_agent(self) -> Any:
memory=memory,
output_key="output",
verbose=True,
return_final_only=True,
prompt=PromptTemplate.from_template(prompt),
)
return agent
12 changes: 7 additions & 5 deletions libs/superagent/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/superagent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ openpyxl = "^3.1.2"
unstructured = "^0.10.16"
python-docx = "^0.8.11"
langsmith = "^0.0.39"
langchain = "^0.0.297"
requests = "^2.31.0"
wolframalpha = "^5.0.0"
langchain = "^0.0.300"


[build-system]
Expand Down

0 comments on commit 459cf1d

Please sign in to comment.