Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/copilot): skip user DB lookup on non-first turns

Zamil Majdy1fc3cc74ea69
diff --git a/autogpt_platform/backend/backend/copilot/baseline/service.py b/autogpt_platform/backend/backend/copilot/baseline/service.py
index 490368c03a..9f1be311ea 100644
--- a/autogpt_platform/backend/backend/copilot/baseline/service.py
+++ b/autogpt_platform/backend/backend/copilot/baseline/service.py
@@ -201,12 +201,16 @@ async def stream_chat_completion_baseline(
# Inject user context into the first user message on first turn
if is_first_turn and understanding:
user_ctx = format_understanding_for_prompt(understanding)
+ injected = False
for msg in openai_messages:
if msg["role"] == "user":
msg["content"] = (
f"<user_context>\n{user_ctx}\n</user_context>\n\n{msg['content']}"
)
+ injected = True
break
+ if not injected:
+ logger.warning("[Baseline] No user message found for context injection")
tools = get_available_tools()
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py
index 8ed5ca91b9..ed1c63163a 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service.py
@@ -1559,7 +1559,7 @@ async def stream_chat_completion_sdk(
e2b_sandbox, (base_system_prompt, understanding), dl = await asyncio.gather(
_setup_e2b(),
- _build_cacheable_system_prompt(user_id),
+ _build_cacheable_system_prompt(user_id if not has_history else None),
_fetch_transcript(),
)