Skip to content
Merged
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
61 changes: 51 additions & 10 deletions src/meshbot/tools/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,62 @@ async def status_request(ctx: RunContext[Any], destination: str) -> str:
return f"Status request to {destination} failed"

@tool()
async def get_conversation_history(
async def get_channel_messages(
ctx: RunContext[Any], channel: str = "0", limit: int = 5
) -> str:
"""Get recent messages from a channel.

Args:
channel: Channel number (default: "0" for main channel)
limit: Number of recent messages to retrieve (default: 5)

Returns:
Recent channel messages in time order
"""
try:
# Get messages from channel
messages = await ctx.deps.memory.storage.get_conversation_messages(
conversation_id=channel, limit=limit
)
if not messages:
return f"No messages in channel {channel}."

response = f"Last {len(messages)} message(s) in channel {channel}:\n"
for msg in messages:
role = "User" if msg["role"] == "user" else "Bot"
response += f"{role}: {msg['content']}\n"

return response.strip()
except Exception as e:
logger.error(f"Error getting channel messages: {e}")
return f"Error retrieving messages from channel {channel}."

@tool()
async def get_user_messages(
ctx: RunContext[Any], user_id: str, limit: int = 5
) -> str:
"""Get recent conversation history with a user."""
"""Get recent private messages with a specific user.

Args:
user_id: User's public key (full or first 8-16 characters)
limit: Number of recent messages to retrieve (default: 5)

Returns:
Recent private messages with the user in time order
"""
try:
history = await ctx.deps.memory.get_conversation_history(user_id, limit)
if not history:
return "No conversation history with this user."
messages = await ctx.deps.memory.storage.get_conversation_messages(
conversation_id=user_id, limit=limit
)
if not messages:
return f"No conversation history with user {user_id[:16]}..."

response = "Recent conversation:\n"
for msg in history:
role = "User" if msg["role"] == "user" else "Assistant"
response = f"Last {len(messages)} message(s) with {user_id[:16]}:\n"
for msg in messages:
role = "User" if msg["role"] == "user" else "Bot"
response += f"{role}: {msg['content']}\n"

return response.strip()
except Exception as e:
logger.error(f"Error getting conversation history: {e}")
return "Error retrieving conversation history."
logger.error(f"Error getting user messages: {e}")
return f"Error retrieving messages with user {user_id[:16]}..."
Loading