Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import litellm
from litellm.exceptions import AuthenticationError
from helpers.extension import Extension
from agent import LoopData
from helpers import dirty_json, errors, log, plugins
Expand Down Expand Up @@ -101,7 +103,18 @@ async def search_memories(self, log_item: log.LogItem, loop_data: LoopData, **kw
)
query = query.strip()
log_item.update(query=query) # no need for streaming here
except AuthenticationError as e:
# Guard against NVIDIA API key being sent to OpenAI endpoint
if "nvapi-" in str(e):
log_item.update(heading="SKIPPED: Invalid API Key (NVIDIA key on OpenAI endpoint)")
log_item.update(content="Memory recall skipped due to configuration error. Please update API_KEY_OPENAI in .env or fix provider routing.")
# Gracefully exit without crashing or logging full traceback
query = ""
else:
# Re-raise if it is a different authentication error
raise
except Exception as e:
# Catch any other unexpected errors
err = errors.format_error(e)
self.agent.context.log.log(
type="warning", heading="Recall memories extension error:", content=err
Expand All @@ -114,7 +127,7 @@ async def search_memories(self, log_item: log.LogItem, loop_data: LoopData, **kw
heading="Failed to generate memory query",
)
return

# otherwise use the message and history as query
else:
query = user_instruction + "\n\n" + history
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import litellm
from litellm.exceptions import AuthenticationError
from helpers import errors, plugins
from helpers.extension import Extension
from helpers.dirty_json import DirtyJson
Expand All @@ -23,7 +25,7 @@ def execute(self, loop_data: LoopData = LoopData(), **kwargs):

if not set["memory_memorize_enabled"]:
return

# show full util message
log_item = self.agent.context.log.log(
type="util",
Expand Down Expand Up @@ -57,12 +59,28 @@ async def memorize(self, loop_data: LoopData, log_item: LogItem, **kwargs):
# log_item.stream(content=content)

# call util llm to find solutions in history
solutions_json = await self.agent.call_utility_model(
system=system,
message=msgs_text,
# callback=log_callback,
background=True,
)
try:
solutions_json = await self.agent.call_utility_model(
system=system,
message=msgs_text,
# callback=log_callback,
background=True,
)
except AuthenticationError as e:
# Guard against NVIDIA API key being sent to OpenAI endpoint
if "nvapi-" in str(e):
log_item.update(heading="SKIPPED: Invalid API Key (NVIDIA key on OpenAI endpoint)")
log_item.update(content="Memory memorization skipped due to configuration error. Please update API_KEY_OPENAI in .env or fix provider routing.")
# Gracefully exit without crashing the background thread
return
else:
# Re-raise if it is a different authentication error
raise
except Exception as e:
# Catch any other unexpected errors to prevent thread crashes
log_item.update(heading="SKIPPED: Memory memorization failed")
log_item.update(content=f"Error: {str(e)}")
return

# log query < no need for streaming utility messages
log_item.update(content=solutions_json)
Expand Down