fix-cron-scheduled-tasks #1

Merged
tanyar09 merged 11 commits from fix-cron-scheduled-tasks into feature/cleanup-providers-llama-only 2026-03-04 12:04:57 -05:00
2 changed files with 33 additions and 1 deletions
Showing only changes of commit 02cf7fb4da - Show all commits

View File

@ -221,13 +221,19 @@ class AgentLoop:
args_str = json.dumps(tool_call.arguments, ensure_ascii=False)
logger.info(f"Tool call: {tool_call.name}({args_str[:200]})")
result = await self.tools.execute(tool_call.name, tool_call.arguments)
logger.info(f"Tool result length: {len(result) if result else 0}, preview: {result[:200] if result else 'None'}")
messages = self.context.add_tool_result(
messages, tool_call.id, tool_call.name, result
)
logger.debug(f"Added tool result to messages. Total messages: {len(messages)}")
else:
final_content = self._strip_think(response.content)
logger.info(f"Final response generated. Content length: {len(final_content) if final_content else 0}")
break
if final_content is None and iteration >= self.max_iterations:
logger.warning(f"Max iterations ({self.max_iterations}) reached without final response. Last tool calls: {tools_used[-3:] if len(tools_used) >= 3 else tools_used}")
return final_content, tools_used
async def run(self) -> None:

View File

@ -3,11 +3,37 @@
import json
import json_repair
import os
import sys
from typing import Any
# Workaround for litellm's os.getcwd() issue during import
# litellm/proxy/proxy_cli.py does sys.path.append(os.getcwd()) which can fail
# if the current directory was deleted. Patch os.getcwd() to handle this gracefully.
_original_getcwd = os.getcwd
def _safe_getcwd():
try:
cwd = _original_getcwd()
# Verify the directory actually exists
if not os.path.exists(cwd):
raise FileNotFoundError(f"Current directory does not exist: {cwd}")
return cwd
except (FileNotFoundError, OSError):
# Return a safe fallback directory (home directory)
fallback = os.path.expanduser("~")
# Ensure fallback exists
if not os.path.exists(fallback):
fallback = "/tmp"
return fallback
# Patch os.getcwd before importing litellm
os.getcwd = _safe_getcwd
import litellm
from litellm import acompletion
# Restore original getcwd after import
os.getcwd = _original_getcwd
from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest
from nanobot.providers.registry import find_by_model, find_gateway