fix: add null checks for runtime.context in middlewares and tools (#1269)

Add defensive null checks before accessing runtime.context.get() to
prevent AttributeError when runtime.context is None. This affects:
- UploadsMiddleware
- MemoryMiddleware
- LoopDetectionMiddleware
- SandboxMiddleware
- sandbox tools
- setup_agent_tool
- present_file_tool
- task_tool

Also adds .env loading in serve.sh for environment variable support.

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
Matthew
2026-03-25 08:46:42 +08:00
committed by GitHub
parent f499f37e94
commit 2eca58bd86
9 changed files with 15 additions and 8 deletions

View File

@@ -24,7 +24,7 @@ def setup_agent(
description: One-line description of what the agent does.
"""
agent_name: str | None = runtime.context.get("agent_name")
agent_name: str | None = runtime.context.get("agent_name") if runtime.context else None
try:
paths = get_paths()