Rebase onto upstream (a4d95fd) #12

Closed
wylab wants to merge 144 commits from rebase-onto-upstream into main
2 changed files with 50 additions and 4 deletions
Showing only changes of commit b54c79003e - Show all commits
+7 -4
View File
@@ -661,16 +661,18 @@ Respond with ONLY valid JSON, no markdown fences."""
session_key: str = "cli:direct", session_key: str = "cli:direct",
channel: str = "cli", channel: str = "cli",
chat_id: str = "direct", chat_id: str = "direct",
metadata: dict[str, Any] | None = None,
) -> str: ) -> str:
""" """
Process a message directly (for CLI or cron usage). Process a message directly (for CLI or cron usage).
Args: Args:
content: The message content. content: The message content.
session_key: Session identifier (overrides channel:chat_id for session lookup). session_key: Session identifier (overrides channel:chat_id for session lookup).
channel: Source channel (for tool context routing). channel: Source channel (for tool context routing).
chat_id: Source chat ID (for tool context routing). chat_id: Source chat ID (for tool context routing).
metadata: Optional metadata to pass through (for suppress mode, etc.).
Returns: Returns:
The agent's response. The agent's response.
""" """
@@ -678,8 +680,9 @@ Respond with ONLY valid JSON, no markdown fences."""
channel=channel, channel=channel,
sender_id="user", sender_id="user",
chat_id=chat_id, chat_id=chat_id,
content=content content=content,
metadata=metadata or {},
) )
response = await self._process_message(msg, session_key=session_key) response = await self._process_message(msg, session_key=session_key)
return response.content if response else "" return response.content if response else ""
+43
View File
@@ -0,0 +1,43 @@
# tests/test_agent_loop_metadata.py
import pytest
from pathlib import Path
from nanobot.agent.loop import AgentLoop
from nanobot.bus.queue import MessageBus
from nanobot.providers.base import LLMProvider, LLMResponse
from unittest.mock import AsyncMock, MagicMock
@pytest.mark.asyncio
async def test_process_direct_passes_metadata():
"""Test that process_direct passes metadata to InboundMessage."""
bus = MessageBus()
provider = MagicMock(spec=LLMProvider)
provider.chat = AsyncMock(return_value=LLMResponse(
content="test response",
has_tool_calls=False,
tool_calls=[]
))
provider.get_default_model = MagicMock(return_value="test-model")
workspace = Path("/tmp/test-workspace")
workspace.mkdir(exist_ok=True)
loop = AgentLoop(bus=bus, provider=provider, workspace=workspace)
# Call with metadata
test_metadata = {"suppress_output": True, "test_key": "test_value"}
await loop.process_direct(
content="test message",
metadata=test_metadata
)
# Verify provider.chat was called
assert provider.chat.called
call_args = provider.chat.call_args
messages = call_args.kwargs["messages"]
# The user message should contain the content
# (We can't easily check InboundMessage directly, but we verify
# the flow worked by checking the session was created)
session = loop.sessions.get_or_create("cli:direct")
assert len(session.messages) > 0