Skip to content

Commit

Permalink
Merge pull request #31 from superagentxai/30-memory-issue-sqlhandler
Browse files Browse the repository at this point in the history
AgentX-Pipe Memory Issue
  • Loading branch information
RaghavPrabhu authored Dec 30, 2024
2 parents 7e0cdc6 + 997d0e6 commit df73458
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 299 deletions.
567 changes: 284 additions & 283 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "superagentx"
version = "0.1.13"
version = "0.1.14b"
description = "The Ultimate Modular Autonomous Multi AI Agent Framework."
license = "MIT"
authors = [
Expand Down
7 changes: 2 additions & 5 deletions superagentx/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,10 @@ async def _execute(
self,
query_instruction: str,
pre_result: str | None = None,
old_memory: str | None = None
old_memory: list[dict] | None = None
) -> GoalResult:
results = []
instruction = query_instruction
if old_memory:
instruction = f"Context:\n{old_memory}\nQuestion: {query_instruction}"
logger.debug(f'Updated Query Instruction with old memory : {instruction}')
async for _engines in iter_to_aiter(self.engines):
if isinstance(_engines, list):
logger.debug(f'Engine(s) are executing : {",".join([str(_engine) for _engine in _engines])}')
Expand Down Expand Up @@ -256,7 +253,7 @@ async def execute(
*,
query_instruction: str,
pre_result: str | None = None,
old_memory: str | None = None,
old_memory: list[dict] | None = None,
stop_if_goal_not_satisfied: bool = False
) -> GoalResult | None:
"""
Expand Down
6 changes: 0 additions & 6 deletions superagentx/agentxpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ async def retrieve_memory(
return await self.memory.search(
query=query_instruction,
memory_id=self.memory_id,
chat_id=self.chat_id,
limit=10,
)

Expand All @@ -205,11 +204,6 @@ async def _flow(
logger.debug(f'Updated with previous results.\nPrevious Result : {pre_result}')
if self.memory:
old_memory = await self.retrieve_memory(query_instruction)
if old_memory:
message_content = ""
async for _mem in iter_to_aiter(old_memory):
message_content += f"{_mem.get('content')} "
old_memory = f"Context :\n{message_content}\nQuestion : {query_instruction}"
logger.debug(f"Updated with old memory.\n{old_memory}")
try:
if isinstance(_agents, list):
Expand Down
3 changes: 3 additions & 0 deletions superagentx/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async def start(
self,
input_prompt: str,
pre_result: str | None = None,
old_memory: list[dict] | None = None,
**kwargs
) -> list[typing.Any]:
"""
Expand All @@ -87,6 +88,7 @@ async def start(
based on the context.
pre_result: An optional pre-computed result or state to be used during the execution.
Defaults to `None` if not provided.
old_memory: An optional previous context of the user's instruction
kwargs: Additional keyword arguments to update the `input_prompt` dynamically.
Returns:
Expand All @@ -101,6 +103,7 @@ async def start(
kwargs = {}
prompt_messages = await self.prompt_template.get_messages(
input_prompt=input_prompt,
old_memory=old_memory,
**kwargs
)
logger.debug(f"Prompt Message : {prompt_messages}")
Expand Down
1 change: 0 additions & 1 deletion superagentx/memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ async def search(
self,
query: str,
memory_id: str,
chat_id: str,
limit: int = 10,
filters: dict | None = None
) -> list[dict]:
Expand Down
6 changes: 6 additions & 0 deletions superagentx/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ async def get_messages(
self,
*,
input_prompt: str,
old_memory: list[dict] | None = None,
**kwargs: Any
) -> list[dict]:
"""
To construct the message structure based on the user's prompt type
Args:
input_prompt (str): Give the instruction of your expected result.
old_memory (list[dict]): An optional previous context of the user's instruction
kwargs (Any): Format the variable's value in the given prompt.
"""
prompt = await self._get_prompt()
Expand All @@ -64,6 +66,10 @@ async def get_messages(
"content": format_string
}
prompt.append(content)

if old_memory:
prompt += old_memory

if self.system_message:
_system_content = {
"role": "system",
Expand Down
2 changes: 1 addition & 1 deletion superagentx_cli/templates/pyproject.toml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keywords = ["{{ package_name }}", "AGI", "Agentic AI", "ASI", "superagentx", "ag
python = ">=3.10,<=3.13"
rich = "^13.9.2"
websockets = "^13.1"
superagentx = "^0.1.12"
superagentx = "^0.1.13"
superagentx-handlers = "^0.1.5"
fastapi = {extras = ["standard"], version = "^0.115.4"}

Expand Down
3 changes: 1 addition & 2 deletions tests/memory/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ async def test_search(self, test_memory_init: dict):
client: Memory = test_memory_init.get("client")
response = await client.search(
query="agentic",
memory_id=datas.get("memory_id"),
chat_id=datas.get("chat_id")
memory_id=datas.get("memory_id")
)
logger.info(response)
return response

0 comments on commit df73458

Please sign in to comment.